Created
October 22, 2023 04:25
-
-
Save kakopappa/7d45a826ba02203ab8571b735add45c9 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 | |
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(SIGNAL_PIN); // make a reading from sensor | |
digitalWrite(POWER_PIN, LOW); // turn off the sensor | |
Serial.printf("value: %d\n", value); // print reading | |
delay(1000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment