Page 1 of 1

ADC input stuck on one level

Posted: Tue Apr 20, 2021 6:49 pm
by ParaPashka
Hi all!
I am using ESP32 WROOM-32 board.
When i read data from light sensor, the first value that i get is correct. After that i change the voltage on the pin. But the data that I get is still on the same level (changes just a little bit).
The input voltage is around 0.5v. I get:
...
533
534
575
...
I change the voltage to 1.8v. But i still get the same:
...
534
546
538
...

I reset and start the program starting with 1.8v input:
...
2009
1958
2007
...
I change the input to 0.5v, but still get the same:
...
2007
2008
2001
...

This is the code:

Code: Select all

from machine import ADC
from machine import Pin
light_sensor = ADC(Pin(33))
light_sensor.atten(ADC.ATTN_11DB)
while True:
    print(light_sensor.read())
I tryed it on 2 equal esp32 boards. I tryed using different pins. Tryed to reinit the ADC object before getting each value in the cycle. Nothing helps to get actual data.
What is the problem?

Re: ADC input stuck on one level

Posted: Tue Apr 20, 2021 7:13 pm
by Roberthh
That's strange. With the 11db setting, you could try to connect the ADC input to GND and 3.3V. Then you should read 0 and 4095 as adc.read() value. That's what I tried here.

Re: ADC input stuck on one level

Posted: Wed Apr 21, 2021 9:41 am
by ParaPashka
I got the solution.
After I added small pause between reading data, everything went correct.
New code:

Code: Select all

from machine import ADC
from machine import Pin
import time

light_sensor = ADC(Pin(34))
light_sensor.atten(ADC.ATTN_11DB)
while True:
    print(light_sensor.read())
    time.sleep_ms(10) #added this line