Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- long duration,cm;
- void setup()
- {
- pinMode(11, OUTPUT);
- pinMode(10, INPUT);
- Serial.begin(9600);
- }
- void loop()
- {
- digitalWrite(11, LOW);
- delayMicroseconds(2);
- digitalWrite(11, HIGH);
- delayMicroseconds(10);
- digitalWrite(11, LOW);
- duration = pulseIn(10,HIGH);
- cm=duration/29/2;
- Serial.print(cm);
- Serial.print("cm");
- Serial.println();
- delay(500);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement