Neu: Die KI-Firewall überwacht die gesamte Plattform und erklärt jeden Vorfall in einfachen Worten. So funktioniert es

Reply To: ESP32 analogRead stuck at 4095 as soon as WiFi connects

It’s the pin. GPIO 4 is on ADC2, and on the ESP32 the WiFi driver uses ADC2, so analogRead() on any ADC2 pin fails while WiFi is on. Depending on the core version you get 0, 4095 or an error in the log. Same sensor on GPIO 34 works fine. ADC1 is GPIO 32-39, and 34-39 are input-only, which is all you need for a sensor.

So: move the wire to GPIO 34 (or 32/33/35/36/39), change the pin number, done. No code changes for WiFi.

Two smaller things while you’re in there. Take 16 readings and average them, the ESP32 ADC is noisy and a bit non-linear at the ends. And send both soil_raw and soil_pct, so you can recalibrate later from the raw history without reflashing.

const int SOIL = 34;     // ADC1_CH6
uint32_t sum = 0;
for (int i = 0; i < 16; i++) { sum += analogRead(SOIL); delay(2); }
int raw = sum / 16;
int pct = constrain(map(raw, 3300, 1500, 0, 100), 0, 100);
Timestamps in UTC or it didn't happen.
Akzeptierte Lösung♥ 1