Advertisement
zoro-10

Digital Infrared Motion Sensor

Apr 1st, 2024 (edited)
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.45 KB | None | 0 0
  1. https://imgur.com/a/N8xWKFg
  2.  
  3.  
  4. int sensorState = 0;
  5. void setup()
  6. {
  7. pinMode(2, INPUT);
  8. pinMode(LED_BUILTIN, OUTPUT);
  9. }
  10. void loop()
  11. {
  12.  // read the state of the sensor/digital input
  13. sensorState = digitalRead(2);
  14.  // check if sensor pin is HIGH. if it is, set the
  15.  // LED on.
  16. if (sensorState == HIGH) {
  17. digitalWrite(LED_BUILTIN, HIGH);
  18.  } else {
  19. digitalWrite(LED_BUILTIN, LOW);
  20.  }
  21. delay(10); // Delay a little bit to improve simulation performance
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement