Created
September 23, 2023 17:23
-
-
Save kakopappa/ce5b95c7618826005ef39bb1861cb6f1 to your computer and use it in GitHub Desktop.
Sinric Pro Contact Sensor. Tutorial: https://help.sinric.pro/pages/tutorials/contact-sensors/contact.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 D2 | |
| #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_PULLUP); | |
| 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("Sliding window is open"); | |
| } else { | |
| Serial.println("Sliding window is closed"); | |
| } | |
| oldState = newState; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment