Esp01 read sensor value

Hi!!
I am trying to read a digital value from a soil moisture detector module, that has a digital output, with my Esp 01. But in esphome I am not able to get the info.

My yaml is:

binary_sensor:
  - platform: gpio
    id: humidity
    pin: RX

I am using the RX that is for input.
Thanks

Well one thing is for sure, a binary sensor won’t work. A binary sensor is on or off.

What model is the sensor?

And RX is not a valid pin name according to the schemes I know. Check the pinout diagram for your specific board.

You mean call it GPIO3 instead of RX.

Thanks for answering the sensor is this:
https://es.aliexpress.com/item/1005005141594731.html?pdp_npi=2%40dis!EUR!3%2C07€!2%2C15€!!!!!%40211b5e2116904708397303871eebe7!12000031828018654!btf&_t=pvid%3A88e6c333-25b0-4691-b792-7c74c19e366e&afTraceInfo=1005005141594731__pc__pcBridgePPC__xxxxxx__1690470840&spm=a2g0o.ppclist.product.mainProduct&gatewayAdapt=glo2esp

I changed in the yaml but nothing at all

Not even logs? :page_with_curl:

ESP01 only has one unallocated I/O pin, GPIO2. Other pins can cause the ESP01 to get confused and not be programmed or not boot successfully.

I’m assuming you are connecting the ESP01 to the D0 on the sensor? Without doing more investigation, I’m not sure if you’d need pull up or pull down resistors on that line.

Are you able to load your code onto the ESP01?

“The probe uses the form of analog resistance to detect the moisture content of the soil. Interface: ±AO DO. AO analog outputs and DO digital outputs. Departure. The current is about 10mA.” Good old Aliexpress with it’s descriptions. Esp01 doesn’t have an A0 pin so you need to follow the more complicated option.


I’m not sure what bit you connect to the ESP pin. It doesn’t look like it’s meant to be connected directly.

Yep that’s the problem I have to do the schema. Thanks and if I want to do a sensor in the yaml not a binary_sensor. What type of platform I shoud use?

“Principle: When the probe detection exceeds the set value, DO outputs low level, and the triode is turned on. load work. 1K is the current limiting resistor, and 10K is the pull-up resistor of D0 port.”

For “triode” I think it means an NPN transistor. Could this be a binary sensor that only detects if there is moisture above a level? I would assume the collector end of the transistor is connected to the pin on the Esp01.

I’m making several assumptions about the example circuit. The designation from top to bottom is Analog Output, Digital Output, GND and VCC. The potentiemter allows you to set the leve that the digital output will switch.

So as the moisture level changes current will be turned on or off according to your setting. Personally before I connected this module I would use a multimeter to make sure how the digital output switches. You might need to connect the digital output to VCC with a 10k resistor or it just may not switch.

Then, once I was happy with the functionality I’d connect to the ESP01.

“Corrosion Resistance” I suspect it’s resistance to corrosion is very much relative. It’s a cheap Chinese device and if the current runs all the time it won’t last long. As it rusts in the soil it will affect that set valve and be set off at different level.
If I was to do a moisture sensor for soil I’d make a capacitive sensor covered in plastic and use an ESP32. But I’d still like to see this device work for the OP.

I mount the circuit, but the D0 output I don’t understand very well how is working.
The A0 it’s working fine, when is wet I get around 4V and when is dry I get 7V.
This is the schema and the circuit. Maybe is something wrong

The D0 output is always getting 3V before 1k resistor and 0,7V after. I moved the valve but nothing changed

The purpose of the triac is to switch a high current, for example to switch on a pump. If you are only after the logic level to your ESP01, then you can drop that part of the circuit complately and just have the pull up resistor connected to Dout.

Even if you are using the triac to switch a load, I would still do a test with just the pull up resistor in place, remove the triac from the circuit and then monitor what Dout does. Dry should give you a “low” level and “wet” a high. To do this test you don’t need to connect the ESP01, just use a multimeter.

Also you really don’t need that much solder on the pins!

Thanks now it’s working, I get hight voltage when is wet and low when is dry.
Thanks to all for your help

If you leave DC permanently connected expect a lifetime (corrosion!) of your probe of a few month only :put_litter_in_its_place: