Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define echo 12
- #define trig 13
- void setup() {
- // put your setup code here, to run once:
- pinMode(trig, OUTPUT);
- pinMode(echo, INPUT);
- Serial.begin(9600);
- }
- void loop() {
- // put your main code here, to run repeatedly:
- long dur, dis;
- digitalWrite(trig, LOW);
- delayMicroseconds(2);
- digitalWrite(trig, HIGH);
- delayMicroseconds(10);
- digitalWrite(trig, LOW);
- dur = pulseIn(echo, HIGH);
- dis = (dur/2)/29.1;
- Serial.println(dis);
- delay(100);
- }
Add Comment
Please, Sign In to add comment