Page 1 of 1

Rain Sensor (FC-37) with MicroPython

Posted: Sat Jul 06, 2019 3:43 pm
by axityatrips
I need to know how to interface a FC-37 with ESP32 using MicroPython
I need to make a flood alarm and my idea is that I will connect the FC-37 with ESP32 on Pin D33 and D27, what I want is that the buzzer and led glows along wii that I want that there will also be a trigger that publishes a message which says Flooded. BTW I'm using Adafruit.IO

Re: Rain Sensor (FC-37) with MicroPython

Posted: Sat Jul 06, 2019 11:29 pm
by jimmo
The FC-37 has two ways you can use it:
- A simple "is there rain" detector -- the D0 pin will be either on or off.
- Or "how much rain is there" -- the A0 pin will be a voltage that changes based on the amount of water present on the sensor.

So you only need to use one of the pins, depending on what you want to do. If you're using D0, then you can access it by just reading the pin value using machine.Pin (set it to input mode, then access it's .value()). With A0, you'll have to use one of the ADC pins on the ESP32.

Re: Rain Sensor (FC-37) with MicroPython

Posted: Sun Jul 07, 2019 6:20 am
by rpr
As @jimmo says, it is quite easy with micropython. Here is my code:

Code: Select all

from machine import Pin, ADC
from time import sleep

d = Pin(27, Pin.IN)
adc = ADC(Pin(33))

def loopreading():
    while True:
        if d.value() > 0:
            x = "No Rain"
            x = "Rain"
        print(,"  ",x)