Brightness sensor with Blynk

Hi, I’m Davide Minervini and I’ve just started programming, so I’m inexperienced.
While I was trying to program an esp 32 board and Blynk software via wireless communication I ran into a problem.
My goal is to get the reading value of the photoresistor (pin 2) every second both on the serial monitor and on my dashboard with a gauge with pin V3 of my Android phone.
The problem I encountered with the following sketch is that both the application gauge and the serial monitor respond to me with a value of 0. Testing the sensor with another basic sketch, they respond to me correctly.
I hope you can help me, I await your answers.
Thank you in advance for your cooperation.

BlynkTimer timer;

int foto = 2;
int val;

void setup() {
  Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
  pinMode(foto, INPUT);

void loop() {
   val = analogRead(foto);
   Blynk.virtualWrite(V3, val);
  Serial.print("sensor = ");
  Serial.println(val);        //stampa valore


Well, first of all you shouldn’t be doing this…

You should be using BlynkTimers, and just having; and; in your void loop.

Read this for more info…

The reason why your sensor readings aren’t working is because you are using pin 2, which is one of the pins connected to ADC2 in the ESP32. The pins connected to ADC2 can’t be used for analog inputs when WiFi is being used.
The solution is to use a pin that is connected to ADC1 instead.
More info, and a list of which analog inputs are connected to ADC1 and ADC2 can be found here…


Good evening @PeteKnight, thanks so much for your reply.
I just tried the changes you suggested and the program works perfectly.
Thank you very much for your availability.

1 Like