Hi and welcome back.
As an engineering student, I had to make a
project on sound. So as I was working on arduino, I suddenly got an idea of
making a radar using ultrasound. So actually, it is an obstacle detector with
an auto-firing gun.
Ultrasound is
an oscillating sound pressure wave with a frequency greater
than the upper limit of the human hearing range. Ultrasound devices operate with
frequencies from 20 kHz up to several gigahertzes.
SONAR, SOund Navigation And Ranging system, is a technology which uses ultrasonics. In this system, a short ultrasonic pulse is send at certain time intervals. When there is an obstacle, the wave gets reflected from the obstacle, and gets collected by the receiver.
Before starting any project, it is mandatory to prepare an architecture. You shoud always decide how the project will finallly look like. This process helps to speed up the coding as well as to realize the project in reality.
First, the components used -
GENERATION OF
ULTRASONIC WAVE -
- An ultrasonic wave is generated when an electric field is applied to an array of piezoelectric crystals located on the transducer surface.
- Electrical stimulation causes mechanical distortion of the crystals resulting in vibration and production of sound waves (i.e. mechanical energy). The conversion of electrical to mechanical (sound) energy is called the converse piezoelectric effect.
- Each piezoelectric crystal produces an ultrasound wave.
- The summation of all waves generated by the piezoelectric crystals forms the ultrasound beam. Ultrasound waves are generated in pulses and each pulsecommonly consists of 2 or 3 sound cycles of the same frequency.
ULTRASOUND IMAGING
-
- An ultrasound image is generated when the pulse wave emitted from the transducer is transmitted into the body, reflected off the target and returned to the transducer.
- The transducer waits to receive the returning wave after each pulsed wave. The transducer transforms the echo into an electrical signal.
- This electrical pulses generated are then used for various purposes.
ULTRASOUND
RECEPTION –
- The transmitted wave, on hitting the target, gets scattered and some part of it gets reflected.
- The angle of the incidence is also a major determinant of reflection.
- An ultrasound wave hitting a smooth mirror like interface at a 90 degree angle will result in a perpendicular reflection, while at an angle less than 90 degrees will result in the wave being deflected away from the transducer at an angle equal to the angle of incidence but in the opposite direction.
- When this happens, the signal of the returning echo is weaker.
- Specular reflection occurs at flat, smooth interfaces where the transmitted wave is reflected in a single direction depending on the angle of incidence.
- For specular reflection the wavelength of the ultrasound wave must be smaller than the reflective structure.
- Scattering occurs when the incident wave encounters an interface that is not perfectly smooth.
- Echoes from such surfaces, are generally weaker than those returning from specular reflectors.
- Scattering also occurs when the wavelength of the ultrasound wave is larger than the dimensions of the reflective structure.
SONAR
–
SONAR, SOund Navigation And Ranging system, is a technology which uses ultrasonics. In this system, a short ultrasonic pulse is send at certain time intervals. When there is an obstacle, the wave gets reflected from the obstacle, and gets collected by the receiver.
The time duration is calculated and the distance is
measured between the obstacle and the transmitter by using the following
formula -
Distance = Speed * Time
where →
speed = 340 m/s i.e. the speed of sound, as ultrasonic waves are
sound waves.
time = duration between sent and received pulse. But it is always
taken as time/2 for one way pulse.
This technology is most widely used in submarines and
ships to check the depth of the sea.
Before starting any project, it is mandatory to prepare an architecture. You shoud always decide how the project will finallly look like. This process helps to speed up the coding as well as to realize the project in reality.
First, the components used -
- Arduino
uno
- Ultrasonic
sensor HC-SR04. There are others available, you can use any one you want.
- Mini
servo motors. The hobby motors has enough torque and weight capacity to
move.
- Jumper
wires, Header pins etc.
Next, decide the architecture. Decide where to place
the sensor and a gun and the other components.
First the architecture decided was -
The sensor has a measuring angle of 15°. To make
sure that the sensor does not scan the ground on which it is resting, the
sensor is placed at a certain height.
The height is calculated as follows –
The max range of the sensor is decided by the
user: Let it be ‘x’
The triangle is right angled so –
sin (7.5) = x / (max
height)
Thus the maximum height can be found out.
Same as the above calculation, for a right
angled triangle –Since the sensor has an angle of sensing, the gun placed above
it must also be placed at an angle, so that it will correctly strike the target
at the midpoint.
tan (ß) = (max height of
gun over sensor) / (distance between gun and sensor)
where – ß = Tilt angle for the gun with
horizontal.
It has an error of midpoint calculation. Since
the aperture of the sensor is 15°, it becomes difficult to perfectly point an
object at the midpoint of the object.
Another error that arises is that, the angle
communicated to the other servo holding the gun, will be the starting angle at
which the object is found. So the gun might fire at a location where the object
just starts, resulting in not perfectly hitting of the object.
Well the final idea that was decided was -
But the problem of edge detection was still
persistent.
So now I had to do something in the coding to
correct that error.
Algorithm -
- Initialize
all variables required. Initialize servo pins, sensor pins, I/O ports.
- Rotate
the servo motor on which sensor is mounted.
- For
every angle, the motor rotates, call the function to scan the area.
- Scanning
function checks for one ping. One ping is checking for one pulse of
trigger pin
- If obstacle detected, stop servo motor and return the
distance to calling function.
- If obstacle not detected, return ‘-1’ to calling
function and keep on scanning.
- If
obstacle is detected, then check the angle at which object is detected.
- Return
the angle value to another function controlling the gun position.
- In
gun position function, calculate the angle required for the gun mounted
servo to rotate so that, it comes to rest at the position where the
obstacle is.
- Once
angle is calculated, rotate the servo to that position.
- Call
a function to fire a gun.
- Gun
fires.
- Stop
the entire process, and continue scanning to check for more obstacles.
- If
obstacle detected again, restart the entire process.
Code -
#include <Servo.h>
//Library for servo motor
#include <NewPing.h>
//Lib for using
the ultrasonic sensor
#define trigPin 12
//Initializing the trigger pin at 12
#define echoPin 8
//Initializing echo pin at 8
#define maxRange 50
//Maximum
range of sensor is 4m. Used here is 50cm.
#define minRange 2
//Minimum range for perfect reading is 2cm.
NewPing sonar(trigPin, echoPin, maxRange);
Servo servo1;
//Setting up servo
Servo servo2;
long duration, distance;
int servoPin_1 = 9;
int servoPin_2 = 10;
int ledPin_1 = 13;
int ledPin_2 = 11;
int a = 0;
int q = 0;
float x = 10.00;
float y = 0;
float f = 0;
int o = 0;
float r = 0;
void setup()
{
Serial.begin(9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(ledPin_1, OUTPUT);
pinMode(ledPin_2, INPUT);
servo2.attach(servoPin_2);
//Attach
servo2 to pin10
}
void loop()
{
int i;
servo1.attach(servoPin_1);
// Scans the entire object till the time
object is in detection.
// As detection finishes, the angle of
the motor turned, till object is found, is recorded
for (i = 10; i <= 170; i++)
{
servo1.write(i);
long z = sense();
Serial.println("ZZ");
Serial.println(z);
if (z > -1)
{
a = i;
Serial.println("AA");
Serial.println(a);
servo1.detach();
sevoPos(a,z);
}
delay(50);
}
for (i = 170; i >= 10; i--)
{
servo1.write(i);
long z = sense();
if (z > -1)
{
a = i;
Serial.println("AA");
Serial.println(a);
servo1.detach();
sevoPos(a,z);
}
delay(50);
}
}
// Function for sensing the area, scanning the
area
long sense()
{
digitalWrite(trigPin,LOW);
//Don't send pulse
delayMicroseconds(2);
//Wait for 2 microseconds
digitalWrite(trigPin,HIGH);
//Send a ping or pulse
delayMicroseconds(10);
//Wait for 10 microseconds
digitalWrite(trigPin,LOW);
//Don't send pulse
duration =
pulseIn(echoPin,HIGH);
distance =
duration/58.2;
//Calculate distance in cm
if (distance >= maxRange || distance
<= minRange)
{
Serial.println("NO
OBJECT"); //no obj detect
return(-1);
}
else
{
Serial.println("OBJECT
DETECTED"); //obj detect
Serial.println(distance);
return(distance);
}
delay(50);
}
//For angle calculation
long sevoPos(int m, long y)
{
if (m <= 90)
{
float s = 90.00 + m;
//Takes inside angle in degrees
Serial.println("SS");
Serial.println(s);
float b = (s*71.00)/4068.00;
//Converts
into radians
Serial.println("BB");
Serial.println(b);
float p = sqrt(x*x + y*y -
2*x*y*cos(b)); //Calculates the length
Serial.println("PP");
Serial.println(p);
float c = (y*sin(b))/p;
//Sine of the angle req. in radians
Serial.println("cc");
Serial.println(c);
float d = asin(c);
//Sine inverse in radians
Serial.println("DD");
Serial.println(d);
float e = (d*4068.00)/71.00;
//Converts radians into
degrees
Serial.println("EE");
Serial.println(e);
float f = 90 - e;
//Adds the total angle for second servo from
its starting point
Serial.println("FF");
Serial.println(f);
o = (int) f;
Serial.println("OO");
Serial.println(o);
q = o - 3;
}
else
{
float s = 180.00 - m;
//Takes inside angle in degrees
float r = 90.00 + s;
float b = (r*71.00)/4068.00;
//Converts into radians
Serial.println("BB");
Serial.println(b);
float p = sqrt(x*x + y*y -
2*x*y*cos(b)); //Calculates the length
Serial.println("ZZ");
Serial.println(p);
float c = (y*sin(b))/p;
//Sine of the
angle req. in radians
Serial.println("cc");
Serial.println(c);
float d = asin(c);
//Sine inverse in radians
Serial.println("DD");
Serial.println(d);
float e = (d*4068.00)/71.00;
//Converts radians into degrees
Serial.println("EE");
Serial.println(e);
float f = 90 + e;
//Adds the total angle for second servo from its starting point
Serial.println("FF");
Serial.println(f);
o = (int) f;
Serial.println("OO");
Serial.println(o);
q = o + 3;
}
servo2.write(q);
//Moves servo2 upto the point the object is found.
for(int j = 0; j <= 5; j++)
{
digitalWrite (ledPin_1,
HIGH);
digitalWrite (ledPin_2,
HIGH);
delay (1000);
digitalWrite (ledPin_1, LOW);
digitalWrite (ledPin_2, LOW);
delay (500);
}
}
A gun was not used, instead leds were used to
show gun firing. After completing the project, the final look was -
The gun made here is a paper gun. A toy gun can
also be used, where servo motor may be used to trigger the gun.
APPLICATION :-
This concept can be used in fishing. Ultrasonic sensors work best underwater, than above the water, because of attenuation. The sensor will be allowed to rotate freely under the water, while there will be a harpoon on the boat, ready to fire at the fish.
Once, the ultrasonic sensor detects the movement of the fish, it will relay the position of the fish. And accordingly the hook will be fired and it will pull out the fish. !!
FUTURE SCOPE :-
Thank u ....
APPLICATION :-
This concept can be used in fishing. Ultrasonic sensors work best underwater, than above the water, because of attenuation. The sensor will be allowed to rotate freely under the water, while there will be a harpoon on the boat, ready to fire at the fish.
Once, the ultrasonic sensor detects the movement of the fish, it will relay the position of the fish. And accordingly the hook will be fired and it will pull out the fish. !!
FUTURE SCOPE :-
- The concept of ultrasound can be used for automatic flight stabilization of any drone or quadcopter flying at a relatively low height. In some military scenarios where, a quadcopter is needed to be flown at a very low height for reconnaissance mission. To avoid being detected by radar, any flying object is needed to be flown at an altitude less than the minimum radar height. In such cases, the ultrasonic sensor kept on the belly of the craft will automatically detect the height for which it is flying. A fixed value of altitude is given and the drone is instructed to fly at that given altitude. If by any mistake the height increases or decreases, the ultrasonic sensor will detect the change in height from sensor to ground. It may then increase its rotor speed and rise or fall to its desired altitude.
- Another scope for this project is, it can be used to track down any person. Ultrasonic sensor on its own is precise but it cannot differentiate between non-living objects and living objects. This problem can be solved by using a heat sensor. Each and every thing has a unique heat signature. This property can be exploited by using heat sensors and infrared detectors to precisely pinpoint any object or person needed to be shot down. The ultrasonic sensor will detect the objects in front of it. Then the heat sensors and infrared sensors will check for the different heat signatures. Correspondingly it will track down the object needed.
- Automatic driverless cars can use ultrasound to detect obstacles and drive. Driverless cars use a microcontroller to make an image for itself. All available sensors make a virtual image for the microcontroller. Accordingly, it will drive the car. It can use ultrasonic sensors placed on its sides to check for obstacles. If anything is present, it will tell the micro-controller to steer the car away from it.
Thank u ....
The structure was made by my friend Nimesh Khopade.
Image and project was developed by myself and Shrikant Pal
Thank u once again ...
Any suggestions or coding problems please do comment......








good work man :)
ReplyDeleteThanx bro... :)
Delete