0

I have an ESP32, the current program running on it uses WiFi but, if I use WiFi and Analog read at the same time, Analog read does not work.

Why does this happen and what's the way around it?

Hardware - ESP32, Pin 25 for the ADC

Code-

#include <WiFi.h>

void setup() {
  Serial.begin(115200);
  WiFi.begin("You really", "Want to know"); // If this line is commented then it works
}

void loop() {
  Serial.println(analogRead(25));
}
8
  • What do you mean with “analogRead does not work”? What happens when you try to read an analog value from a pin? Please describe your hardware setup and show some code that demonstrates the problem.
    – StarCat
    Jun 26 at 5:54
  • When WiFi is being used the values from analogRead stay at 0 whether connected to 3.3 or 100 volts
    – Coder9390
    Jun 26 at 10:36
  • That is not normal behaviour so it's probably caused by your specific setup. Please provide some more information. What about your code and hardware setup? Are you using the correct pin(s). If you have connected an analog port to 100 volts you have probably killed your ESP32.
    – StarCat
    Jun 26 at 10:47
  • l'll update the question with the code, "100 Volts" was supposed to sarcastic as it shows only 0 connected to any voltage
    – Coder9390
    Jun 26 at 13:10
  • This code is a simplified version, but the problem exists here too
    – Coder9390
    Jun 26 at 13:22
6

The ESP32 has two ADCs. One of them, ADC2, is actively used by the WiFi.

From the IDF documentation:

Since the ADC2 module is also used by the Wi-Fi, only one of them could get the preemption when using together, which means the adc2_get_raw() may get blocked until Wi-Fi stops, and vice versa.

That means you can't use the ADC on any of the ADC2 channels while WiFi is on: GPIO4, GPIO0, GPIO2, GPIO15, GPIO13, GPIO12, GPIO14, GPIO27, GPIO25 and GPIO26.

But you can use ADC1, which uses pins GPIO36, GPIO37, GPIO38, GPIO39, GPIO32, GPIO33, GPIO34 and GPIO35.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.