capacitive moisture sensor

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
Jager
Posts: 6
Joined: Tue Jun 23, 2020 7:18 pm

capacitive moisture sensor

Post by Jager » Thu Jun 25, 2020 3:15 pm

I am new to MP, and have searched this archive, and the internet in general. I am using a NodeMCU V3 board, flashed with "..20191220-v1.12.bin". The code outputs a 3, or 2. Just a guess, is that voltage? It is powered at 3.3v with yellow connected to D0. See attached code:

import machine
from machine import Pin
from machine import ADC
import time
from time import sleep


moisture = ADC(0)

while True:
moisture_value = moisture.read()
print(moisture_value)
sleep(3)

Thanks in advance, cheers from Nova Scotia

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: capacitive moisture sensor

Post by pythoncoder » Thu Jun 25, 2020 3:50 pm

You'll need to give us more information about your sensor hardware and how it's connected if we are to be able to help.
Peter Hinch
Index to my micropython libraries.

Jager
Posts: 6
Joined: Tue Jun 23, 2020 7:18 pm

Re: capacitive moisture sensor

Post by Jager » Thu Jun 25, 2020 4:48 pm

Good day Sir,

This is the unit: https://www.amazon.com/Analog-Capacitiv ... il-bullets

I got these specs from the same site.

This analog capacitive soil moisture sensor measures soil moisture levels by capacitive sensing, rather than resistive sensing like other types of moisture sensor
It is made of a corrosion resistant material giving it a long service life
Insert it into soil and impress your friends with the real-time soil moisture data
This module includes an on-board voltage regulator which gives it an operating voltage range of 3.3 ~ 5.5V
This sensor is compatible with DFRobot 3-pin "Gravity" interface, which can be directly connected to the Gravity I/O expansion shield

Features:

Supports 3-Pin Gravity Sensor interface
Analog output
Applications:
Garden plants
Moisture detection
Intelligent agriculture

Specifications:
Operating Voltage: DC 3.3-5.5V
Output Voltage: DC 0-3.0V
Interface: PH2.0-3P
Size: 99x16mm/3.9x0.63"
Quantity: 1 Set

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: capacitive moisture sensor

Post by pythoncoder » Thu Jun 25, 2020 5:00 pm

The ESP8266 ADC has a 0-1V range. Some boards (e.g. the D1 Mini) have a voltage divider to provide a 3.3V range. Unless the NodeMCU V3 has a voltage divider, you will need to provide one to bring the 0-3.0V range down to 0-1.0V.
Peter Hinch
Index to my micropython libraries.

Jager
Posts: 6
Joined: Tue Jun 23, 2020 7:18 pm

Re: capacitive moisture sensor

Post by Jager » Thu Jun 25, 2020 6:38 pm

schem.png
schem.png (10.51 KiB) Viewed 6012 times
I have this image, it's yours from a previous discussion. Is J1 the positive voltage for the sensor? ESP8266 has no attenuation, so this will hopefully get me on track. Thanks! I just connected it with the supplied resistance and wiring, same deal number 2 or 3 in the output. I am getting 1.0 v DC from J1 to ground, same 2 or 3 as the output? :?:

Jager
Posts: 6
Joined: Tue Jun 23, 2020 7:18 pm

Re: capacitive moisture sensor

Post by Jager » Fri Jun 26, 2020 10:31 pm

pythoncoder wrote:
Thu Jun 25, 2020 5:00 pm
The ESP8266 ADC has a 0-1V range. Some boards (e.g. the D1 Mini) have a voltage divider to provide a 3.3V range. Unless the NodeMCU V3 has a voltage divider, you will need to provide one to bring the 0-3.0V range down to 0-1.0V.
Please see drawing, is this what I am after?
capmoisturedrawing-01.jpg
capmoisturedrawing-01.jpg (71.51 KiB) Viewed 5965 times

kevinkk525
Posts: 969
Joined: Sat Feb 03, 2018 7:02 pm

Re: capacitive moisture sensor

Post by kevinkk525 » Sat Jun 27, 2020 5:18 am

as far as I know all nodemcu v3 boards already have a voltage divider so you can put 3.3V to the adc pin. (haven't used the adc pin in a while but got lots of nodemcu v3 here and iirc I always connected 3.3V directly to the adc)
But you can easily check that. Put 3.3V onto your voltage divider and if the adc doesn't read 1024 but ~300 then there's already a voltage divider on the board.


But your drawing is definitely not what you're after. What you did is make a voltage divider on the power supply and then have a 2.2kR before the device which means it won't work at all because it only gets a small fraction of voltage.
You (maybe) need a voltage divider between the output pin and the adc pin.
When refering to your picture, the 3.3V is the output of the sensor and j1 is the adc pin.
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: capacitive moisture sensor

Post by pythoncoder » Sat Jun 27, 2020 10:57 am

I don't have a nodemcu board. You want to power the sensor from 3.3V. If Kevin is right (he usually is ;)) you can connect connect the output directly to the ADC pin: no resistors required.

Then issue

Code: Select all

from machine import ADC
adc = ADC(0)
print(adc.read_u16())
Peter Hinch
Index to my micropython libraries.

Jager
Posts: 6
Joined: Tue Jun 23, 2020 7:18 pm

Re: capacitive moisture sensor

Post by Jager » Sat Jun 27, 2020 10:14 pm

pythoncoder wrote:
Sat Jun 27, 2020 10:57 am
I don't have a nodemcu board. You want to power the sensor from 3.3V. If Kevin is right (he usually is ;)) you can connect connect the output directly to the ADC pin: no resistors required.

Then issue

Code: Select all

from machine import ADC
adc = ADC(0)
print(adc.read_u16())
Thanks!! I connected a new sensor to a new NodeMCU, with a DHT22 also connected and the following code gives me all the inputs i need without resistors.

from machine import Pin
from machine import ADC
from time import sleep
import dht

adc = ADC(0)
sensor = dht.DHT22(Pin(14))
#sensor = dht.DHT11(Pin(14))

while True:
try:
sleep(2)
sensor.measure()
temp = sensor.temperature()
hum = sensor.humidity()
temp_f = temp * (9/5) + 32.0
print('Temperature: %3.1f C' %temp)
print('Temperature: %3.1f F' %temp_f)
print('Humidity: %3.1f %%' %hum)
sleep(1)
print(adc.read_u16())
except OSError as e:
print('Failed to read sensor.')

I get this output:

Temperature: 27.3 C
Temperature: 81.1 F
Humidity: 49.4 %
50943

feels good to get a result, perfect start to a plant minder, warm evening in the Maritimes. Thanks for your patience and indulgence!

Post Reply