Wrong signal from a voltage divider wit esp8266

Thread Starter

dades1988

Joined Aug 28, 2022
8
I have the following circuit.
partitore.drawio.png
I connected vout with A0 pin(adc pin) of my esp8266. When I read the tension by a0(with command analogRead(A0)), I expect that value is about 667(0.652 V). But instead I get a random signal(not const)... by analogRead(A0) i get:
adc_value = 448
adc_value =0
adc_value =0
adc_value =1023
adc_value = 224
adc_value =0
adc_value =1023
etc...

I don't understand why...
PS: As a power supply I use a bench power supply and I already try to change esp8266 with another(to try if it if broken...)
 

ericgibbs

Joined Jan 29, 2010
16,393
hi dades.
Try connecting the 3.3V of the ESP to A0 input, you should read 1023.
Then try with A0 at 0V, should get 0000
Post your Sketch

E

@dades1988
BTW: I assume you have connected the 0V of the power supply to the 0V of the ESP.????

partitore.drawio.png
 
Last edited:

Ian0

Joined Aug 7, 2020
6,312
To ask the obvious question . . .
is the negative terminal of your supply (in the diagram) connected to the Vss of the ESP8266?
 

Thread Starter

dades1988

Joined Aug 28, 2022
8
hi dades.
Try connecting the 3.3V of the ESP to A0 input, you should read 1023.
Then try with A0 at 0V, should get 0000
Post your Sketch

E

@dades1988
BTW: I assume you have connected the 0V of the power supply to the 0V of the ESP.????

View attachment 276729
No, I did not it. At the esp I only connected the a0 pin and the usb for the power supply. For you, do i need to connect it to ground of esp?
 

Ian0

Joined Aug 7, 2020
6,312
I guess that the positive reference for the ADC is connected to 5V.
So that the reading would be
Vin/5V * 1024
which would read 133.
 

Reloadron

Joined Jan 15, 2015
6,979
The ESP8266 is a 10 bit ADC and uses a 3.3 volt V reference. Also the ESP8266 is non linear when measuring voltage especially levels below 1.0 volt. You can oversample, take many samples and average but keep in mind you can't make a silk purse from a sows ear. Some chips respond better than others.

To convert to reading voltage the code would look like this or similar:
Code:
const int analogInPin = A0;  // ESP8266 Analog Pin ADC0 = A0

int sensorValue = 0;  // value read from the pot
float volts;

void setup() {
  // initialize serial communication at 115200
  Serial.begin(115200);
}

void loop() {
  // read the analog in value
  sensorValue = analogRead(analogInPin);
 
 volts = (sensorValue * 3.3 / 1024);
  // print the readings in the Serial Monitor
  Serial.print("sensor = ");
  Serial.println(sensorValue);

  Serial.print ("Volts =  ");
  Serial.println (volts);
 
 
  delay(1000);
}
The result would look like this with 0.652 volts applied.
ESP8266.png

Note the standard voltage applied is 0.652 volts. You can see the low end error. Using your divider your output would be close to the above input.

Ron


Ron
 
Last edited:
Top