B4R Code Snippet Reading a water/soil sensor (3 pin red)

Discussion in 'B4R Code Snippets' started by Peter Simpson, Aug 20, 2018.

  1. Peter Simpson

    Peter Simpson Expert Licensed User

    SubName: Reading a water sensor (3 pin red)
    Description: You can use this simple code to read a 3 pin rain/droplet/water sensor detector.

    When the sensor is completely dry (no resistance) the logs will show 0(zero). With this particular sensor the more water there is on it, the more there is resistance, thus the reading goes higher.

    ********************* PROGRAM STARTING ****************
    AppStart
    0
    it's dry
    0
    it's dry
    515
    It's Wet
    542
    It's Wet
    657
    It's Wet
    653
    It's Wet
    693
    It's Wet
    672
    It's Wet
    659
    It's Wet
    653
    It's Wet
    649
    It's Wet
    649
    It's Wet
    649
    It's Wet
    635
    It's Wet
    583
    It's Wet
    578
    It's Wet
    580
    It's Wet
    639
    It's Wet
    656
    It's Wet
    648
    It's Wet
    648
    It's Wet
    599
    It's Wet
    557
    It's Wet
    550
    It's Wet
    535
    It's Wet
    385
    It's Wet
    375
    It's Wet
    369
    It's Wet
    362
    It's Wet
    355
    It's Wet
    355
    It's Wet
    353
    It's Wet
    389
    It's Wet
    0
    it's dry
    0
    it's dry
    0
    it's dry
    0
    it's dry
    0
    it's dry
    0
    it's dry
    0
    it's dry
    0
    it's dry
    0
    it's dry
    0
    it's dry
    0
    it's dry
    0
    it's dry
    0
    it's dry
    0
    it's dry

    Code:
    'WIRE LEGEND for red 3 pin water sensor
    'GND = GND
    'VCC = 5V
    'S (Sensor) = 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 V_Pin_A0 As Pin
        
    Private TmrReadings As Timer
    End Sub

    Private Sub AppStart
        Serial1.Initialize(
    115200)
        
    Log("AppStart")
        V_Pin_A0.Initialize(
    0, V_Pin_A0.AnalogRead)
        TmrReadings.Initialize(
    "Readings_Tick"1000)
        TmrReadings.Enabled = 
    True
    End Sub

    Sub Readings_Tick
        
    Log(V_Pin_A0.AnalogRead)
        
    If V_Pin_A0.AnalogRead = 0 Then Log("It's dry"Else Log("It's wet")
    End Sub
    Tags: Water, Sensor, Arduino, ESP

    Arduino wiring
    Water Sensor_bb.png

    Actual sensor/module
    Water-Level-Sensor.jpg
     
    Last edited: Aug 20, 2018
  2. Beja

    Beja Expert Licensed User

    You mean dry is high resistance (impedance)
    More water means less resistance, hence high value reading.
     
  3. embedded

    embedded Member Licensed User

    L
    More water level means current path is shorter than previous one.... shorter path having less resistance....less resistance...less voltage drop....high adc value..
     
    Peter Simpson and Beja like this.
  4. Beja

    Beja Expert Licensed User

    Ok.. I think there was misunderstanding in my part.
    The moisture sensor confused me and I don't know why it was put in the example.. Soil moisture sensor is completely buried in the soil.
    Thanks
     
    Last edited: Mar 10, 2019
  5. Peter Simpson

    Peter Simpson Expert Licensed User

    Because it does not matter if it's placed in a cup of water or placed in soil, resistance changes the deeper the sensor is/more moist the sensor becomes.

    Pint time, catcha on da flip side ;)
     
    Beja likes this.
  6. Beja

    Beja Expert Licensed User

    You are right. If anything matters, soil moisture gives you more readings (for the same point) depending on the moisture level, while water only gives one value for each point on the scale.
     
    Peter Simpson likes this.
  7. Peter Simpson

    Peter Simpson Expert Licensed User

    I've updated the title, thank you...
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice