Capacitive Moisture sensor DOIT ESP32 - Cant seem to work

cee-lizzle
Posts: 4
Joined: Sat Jan 30, 2021 7:18 pm

Capacitive Moisture sensor DOIT ESP32 - Cant seem to work

Postby cee-lizzle » Sat Jan 30, 2021 8:52 pm

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
Attachments
b197b6ac-ca5e-4421-999f-a7deb5df4c4b.jpg
b197b6ac-ca5e-4421-999f-a7deb5df4c4b.jpg (131.21 KiB) Viewed 4470 times

ESP_Sprite
Posts: 9746
Joined: Thu Nov 26, 2015 4:08 am

Re: Capacitive Moisture sensor DOIT ESP32 - Cant seem to work

Postby ESP_Sprite » 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.)

cee-lizzle
Posts: 4
Joined: Sat Jan 30, 2021 7:18 pm

Re: Capacitive Moisture sensor DOIT ESP32 - Cant seem to work

Postby cee-lizzle » Mon Feb 01, 2021 2:01 pm

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

ESP_Sprite
Posts: 9746
Joined: Thu Nov 26, 2015 4:08 am

Re: Capacitive Moisture sensor DOIT ESP32 - Cant seem to work

Postby ESP_Sprite » Tue Feb 02, 2021 1:27 am

Hard to say... GPIO2 is a bootstrap pin that might have an internal pulldown that attenuated the signal enough to get into range perhaps.

cee-lizzle
Posts: 4
Joined: Sat Jan 30, 2021 7:18 pm

Re: Capacitive Moisture sensor DOIT ESP32 - Cant seem to work

Postby cee-lizzle » Thu Feb 04, 2021 3:42 pm

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!

ESP_Sprite
Posts: 9746
Joined: Thu Nov 26, 2015 4:08 am

Re: Capacitive Moisture sensor DOIT ESP32 - Cant seem to work

Postby ESP_Sprite » Fri Feb 05, 2021 7:53 am

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.)

cee-lizzle
Posts: 4
Joined: Sat Jan 30, 2021 7:18 pm

Re: Capacitive Moisture sensor DOIT ESP32 - Cant seem to work

Postby cee-lizzle » Fri Feb 26, 2021 10:18 pm

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!

Who is online

Users browsing this forum: No registered users and 97 guests