Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define trigPin D5
- #define echoPin D6
- void setup() {
- pinMode(D10, OUTPUT);
- Serial.begin (115200);
- pinMode(trigPin, OUTPUT);
- pinMode(echoPin, INPUT);
- }
- void loop() {
- long duration, distance;
- digitalWrite(trigPin, LOW); // Added this line
- delayMicroseconds(2); // Added this line
- digitalWrite(trigPin, HIGH);
- delayMicroseconds(10); // Added this line
- digitalWrite(trigPin, LOW);
- duration = pulseIn(echoPin, HIGH);
- distance = (duration/2) / 29.1;
- Serial.print(distance);
- Serial.println(" cm");
- if (distance < 100)
- {
- // actie A
- Serial.println("Lichtje aan");
- digitalWrite(D10,LOW);
- }
- else
- {
- // actie B
- Serial.println("Lichtje uit");
- digitalWrite(D10,HIGH);
- }
- delay(500);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement