ESP32 doesn't read analog when Blynk begin but UNO do

Hi guys,
Please help. I’ve tried in many scenarios and find no way out so please advice.

I have ESP32 WEMOS Lolin with OLED and want to read the analog from thermistor value which connected to GPIO 13.

The output is always 4095 on the serial monitor and Blynk app virtual pin which is not correct value.
But when I comment out the “Blynk.begin(auth, ssid, pass);” and “Blynk.run();” , the output read just fine in the serial monitor.

I’ve tried to change from ESP32 board to UNO, the output is also read well in the serial monitor(and in the Blynk app by virtual pin).

So I am very in doubt why the analogRead doesn’t work with ESP32(when with Blynk) but works with UNO. Thanks.

//Here is the code for ESP32
#define BLYNK_PRINT Serial
#define inPin 13
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>

char auth[] = "xxx";
char ssid[] = "xxx";
char pass[] = "xxx";

BlynkTimer timer;

void setup()
{
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);
  timer.setInterval(1000L, TimerEvent);
}

void TimerEvent()
{
int sample = analogRead(inPin);
Serial.println(sample);  
}
void loop()
{
  Blynk.run();
  timer.run();
}
//Here is the code for UNO board
#define BLYNK_PRINT DebugSerial

#include <SoftwareSerial.h>
SoftwareSerial DebugSerial(2, 3); // RX, TX

#include <BlynkSimpleStream.h>
#define inPin A0

char auth[] = "xxxx";
BlynkTimer timer;

void setup()
{
  Serial.begin(9600);
  Blynk.begin(Serial, auth);
  timer.setInterval(1000L, TimerEvent);
}

void loop()
{
  Blynk.run();
  timer.run();
}

void TimerEvent()
{
int sample = analogRead(inPin);
Serial.println(sample);  
Blynk.virtualWrite(V5, sample);
}

This is not a Blynk specific issue. ESP32 and Arduino UNO are totally different devices and different pin designations for the Analog GPIO.

NOTE The ESP32 has many Analog input capable pins, but some of them will not work when also using WiFi.

I recommend doing some Googling on the issue - https://www.google.com/search?q=analog+read+esp32

Thank you man. You rang the bell. I used ADC0 pin the issue solved.

2 Likes

Nice one @Gunner :rofl: :rofl: :rofl:

Pete.

2 Likes