Advertisement
Guest User

Untitled

a guest
Feb 13th, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. //This sketch demonstrates how to interface with ultrasonic sensors using the Arduino and NewPing library
  2.  
  3. #include <NewPing.h>
  4.  
  5. int TRIGGER = 12;
  6. int ECHO = 11;
  7.  
  8. //Declare a sonar object specifying the trigger and echo pins
  9. NewPing sonar(TRIGGER, ECHO);
  10.  
  11. void setup(){
  12. //Start serial at 115200 baud rate
  13. Serial.begin(115200);
  14. }
  15.  
  16. void loop(){
  17. //get current measurement from sensor in centimeters
  18. int distance = sonar.ping_cm();
  19. //print it to the serial monitor
  20. Serial.print(distance);
  21. Serial.println("cm");
  22. //pause slightly before rereading the sensor again, don't make this value less than 30
  23. delay(100);
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement