Arduino Projects

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 line


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 Arduino radar prototype using ultrasonic sensor

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

  1. #include <Servo.h>
  2. #include <LiquidCrystal.h>

  3. Servo myservo;
  4. LiquidCrystal lcd(7, 6, 5, 4, 3, 2); // Creates an LCD object. Parameters: (rs, enable, d4, d5, d6, d7)

  5. int pos = 0; // la position initiale du servo moteur
  6. const int trigPin = 9;
  7. const int echoPin = 10;
  8. const int moteur = 11;
  9. const int buzzer = 12;
  10. const int ledPin1 = 14;
  11. const int ledPin2 = 15;
  12. float distanceCm, DistanceSec,duration;

  13. void setup() {
  14. myservo.attach(moteur); // attache le Servo moteur a la pin numéro 11
  15. lcd.begin(16,2); // Initialiser l’interface de Lcd avec leurs Dimensions
  16. pinMode(trigPin, OUTPUT);
  17. pinMode(echoPin, INPUT);
  18. pinMode(buzzer, OUTPUT);
  19. pinMode(ledPin1, OUTPUT);
  20. pinMode(ledPin2, OUTPUT);
  21. DistanceSec=20;

  22. }

  23. void loop() {
  24. for (pos = 0; pos <= 180; pos += 1) {// aller de 0 a 180 degée
  25. // in steps of 1 degree
  26. myservo.write(pos); // Programmer le Servo pour aller a la position (pos)
  27. digitalWrite(trigPin, LOW);
  28. delayMicroseconds(2);
  29. digitalWrite(trigPin, HIGH); //envoyer une impulsion de 10 micro seconds
  30. delayMicroseconds(10);
  31. digitalWrite(trigPin, LOW);

  32. duration = pulseIn(echoPin, HIGH);
  33. distanceCm = duration*0.034/2;
  34. if (distanceCm <= DistanceSec)
  35. {

  36. if(distanceCm <= DistanceSec/2)
  37. {

  38. tone(buzzer, 10); // Send 1KHz sound signal…
  39. digitalWrite(ledPin1, LOW);
  40. digitalWrite(ledPin2, HIGH);
  41. delay(700);
  42. noTone(buzzer); // Stop sound…
  43. lcd.setCursor(0,0); // positionner le cursor a 0,0
  44. lcd.print(“Distance: “); // Printe “Distance” sur LCD
  45. lcd.print(distanceCm); // Printe la valeur Obtenue sur LCD
  46. lcd.print(” cm “); // Printe l’unité sur LCD
  47. delay(10);
  48. lcd.setCursor(0,1);
  49. lcd.print(“Angle: “);
  50. lcd.print(pos);
  51. lcd.print(” deg “);
  52. delay(2000);
  53. }
  54. else
  55. {
  56. digitalWrite(buzzer, HIGH);
  57. digitalWrite(ledPin2, LOW);
  58. digitalWrite(ledPin1, HIGH);
  59. delay(100);
  60. digitalWrite(buzzer, LOW);
  61. lcd.setCursor(0,0); // positionner le cursor a 0,0
  62. lcd.print(“Distance: “); // Printe “Distance” sur LCD
  63. lcd.print(distanceCm); // Printe la valeur Obtenue sur LCD
  64. lcd.print(” cm “); // Printe l’unité sur LCD
  65. delay(10);
  66. lcd.setCursor(0,1);
  67. lcd.print(“Angle: “);
  68. lcd.print(pos);
  69. lcd.print(” deg “);
  70. delay(2000);
  71. }
  72. }
  73. else{
  74. digitalWrite(buzzer, LOW);
  75. digitalWrite(ledPin1, LOW);
  76. digitalWrite(ledPin2, LOW);
  77. }

  78. lcd.setCursor(0,0); // positionner le cursor a 0,0
  79. lcd.print(“Distance: “); // Printe “Distance” sur LCD
  80. lcd.print(distanceCm); // Printe la valeur Obtenue sur LCD
  81. lcd.print(” cm “); // Printe l’unité sur LCD
  82. delay(10);
  83. lcd.setCursor(0,1);
  84. lcd.print(“Angle: “);
  85. lcd.print(pos);
  86. lcd.print(” deg “);
  87. delay(80); //attendre 100ms pour que le servo cherche sa position

  88. }
  89. for (pos = 180; pos >= 0; pos -= 1) {//
  90. myservo.write(pos); //
  91. digitalWrite(trigPin, LOW);
  92. delayMicroseconds(2);
  93. digitalWrite(trigPin, HIGH);
  94. delayMicroseconds(10);
  95. digitalWrite(trigPin, LOW);

  96. duration = pulseIn(echoPin, HIGH);
  97. distanceCm = duration*0.034/2;
  98. if (distanceCm <= DistanceSec){
  99. if(distanceCm <= DistanceSec/2)
  100. {
  101. tone(buzzer, 10); // Send 1KHz sound signal…
  102. digitalWrite(ledPin1, LOW);
  103. digitalWrite(ledPin2, HIGH);
  104. delay(700);
  105. noTone(buzzer); // Stop sound…
  106. lcd.setCursor(0,0); // positionner le cursor a 0,0
  107. lcd.print(“Distance: “); // Printe “Distance” sur LCD
  108. lcd.print(distanceCm); // Printe la valeur Obtenue sur LCD
  109. lcd.print(” cm “); // Printe l’unité sur LCD
  110. delay(10);
  111. lcd.setCursor(0,1);
  112. lcd.print(“Angle: “);
  113. lcd.print(pos);
  114. lcd.print(” deg “);
  115. delay(2000);
  116. }
  117. else
  118. {
  119. digitalWrite(buzzer, HIGH);
  120. digitalWrite(ledPin2, LOW);
  121. digitalWrite(ledPin1, HIGH);
  122. delay(100);
  123. digitalWrite(buzzer, LOW);
  124. lcd.setCursor(0,0); // positionner le cursor a 0,0
  125. lcd.print(“Distance: “); // Printe “Distance” sur LCD
  126. lcd.print(distanceCm); // Printe la valeur Obtenue sur LCD
  127. lcd.print(” cm “); // Printe l’unité sur LCD
  128. delay(10);
  129. lcd.setCursor(0,1);
  130. lcd.print(“Angle: “);
  131. lcd.print(pos);
  132. lcd.print(” deg “);
  133. delay(2000);
  134. }
  135. }
  136. else{
  137. digitalWrite(buzzer, LOW);
  138. digitalWrite(ledPin1, LOW);
  139. digitalWrite(ledPin2, LOW);
  140. }

  141. lcd.setCursor(0,0); //
  142. lcd.print(“Distance: “); //
  143. lcd.print(distanceCm); //
  144. lcd.print(” cm “);
  145. delay(10);
  146. lcd.setCursor(0,1);
  147. lcd.print(“Angle: “);
  148. lcd.print(pos);
  149. lcd.print(” deg “);
  150. delay(80);
  151. }
  152. }

Related Articles

Leave a Reply

Back to top button
error: Content is protected !!