Reputation: 11
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.
Upvotes: 0
Views: 1124
Reputation: 365
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
Upvotes: 0