0

I am trying to read value from a capacitive moisture sensor (https://www.amazon.fr/Capacitive-Moisture-Corrosion-Resistant-Raspberry/dp/B07FLR13FS) from an ESP32.

I connected the sensor to pin GPIO 0 but the value returned is a constant 4095 even if the sensor is dry or wet. I tried to use 3.3v and 5v but the result is the same. Even if I disconnect the data pin the value is still 4095. I've read that 4095 is the max value returned on a sensor connected to 5v but not sure what I am doing here.

This is the code I am using:

const int moisturePin = 0;

void setup() { 
  Serial.begin(115200);
}

void loop() {
  float moistureValue = analogRead(moisturePin);
  Serial.println(moistureValue);
  delay(30000);
}

Thanks for any help.

  • The ESP32 is a 3.3 volt part. It's not 5 volt tolerant. You've quite possibly damaged the chip by connecting 5 volts to it. GPIO0 is also not usable as an input - it's used to determine how the CPU boots. See [this page]https://randomnerdtutorials.com/esp32-pinout-reference-gpios/) for a reference of what pins you can use - they'll vary by breakout board but the GPIO availability will be accurate for all of the original ESP32 processors. – romkey May 21 '22 at 17:40
  • I miss explained I think, I did not powered the chip with 5v, the capacitive sensor was plugged in the 5v pin of the chip. But thanks for the info about GPIO0, i didn't know that. I will check the link you posted. thanks ! – Julianit0w May 22 '22 at 12:10
  • Not 5V tolerant means that none of the pins on the chip can handle 5V. ADC pins cannot handle 5V. If a sensor's output can be 5V - which is probably the case for your capacitive sensor if it's powered off 5V - you must not directly connect that output to a pin on the ESP32. You can connect it through a voltage divider or level shifter. If you connect a 5V signal to any pin on an ESP32 you risk burning out that pin or the entire CPU. – romkey May 22 '22 at 16:27
  • Oh ok ! Good to know ! I hope I didn't burn the pin. For a voltage divider, how much is the max voltage for the esp in input ? – Julianit0w May 23 '22 at 08:50
  • It's a 3.3V part so... 3.3V is good to aim for. – romkey May 23 '22 at 15:06

1 Answers1

0

GPIO 0 is ADC2 connected, which is not to be used if WiFi is also used.

Connect the sensor to GPIO 34/35 and try again. And never attach 5V to the ESP… possibly that one didn’t survive.

Also set pinMode (function Arduino), so the pin is an input. In the ESP32 datasheet you can find the reference to each pin number and if it belongs to ADC1/2

RemyHx
  • 325
  • 3
  • 9
  • Yes I rode something about that, this is why I created a temporary sketch without using WiFi just to test the sensor before. But I also tried with GPIO36/39 without any success, is there any difference between these 2 ? EDIT: Like I answer to @romkey I did not power the ESP with 5v, I just pinned the sensor to the 5v pin of the esp. And thanks for the help btw :) – Julianit0w May 22 '22 at 12:12
  • Ah ok! So the sensor GND is connected to esp GND, power to 3.3V, AOUT to the pins you described? Pinmode set to input? In your example it appears to not being used. – RemyHx May 22 '22 at 16:02
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Sumit Sharma May 23 '22 at 07:00
  • You mean like the edit I just did Sumit Sharma? – RemyHx May 23 '22 at 08:44
  • The sensor GND is connected to the esp GND yes, power to 3.3, AOUT to GPIO36 and no I didn't set the pinmode to input, I thought it was unnecessary in my case, I have others sensors which are working without setting pinMode to INPUT. I'll try. – Julianit0w May 23 '22 at 08:54
  • It doesn't change anything with pinmode... – Julianit0w May 24 '22 at 15:00
  • Do you have an oscilloscope? Maybe first check the output. (Of the sensor) – RemyHx May 25 '22 at 15:43