Distance Detection using SONAR
Distance Detection using SONAR
Just Arduino Things | TW TechieTube
Sonar (sound navigation and ranging) is a technique that uses sound propagation (usually underwater, as in submarine navigation) to navigate, communicate with or detect objects on or under the surface of the water, such as other vessels. Sonar, short for Sound Navigation and Ranging, is helpful for exploring and mapping the ocean because sound waves travel farther in the water than do radar and light waves.
- Arduino UNO (1)
- Ultrasonic Sensor (1)
- Breadboard (1)
- Jumper Cables
A very Simple Project to measure the distance of the obstacle.
In this project You will work on SR04 Ultrasonic sensor.
Connect the SR04 VCC pin to the Arduino 5v
Connect the SR04 GND pin to the Arduino GND
Connect the SR04 TRG pin to the Arduino Digital pin 12
Connect the SR04 ECHO pin to the Arduino Digital pin 11
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). NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance. void setup() { Serial.begin(9600); // Open serial monitor at 9600 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: "); Serial.print(sonar.ping_cm()); // Send ping, get distance in cm and print result (0 = Outside SetDist Range) Serial.println("cm"); }
Comments
Post a Comment