Advertisement
Guest User

Untitled

a guest
Nov 11th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. #define TRIGGER_PIN D1
  2. #define ECHO_PIN D0
  3.  
  4. void setup() {
  5. Serial.begin (115200);
  6. pinMode(TRIGGER_PIN, OUTPUT);
  7. pinMode(ECHO_PIN, INPUT);
  8. pinMode(BUILTIN_LED, OUTPUT);
  9. }
  10.  
  11. void loop() {
  12. long duration, distance;
  13. digitalWrite(TRIGGER_PIN, LOW); // Added this line
  14. delayMicroseconds(2); // Added this line
  15. digitalWrite(TRIGGER_PIN, HIGH);
  16. delayMicroseconds(10); // Added this line
  17. digitalWrite(TRIGGER_PIN, LOW);
  18. duration = pulseIn(ECHO_PIN, HIGH);
  19. distance = (duration/2) / 29.1;
  20. Serial.print(distance);
  21. Serial.println(" cm");
  22. delay(1000);
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement