Soil moisture value reading

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Soil moisture value reading

Post by Roberthh » Wed Mar 14, 2018 12:52 pm

Why don't you use the attentuator of the ESP32 and set it to 11db? That gives you a range of 0-3.5V. The lienarity is even worse than usual, but for your application that should not matter.

ajocius
Posts: 83
Joined: Mon Feb 19, 2018 6:31 am

Re: Soil moisture value reading

Post by ajocius » Wed Mar 14, 2018 6:45 pm

because:
  • Do not know how to change attentuator on ESP32
  • I would like to have several soil moistures connected, can this be done for more than one PIN?

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Soil moisture value reading

Post by Roberthh » Wed Mar 14, 2018 7:32 pm

Yes, the documentation is extremly sparse for the ESP32 build.

Code: Select all

from machine import Pin, ADC
adc=ADC(Pin(34))
adc.atten(adc.ATTN_11DB)
And yes, you can do that for more than one input. At the moment, ADC1 is supported, with its inputs at GPIO32 to GPIO39

ajocius
Posts: 83
Joined: Mon Feb 19, 2018 6:31 am

Re: Soil moisture value reading

Post by ajocius » Thu Mar 15, 2018 7:02 pm

Learning something new every day here. I do not quite understand this function. Should I use pin34 with attent function to connect to sensors VCC (meaning that Pin34 will provide reduced voltage to 1V) or is it supposed to be used to receive analog in from Sensor (since Pin34 is also A6)

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Soil moisture value reading

Post by Roberthh » Thu Mar 15, 2018 7:59 pm

Pin34 is just one of the ADC inputs. And setting the attenuation to 11db means, the ADC range changes from 0-1V into 0-3.3V. If your humidity sensor is operated with 3.3V, then you will not need the resistor voltage divider. Depening on the length of the wires, it is still recommended to add some protective circuitry, like at least a serial resistor of 10kOhm, and a small capacitor at the ADC input to GND, like 1 nF.

ajocius
Posts: 83
Joined: Mon Feb 19, 2018 6:31 am

Re: Soil moisture value reading

Post by ajocius » Fri Mar 16, 2018 8:20 am

resistor would be between sensor Analog output and ADC input on ESP32?

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Soil moisture value reading

Post by Roberthh » Fri Mar 16, 2018 8:52 am

Yes, close to the analog input of the esp32, to limit the inrush current in case of spikes etc. The current itself will then be absorbed by the built-in ESD protection diodes of the ESP32.

Post Reply