Page 1 of 1
Capacitive Moisture sensor DOIT ESP32 - Cant seem to work
Posted: Sat Jan 30, 2021 8:52 pm
by cee-lizzle
Hey everyone.
I've been trying to get these moisture sensors to work for 4 hours but i just cant seem to! I've tried everything i can think of 3.3v, 5v, different sensors(but the same) differnet cables, different pins, pull up, pull down etc etc, ive tried attenuation but not much.
it either starts from 4095 and slowley goes down to 0 with no effect when i dip it in and out of water.
or its just pinned at 4095 (with 5v).
here's my test code
Code: Select all
#include <Arduino.h>
#define pin 26
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
//pinMode(pin, PULLDOWN);
}
void loop() {
int val;
val = analogRead(pin);
Serial.println(val);
//delay(500);
}
the pin set up is as follows
gnd - gnd
vcc - 3.3v
aout - d26
image attached
heres my sensors -
https://www.amazon.co.uk/gp/product/B08 ... UTF8&psc=1
and the board im using -
https://docs.zerynth.com/latest/referen ... sp32/docs/
any help would be much appreicated, im at my whits end!
thanks so much in advance
Re: Capacitive Moisture sensor DOIT ESP32 - Cant seem to work
Posted: Mon Feb 01, 2021 3:19 am
by ESP_Sprite
According to the reviews on that page, the issue is that those sensors only work with a 5V power supply. The issue there is that the output voltage in that case will also have a max of 5V, which is way above what the ESP32 can have on an input pin. You can use resistive divider to put it back into range, for instance an 100K/100K should work. (In that case, also suggest you add a capacitor of 10n or so on the ADC pin to ground to get rid of stray noise.)
Re: Capacitive Moisture sensor DOIT ESP32 - Cant seem to work
Posted: Mon Feb 01, 2021 2:01 pm
by cee-lizzle
ESP_Sprite wrote: ↑Mon Feb 01, 2021 3:19 am
According to the reviews on that page, the issue is that those sensors only work with a 5V power supply. The issue there is that the output voltage in that case will also have a max of 5V, which is way above what the ESP32 can have on an input pin. You can use resistive divider to put it back into range, for instance an 100K/100K should work. (In that case, also suggest you add a capacitor of 10n or so on the ADC pin to ground to get rid of stray noise.)
Thanks so much for your help! tha makes a lot of sense, I feel like a bit of an idiot. i was trying to use adc1_attenuate, will give it a go and post back.
one thing i did note, it worked seemingly okish with gpio 2 it would go from 1500 - 1600 in and out of water, i dont suppose you or anyone else could shed some light as to why this is?
Thanks
Re: Capacitive Moisture sensor DOIT ESP32 - Cant seem to work
Posted: Tue Feb 02, 2021 1:27 am
by ESP_Sprite
Hard to say... GPIO2 is a bootstrap pin that might have an internal pulldown that attenuated the signal enough to get into range perhaps.
Re: Capacitive Moisture sensor DOIT ESP32 - Cant seem to work
Posted: Thu Feb 04, 2021 3:42 pm
by cee-lizzle
Hmm i thought it might have had something to do with being the only adc & arduino pin.
anyway, one other thing id massivley appreciate you elaborating on...
i understand the maths with the voltage divider but id love you to elaborate how you came to the capacitor value you did for cleaning any noise?
thanks again!
Re: Capacitive Moisture sensor DOIT ESP32 - Cant seem to work
Posted: Fri Feb 05, 2021 7:53 am
by ESP_Sprite
To be honest? Let's call it 'experience-based heuristics', cause that sounds better than 'I just pulled a number out of my ass because it felt about right'.
If you want: I can justify it: The voltage divider and capacitor more-or-less form a R-C filter. With a R-C filter on something like this, you want to filter out fast signals (because they're most likely noise) but want to keep slow signals (because that's most likely the 'true' reading of your moisture sensor. In this case, we have 100K/10n for the rc values, which gives us a rc time of (R*C, aka 100K*10n = 100*10^2 * 10*10^-9 = ) one millisecond. I'm going to gloss over a ton of signal processing and frequency things here and just posit that a rough approximation of the meaning of that time is that signals that are faster than that will get blocked, while signals slower than that will get passed.
As noise usually is very spikey and very fast (uS), it gets filtered out, while your humidity signals (seconds to minutes) can pass unhindered. (Actually, having done the calculations, perhaps a C a bit higher, like 100n would be a bit more appropriate, but it likely doesn't make that much difference.)
Re: Capacitive Moisture sensor DOIT ESP32 - Cant seem to work
Posted: Fri Feb 26, 2021 10:18 pm
by cee-lizzle
haha
Thanks so much for your reply, everything you've said has really helped. sorry it took a while to get back, stupid work got in the way
have a great weekend!