Project Name:- Ultrasound sensor interface with arduino
Today i m going to interface the ultrasonic sensor with arduino arduino.
# Components required
1> Ultrasonic sensor
2> Arduino
3>Arduino cable
4>Computer with arduino ide software
Ultrasonic sensor
fig:- ultrasonic sensor
Ultrasonic sensor is a special type of transducer used for ultrasonic proximity sensors, It allows the transmission and reception of the sound waves.The sound wave is emitted by the transducer which are strike on object and returns to the receiver of transducer. Time delay between transmitting and receiving the sound waves is directly proportional to the distance of the object which is clearly shown on figure below
Fig:- Working mechanism of ultrasonic sensor
circuit connection
Ultrasonic sensor has four pin VCC,GND,Trigger and Echo. VCC and GND are connected to 5V and Gnd pin on arduino respectively. Trigger and Echo pins are connected to 12 and 11 number pins of arduino.
Fig:-circuit diagram
When the circuit is completed then connect the arduino with PC using arduino cable and upload the following code.
Code
#include <NewPing.h>
#define TRIGGER_PIN 12 // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN 11 // Arduino pin tied to echo pin on the ultrasonic sensor.
#define MAX_DISTANCE 200 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
void setup() {
Serial.begin(115200); // Open serial monitor at 115200 baud to see ping results.
}
void loop() {
delay(50); // Wait 50MS between pings (about 20 pings/sec). 29MS should be the shortest delay between pings.
Serial.print("Ping: ");
int value=sonar.ping_cm();
Serial.print(value);// Send ping, get distance in cm and print result (0 = outside set distance range)
Serial.println("cm");
}
Upload the code
Open the serial monitor
Serial monitor display the measured distance by ultrasound sensor