Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //This sketch demonstrates how to interface with ultrasonic sensors using the Arduino and NewPing library
- #include <NewPing.h>
- int TRIGGER = 12;
- int ECHO = 11;
- //Declare a sonar object specifying the trigger and echo pins
- NewPing sonar(TRIGGER, ECHO);
- void setup(){
- //Start serial at 115200 baud rate
- Serial.begin(115200);
- }
- void loop(){
- //get current measurement from sensor in centimeters
- int distance = sonar.ping_cm();
- //print it to the serial monitor
- Serial.print(distance);
- Serial.println("cm");
- //pause slightly before rereading the sensor again, don't make this value less than 30
- delay(100);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement