Rain Sensor (FC-37) with MicroPython

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
axityatrips
Posts: 1
Joined: Sat Jul 06, 2019 3:35 pm

Rain Sensor (FC-37) with MicroPython

Post by axityatrips » Sat Jul 06, 2019 3:43 pm

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

User avatar
jimmo
Posts: 869
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia

Re: Rain Sensor (FC-37) with MicroPython

Post by jimmo » Sat Jul 06, 2019 11:29 pm

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.

rpr
Posts: 75
Joined: Sat Oct 27, 2018 5:17 pm

Re: Rain Sensor (FC-37) with MicroPython

Post by rpr » Sun Jul 07, 2019 6:20 am

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))
adc.atten(ADC.ATTN_11DB)

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

Post Reply