Radar prototype using ultrasonic sensors and Arduino
In this article, we use the Arduino development board and ultrasonic sensor to design a radar model for detection and ranging. RADAR is an object detection system that uses radio waves to identify the range, height, direction, and speed of objects. The radio wave pulses emitted by the radar antenna will be reflected from any object in its path. The object returns a part of the wave and is received by the receiver, which is on the same line as the transmitter.
This Arduino radar project aims to implement a radar system prototype based on the Arduino development board, capable of detecting stationary and moving objects.
Required components
In order to design an Arduino radar model using an ultrasonic sensor, we need the following components.
● Arduino UNO development board
● Servo motor SG90
● Ultrasonic sensor HC-SR04
● Buzzer
● 1602 LCD display
● Breadboard
● Connection wires
Block diagram and connection
The following is the block diagram of the Arduino radar model:
The core of the project uses the Arduino UNO development board, which detects the objects in front through ultrasonic waves, uses a motor to change the angle, and displays the results on the LCD display. The specific circuit connection is as follows:
Working process of radar prototype
The Arduino development board sends a +5V signal to the trigger pin of the ultrasonic sensor HC-SR04, which triggers the sensor, and then provides a rotation action on the servo motor mechanically installed with the ultrasonic sensor HC-SR04 so that it can detect moving objects and Positioned within 180 degrees.
Arduino sends (10S) HIGH pulse width on the TRIGGER pin of the sensor to regenerate a series of ultrasonic waves propagating in the air until it touches an obstacle, and then returns to the sensor pin ECHO in the opposite direction. The sensor detects the width of the pulse to calculate the distance. The sensor keeps the signal on the pin ECHO in the HIGH position during the transmission, so as to measure the duration of the ultrasonic round-trip to determine the distance.
The LCD display shows the calculated distance and rotation angle. The buzzer is an additional component. When an obstacle is detected, it will sound and the LED will light up at the same time. These two LEDs and the buzzer together determine the area (near or far) where the object is located.
Program source code
#include <Servo.h>
#include <LiquidCrystal.h>
Servo myservo;
LiquidCrystal lcd(7, 6, 5, 4, 3, 2); // Creates an LCD object. Parameters: (rs, enable, d4, d5, d6, d7)
int pos = 0; // la position initiale du servo moteur
const int trigPin = 9;
const int echoPin = 10;
const int moteur = 11;
const int buzzer = 12;
const int ledPin1 = 14;
const int ledPin2 = 15;
float distanceCm, DistanceSec,duration;
void setup() {
myservo.attach(moteur); // attache le Servo moteur a la pin numéro 11
lcd.begin(16,2); // Initialiser l'interface de Lcd avec leurs Dimensions
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) {// aller de 0 a 180 degée
// in steps of 1 degree
myservo.write(pos); // Programmer le Servo pour aller a la position (pos)
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH); //envoyer une impulsion de 10 micro seconds
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distanceCm = duration*0.034/2;
if (distanceCm <= DistanceSec)
{
if(distanceCm <= DistanceSec/2)
{
tone(buzzer, 10); // Send 1KHz sound signal...
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, HIGH);
delay(700);
noTone(buzzer); // Stop sound...
lcd.setCursor(0,0); // positionner le cursor a 0,0
lcd.print("Distance: "); // Printe "Distance" sur LCD
lcd.print(distanceCm); // Printe la valeur Obtenue sur LCD
lcd.print(" cm "); // Printe l'unité sur LCD
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); // positionner le cursor a 0,0
lcd.print("Distance: "); // Printe "Distance" sur LCD
lcd.print(distanceCm); // Printe la valeur Obtenue sur LCD
lcd.print(" cm "); // Printe l'unité sur LCD
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); // positionner le cursor a 0,0
lcd.print("Distance: "); // Printe "Distance" sur LCD
lcd.print(distanceCm); // Printe la valeur Obtenue sur LCD
lcd.print(" cm "); // Printe l'unité sur LCD
delay(10);
lcd.setCursor(0,1);
lcd.print("Angle: ");
lcd.print(pos);
lcd.print(" deg ");
delay(80); //attendre 100ms pour que le servo cherche sa position
}
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, 10); // Send 1KHz sound signal...
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, HIGH);
delay(700);
noTone(buzzer); // Stop sound...
lcd.setCursor(0,0); // positionner le cursor a 0,0
lcd.print("Distance: "); // Printe "Distance" sur LCD
lcd.print(distanceCm); // Printe la valeur Obtenue sur LCD
lcd.print(" cm "); // Printe l'unité sur LCD
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); // positionner le cursor a 0,0
lcd.print("Distance: "); // Printe "Distance" sur LCD
lcd.print(distanceCm); // Printe la valeur Obtenue sur LCD
lcd.print(" cm "); // Printe l'unité sur LCD
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);
}
}