Created
October 22, 2023 04:24
-
-
Save kakopappa/aff71487783487cbfbdef4006eaab809 to your computer and use it in GitHub Desktop.
Detecting floods using water sensor : https://help.sinric.pro/pages/tutorials/custom-device-types/water-sensor/flood-leak-rain-sensor.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) | |
const int sPin = A0; | |
const int vccPin = D2; | |
#elif defined(ESP32) | |
const int sPin = 34; | |
const int vccPin = 17; | |
#elif defined(ARDUINO_ARCH_RP2040) | |
const int sPin = 26; | |
const int vccPin = 6; | |
#endif | |
const int FLOOD_THRESHOLD = 100; | |
void setup() { | |
Serial.begin(9600); | |
pinMode(sPin, INPUT); | |
pinMode(vccPin, OUTPUT); | |
digitalWrite(vccPin, LOW); // turn off the sensor at the begining. | |
} | |
void loop() { | |
digitalWrite(vccPin, HIGH); // turn on the power for sensor. | |
delay(100); // wait 100ms | |
int value = analogRead(sPin); // make a reading from sensor | |
digitalWrite(vccPin, LOW); // turn off the sensor | |
if (value > FLOOD_THRESHOLD) { | |
Serial.print("Flooding detected"); | |
} | |
delay(1000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment