This a very simple project to find the distance between .While going through the internet i got an idea to make something using ultrasonic sensor& arduino uno.
In this project i will use SR04 ultrasonic sensor.
And you will also need ping.h library.You can find it on the internet.
Wiring...
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 for making this...
#include <NewPing.h>
#define TRIGGER_PIN 12
#define ECHO_PIN 11
#define MAX_DISTANCE 200
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);
void setup() {
Serial.begin(115200);
}
void loop() {
delay(50);
Serial.print("Ping: ");
Serial.print(sonar.ping_cm());
Serial.println("cm");
}
Comments