SERVO PROJECTSULTRASONIC SENSOR

Arduino Radar System for Distance Measurement

The Arduino Radar System is a versatile project that utilizes a servo motor and an ultrasonic sensor to create a simple radar-like system for distance measurement. This project provides real-time distance information in a specified direction, accompanied by visual and auditory cues.

Component List:

NameQuantityComponent
U11Arduino Uno R3
SERVO21Micro Servo
PIEZO11Piezo
DIST11Ultrasonic Distance Sensor (4-pin)
D11Red LED
D2 ‘…1Blue LED
U21LCD 16 x 2
R1
R2
21 kΩ Resistor

The servo motor rotates the ultrasonic sensor in a sweeping motion, covering a range of 180 degrees. The ultrasonic sensor emits high-frequency sound waves, and by measuring the time it takes for these waves to bounce back after hitting an obstacle, the system calculates the distance. The Arduino processes this information and displays the distance on the LCD. Visual indicators, LEDs, and an audible buzzer provide additional feedback, enhancing the user experience.

Ardunio Code:

#include <Servo.h>
#include <LiquidCrystal.h>
Servo myservo;
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
int pos = 0;
const int trigPin = 9;
const int echoPin = 10;
const int motor = 11;
const int buzzer = 12;
const int ledPin1 = 13;
const int ledPin2 = 8;
float distanceCm, DistanceSec, duration;
void setup() {
myservo.attach(motor);
lcd.begin(16,2);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(buzzer, OUTPUT);
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
DistanceSec=20;
}
void loop() {
for (pos = 0; pos <= 180; pos += 1) {
myservo.write(pos);
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distanceCm = duration * 0.034 / 2;
if (distanceCm <= DistanceSec) {
if (distanceCm <= DistanceSec / 2) {
tone(buzzer, 12);
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, HIGH);
delay(700);
noTone(buzzer);
lcd.setCursor(0, 0);
lcd.print("Distance: ");
lcd.print(distanceCm);
lcd.print(" cm ");
delay(10);
lcd.setCursor(0, 1);
lcd.print("Angle : ");
lcd.print(pos);
lcd.print(" deg ");
delay(2000);
}
else { digitalWrite(buzzer, HIGH);
digitalWrite(ledPin2, LOW);
digitalWrite(ledPin1, HIGH);
delay(100);
digitalWrite(buzzer, LOW);
lcd.setCursor(0, 0);
lcd.print("Distance: ");
lcd.print(distanceCm);
lcd.print(" cm ");
delay(10);
lcd.setCursor(0, 1);
lcd.print("Angle : ");
lcd.print(pos);
lcd.print(" deg ");
delay(2000);
}
}
else { digitalWrite(buzzer, LOW);
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, LOW);
}
lcd.setCursor(0, 0);
lcd.print("Distance: ");
lcd.print(distanceCm);
lcd.print(" cm ");
delay(10);
lcd.setCursor(0, 1);
lcd.print("Angle : ");
lcd.print(pos);
lcd.print(" deg ");
delay(80);
}
for (pos = 180; pos >= 0;
pos -= 1) {
myservo.write(pos);
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distanceCm = duration * 0.034 / 2;
if (distanceCm <= DistanceSec) { if (distanceCm <= DistanceSec / 2) { tone(buzzer, 12);
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, HIGH);
delay(700);
noTone(buzzer);
lcd.setCursor(0, 0);
lcd.print("Distance: ");
lcd.print(distanceCm);
lcd.print(" cm ");
delay(10);
lcd.setCursor(0, 1);
lcd.print("Angle : ");
lcd.print(pos);
lcd.print(" deg ");
delay(2000);
}
else { digitalWrite(buzzer, HIGH);
digitalWrite(ledPin2, LOW);
digitalWrite(ledPin1, HIGH);
delay(100);
digitalWrite(buzzer, LOW);
lcd.setCursor(0, 0);
lcd.print("Distance: ");
lcd.print(distanceCm);
lcd.print(" cm ");
delay(10);
lcd.setCursor(0, 1);
lcd.print("Angle : ");
lcd.print(pos);
lcd.print(" deg ");
delay(2000);
}
}
else { digitalWrite(buzzer, LOW);
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, LOW);
}
lcd.setCursor(0, 0);
lcd.print("Distance: ");
lcd.print(distanceCm);
lcd.print(" cm ");
delay(10);
lcd.setCursor(0, 1);
lcd.print("Angle : ");
lcd.print(pos);
lcd.print(" deg ");
delay(80);
}
}

This Arduino Radar System project offers an engaging introduction to distance sensing and servo motor control, making it an educational and interactive electronics endeavor.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button