Obstacle Detection
Obstacle Detection
DETECTION
Introduction
• An obstacle detection system is a device or system that is designed to detect the presence of
obstacles in a specific area.
• These systems can be used in a variety of applications, such as in vehicles to assist with driving, in
robotics to help with navigation, and in industrial settings to protect workers and equipment.
• Common types of obstacle detection systems include radar, lidar, ultrasonic sensors, and
cameras.
• These systems use different techniques to detect obstacles, such as measuring distance, using
infrared radiation, or analyzing images.
Components Required
• Arduino Nano
• Bread Board
• Jumper Wires
• LED
• Resistor
• Buzzer
• The term servo comes from the Latin word servus, meaning
servant or slave. This reflects the historical use of servo
motors as auxiliary drives that assist the main drive system.
Project- 1
Obstacle detection using LED
Circuit Diagram
CODE
#define pingPin 2 //trig pin of sr04
#define echoPin 3
void setup() {
Serial.begin(9600); // Starting Serial Terminal
pinMode(pingPin,OUTPUT);
pinMode(echoPin,INPUT);
pinMode(12,OUTPUT); //pin12 is used as GND pin for LED since arduino nano has only two GND pins
pinMode(A3,OUTPUT); //pin A3 provides the output on LED
}
void loop() {
long duration, cm;
digitalWrite(12, LOW); //LED GND is always low
CODE
//send a signal at ping pin at an interval of 0.002 seconds to check for an object
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(10);
digitalWrite(pingPin, LOW);
else if (cm<10&&cm>0) {
analogWrite(A3,255);
delay(100);
analogWrite(A3,0);
delay(100);
}
//sound buzzer every 0.1 seconds if obstacle distance is between 0-10cm
else
analogWrite(A3,0); //do not sound the buzzer
}
//function to return distance in cm from microseconds
long microsecondsToCentimeters(long microseconds) {
return microseconds / 29 / 2;
}
Project - 3
Servo Distance Indicator
Circuit Diagram
CODE
#include <Servo.h>
#include <NewPing.h>
long duration;
int distance;
Servo servo;
void setup() {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
Serial.begin(9600);
servo.attach(ServoPin);
}
void loop() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
delay(50);
}
TASK
LED Distance Indicator
Circuit Diagram
CODE
#define pingPin 2 //trig pin of sr04
#define echoPin 3
void setup() {
Serial.begin(9600); // Starting Serial Terminal
pinMode(pingPin,OUTPUT);
pinMode(echoPin,INPUT);
pinMode(12,OUTPUT);
pinMode(A3,OUTPUT); //pin A3 provides the output on led
pinMode(11,OUTPUT);
pinMode(A2,OUTPUT);
pinMode(10,OUTPUT);
pinMode(A1,OUTPUT);
}
void loop() {
long duration, cm;
digitalWrite(12, LOW); //led GND is always low
digitalWrite(11, LOW);
digitalWrite(10, LOW);
//send a signal at ping pin at an interval of 0.002 seconds to check for an object
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(10);
digitalWrite(pingPin, LOW);
duration = pulseIn(echoPin, HIGH); //check time using pulseIn function
cm = microsecondsToCentimeters(duration); //functin call to find distance
if (cm<30&&cm>20){
analogWrite(A1,255);
delay(1000);
analogWrite(A1,0);
delay(1000);
} //light green led if obstacle distance is between 20-30cm.
else if (cm<20&&cm>10) {
analogWrite(A2,255);
delay(500);
analogWrite(A2,0);
delay(500);
} //light blue led if obstacle distance is between 10-20cm.
else if (cm<10&&cm>0) {
analogWrite(A3,255);
delay(100);
analogWrite(A3,0);
delay(100);
} //light red led if obstacle distance is between 0-10cm.
else
analogWrite(A3,0); //do not light
}
//function to return distance in cm from microseconds
long microsecondsToCentimeters(long microseconds) {
return microseconds / 29 / 2;
}
Thank You