Home » , , » Sonar Radar System using Arduino

Sonar Radar System using Arduino

Although they rely on two fundamentally different types of wave transmission, Radio Detection and Ranging (RADAR) and Sound Navigation and Ranging (SONAR) both are remote sensingsystems with important military, scientific and commercial applications. RADAR sends out electromagnetic waves, while active SONAR transmits acoustic (i.e., sound) waves. In both systems, these waves return echoes from certain features or targets that allow the determination of important properties and attributes of the target (i.e., shape, size, speed, distance, etc.). Because electromagnetic waves are strongly attenuated (diminished) in water , RADAR signals are mostly used for ground or atmospheric observations. Because SONAR signals easily penetrate water, they are ideal for navigation and measurement under water.


  • Connecting wires.

ULTRASONIC (HC-SR04)The HC-SR04 Ultrasonic Sensor is a very affordable proximity/distance sensor that has been used mainly for object avoidance in various robotics projects . It essentially gives your Arduino eyes / spacial awareness and can prevent your robot from crashing or falling off a table. It has also been used in turret applications, water level sensing, and even as a parking sensor. This simple project will use the HC-SR04 sensor with an Arduino and a Processing sketch to provide a neat little interactive display on your computer screen.
SERVOA servomotor is a rotary actuator or linear actuator that allows for precise control of angular or linear position, velocity and acceleration. It consists of a suitable motor coupled to a sensor for position feedback.
ARDUINOArduino is a computer hardware and software company, project, and user community that designs and manufactures microcontroller kits for building digital devices and interactive objects that can sense and control objects in the physical world.

  • /*------------------------------------------
  •   Sonar Radar System
  •   By https://nonstopengineering.blogspot.com/
  •   Using Arduino,Ultrasonic and Servo
  •   ------------------------------------------*/
  • #include <Servo.h> //Servo Library

  • const int trigPin = 9; //Initializing trigger pin
  • const int echoPin = 8; //Initializing echo pin
  • long duration;        
  • int distance;

  • Servo myServo; // Creating a servo object for controlling the servo motor

  • void setup() {
  •   pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
  •   pinMode(echoPin, INPUT); // Sets the echoPin as an Input
  •   Serial.begin(9600);     //Sets Baud rate for Serial communication
  •   myServo.attach(10); // Defines on which pin is the servo motor attached
  • }
  • void loop() {
  •   for(int a=0;a<=180;a++) // rotates the servo motor from 0 to 180 degrees
  •   {  
  •   myServo.write(a); //Sending stes to servo which servo should move
  •   delay(20);
  •   distance = Distance(); // Calls a function for calculating the distance measured by the Ultrasonic sensor for each degree
  •   Serial.print(a); // Sends the current degree into the Serial Port
  •   Serial.print(","); // Sends addition character right next to the previous value needed later in the Processing IDE for indexing
  •   Serial.println(distance); // Sends the distance value into the Serial Port
  •   }
  •   for(int b=180;b>0;b--) //   Rversing rotation from 180 to 0 degrees
  •   {  
  •   myServo.write(b); 
  •   delay(20);
  •   distance = Distance();
  •   Serial.print(b);
  •   Serial.print(",");
  •   Serial.println(distance);
  •   }
  • }

  • int Distance() // Function for calculating the distance measured by the Ultrasonic sensor
  •   digitalWrite(trigPin, LOW);  // Sets the trigPin on LOW state for 2 micro seconds
  •   delayMicroseconds(2); 
  •   digitalWrite(trigPin, HIGH); // Sets the trigPin on HIGH state for 10 micro seconds
  •   delayMicroseconds(10); 
  •   digitalWrite(9, LOW);
  •   duration = pulseIn(echoPin, HIGH); // Reads the echoPin, returns the sound wave travel time in microseconds
  •   distance= duration*0.034/200; //Converting distance into meters
  •   return distance;
  • }


Post a Comment

Back to Top