- VCC: positive power supply (3-5V)
- GND: power supply is negative
- DO: TTL switching signal output
- AO: analog signal output.
Programming
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- const int sensorMin = 0;
-
-
-
- const int sensorMax = 1024;
-
-
-
- void setup()
- {
-
- Serial.begin(9600);
- }
- void loop()
- {
-
-
- int sensorReading = analogRead(A0);
-
-
-
-
- int range = map(sensorReading, sensorMin, sensorMax, 0, 3);
-
-
- switch (range)
- {
- case 0:
-
-
- Serial.println("Flood");
- break;
-
- case 1:
-
-
- Serial.println("Touched");
- break;
-
- case 2:
-
-
- " below.
- Serial.println("Not touched");
- break;
- }
-
- delay(1);
-
- }
Explanation
- If the Sensor Board is completely soaked; "case 0" will be activated and "Flood" will be sent to the serial monitor.
- If the Sensor Board has water droplets on it; "case 1" will be activated and "Touched" will be sent to the serial monitor.
- If the Sensor Board is dry; "case 2" will be activated and "Not touched" will be sent to the serial monitor.
- The output in "case 2", "Not Raining" is just for this demonstration.
- When I used this code in production I omitted the output for this case and just had the alert.
Output
Figure 2:Output
Read more articles on Arduino: