SubName: Reading a water sensor (2 pin black)
Description: You can use this simple code to read a 2 pin rain/droplet/water sensor detector.
When the sensor is completely dry (no water resistance) the logs will show the value 1023. With this particular sensor the more water there is on it the lower the value will go. I personally found that the value 750 is a good water warning trigger (that is basically 1 drop of water).
Tags: Water, Sensor, Arduino, ESP
Actual sensor/module
Description: You can use this simple code to read a 2 pin rain/droplet/water sensor detector.
When the sensor is completely dry (no water resistance) the logs will show the value 1023. With this particular sensor the more water there is on it the lower the value will go. I personally found that the value 750 is a good water warning trigger (that is basically 1 drop of water).
********************* PROGRAM STARTING ****************
AppStart
1023
It's dry
1023
It's dry
1023
It's dry
1023
It's dry
1023
It's dry
1023
It's dry
1023
It's dry
1023
It's dry
1015
It's dry
1016
It's dry
1018
It's dry
1019
It's dry
1020
It's dry
1020
It's dry
778
It's dry
734
It's wet
720
It's wet
703
It's wet
706
It's wet
705
It's wet
703
It's wet
706
It's wet
707
It's wet
709
It's wet
1023
It's dry
1023
It's dry
1023
It's dry
1023
It's dry
1023
It's dry
1023
It's dry
1023
It's dry
1023
It's dry
1023
It's dry
1023
It's dry
1023
It's dry
1023
It's dry
1023
It's dry
1023
It's dry
AppStart
1023
It's dry
1023
It's dry
1023
It's dry
1023
It's dry
1023
It's dry
1023
It's dry
1023
It's dry
1023
It's dry
1015
It's dry
1016
It's dry
1018
It's dry
1019
It's dry
1020
It's dry
1020
It's dry
778
It's dry
734
It's wet
720
It's wet
703
It's wet
706
It's wet
705
It's wet
703
It's wet
706
It's wet
707
It's wet
709
It's wet
1023
It's dry
1023
It's dry
1023
It's dry
1023
It's dry
1023
It's dry
1023
It's dry
1023
It's dry
1023
It's dry
1023
It's dry
1023
It's dry
1023
It's dry
1023
It's dry
1023
It's dry
1023
It's dry
B4X:
'WIRE LEGEND for black 2 pin water sensor
'GND = GND
'VCC = 5V
'A0 = A0
'*************************
'*** BOARD TYPE ***
'*** Mega or Mega 2560 ***
'*************************
Sub Process_Globals
'These global variables will be declared once when the application starts.
'Public variables can be accessed from all modules.
Public Serial1 As Serial
Private Sensor_A0 As Pin
Private TmrReadings As Timer
Private sensortrigger As Int = 750
End Sub
Private Sub AppStart
Serial1.Initialize(115200)
Log("AppStart")
Sensor_A0.Initialize(0, Sensor_A0.AnalogRead)
TmrReadings.Initialize("Readings_Tick", 1000)
TmrReadings.Enabled = True
End Sub
Sub Readings_Tick
Log(Sensor_A0.AnalogRead)
If Sensor_A0.AnalogRead < sensortrigger Then Log("It's wet") Else Log("It's dry")
End Sub
Actual sensor/module
Last edited: