Last active
September 25, 2023 09:42
-
-
Save kakopappa/bc5a7152c02e4e692ca9ae6708fe6814 to your computer and use it in GitHub Desktop.
Sinric Pro Motion Sensor. Tutorial: https://help.sinric.pro/pages/tutorials/motion-sensors/HC-SR501-HC-SR505-AM312-HC-SR312.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #if defined(ESP8266) | |
| #define SENSOR_PIN D1 | |
| #elif defined(ESP32) | |
| #define SENSOR_PIN 26 | |
| #elif (ARDUINO_ARCH_RP2040) | |
| #define SENSOR_PIN 5 | |
| #endif | |
| int newState; | |
| int oldState; | |
| void setup() { | |
| Serial.begin(9600); | |
| pinMode(SENSOR_PIN, INPUT); | |
| Serial.printf("Wait 10 secs for the PIR sensor to calibrate properly\r\n"); | |
| delay(1000 * 10); | |
| oldState = digitalRead(SENSOR_PIN); // read the starting state | |
| } | |
| void loop() { | |
| newState = digitalRead(SENSOR_PIN); // read current state | |
| if(oldState != newState) { | |
| if (newState == HIGH) { | |
| Serial.println("Movement detected!"); | |
| } else { | |
| Serial.println("Movement not detected!"); | |
| } | |
| oldState = newState; | |
| } | |
| delay(100); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment