Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define TRIGGER_PIN D1
- #define ECHO_PIN D0
- void setup() {
- Serial.begin (115200);
- pinMode(TRIGGER_PIN, OUTPUT);
- pinMode(ECHO_PIN, INPUT);
- pinMode(BUILTIN_LED, OUTPUT);
- }
- void loop() {
- long duration, distance;
- digitalWrite(TRIGGER_PIN, LOW); // Added this line
- delayMicroseconds(2); // Added this line
- digitalWrite(TRIGGER_PIN, HIGH);
- delayMicroseconds(10); // Added this line
- digitalWrite(TRIGGER_PIN, LOW);
- duration = pulseIn(ECHO_PIN, HIGH);
- distance = (duration/2) / 29.1;
- Serial.print(distance);
- Serial.println(" cm");
- delay(1000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement