Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.39 KB | None | 0 0
  1. long duration,cm;
  2.  
  3. void setup(){
  4. pinMode(10, OUTPUT);
  5. pinMode(11, INPUT);
  6. Serial.begin(9600);
  7. }
  8.  
  9. void loop(){
  10. digitalWrite(11, LOW);
  11. delayMicroseconds(2);
  12. digitalWrite(11, HIGH);
  13. delayMicroseconds(10);
  14. digitalWrite(11, LOW);
  15. duration = pulseIn(11, HIGH);
  16. cm=duration/29/2;
  17.  
  18. Serial.print(cm);
  19. Serial.print("cm");
  20. Serial.println();
  21. delay(500);
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement