Introduction: Sonar Radar System Using Arduino, Servo & Ultrasonic (HC-SR04)

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.

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.

SERVO: A 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.

ARDUINO: Arduino 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.

Step 1: COMPONENTS:

SERVO

ARDUINO

ULTRASONIC (HC-SR04)

Connecting wires.

Step 2: CIRCUIT DIAGRAM

Step 3: IMAGES

Step 4: Code:

/*------------------------------------------
  Sonar Radar System
  By nonstopengineering
  Using Arduino,Ultrasonic and Servo
  ------------------------------------------*/
#include  //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;
}

Step 5: ARDUINO CODE FILE

Step 6: WORKING:

Comments

author
fingerspete (author)2017-01-23

i made it all working except i cant get the radar program on the pc can you help please

author
baudeagle (author)2016-12-20

Looking at your code, I don't see how this is an effective radar of sorts but
rather just seems to be a sweeping measurement/ranging system. For a
"Radar" of sorts don't you need to essentially map out ranges/sounding
for each arc of rotation? Wouldn't you need to then compare the active/recent
sweeps of the ultrasonic against the saved sweep map/data to determine the
location of a new object or the movement of an object?

author
tzaroon (author)baudeagle2016-12-20

Dude you are wrong a little bit. The above code with give you angle and distance, which we can you in many ways.

This is just one step from me. Now its depends on you how you use.

author
Swansong (author)2016-12-20

Thanks for sharing :)