0

I have a NodeMCU 1.0 ESP-12E development board. Trying to hook up a LM35 to measure temperature. For that I need to use the analog pin A0. However it seems my sensor is out by about 4C. I traced this to an offset error - when the board is connected via USB to the PC, and I connect analog pin A0 to analog ground with a jumper on the board, I read 13 from analogRead(A0). I should be getting 0. I confirmed with a voltmeter that A0 is at ground potential. I have nothing else connected to the board. When I feed in 3.3V to A0, I get 1024. When I hook up the LM35 which outputs 210mV, I get a reading of 81 which is 13 off (based on the standard analogValue / 1024 * 3300 calculation).

What am I doing wrong?

2
  • just subtract 13 from the adc read, problem solved.
    – dandavis
    Commented Dec 24, 2021 at 21:56
  • Won’t work as I said, it is 13 when wifi is off, 2-3 if wifi is on. That will not be reliable.
    – pwnell
    Commented Dec 25, 2021 at 23:55

1 Answer 1

1

The input A0 is not actually an ADC input. Instead it's the input to a voltage divider which then goes to the ADC input. The ESP8266's ADC is only capable of reading up to about 1.1V, so the makers of the NodeMCU helpfully created a small voltage divider (two resistors) to drop the input voltage to the range the ADC can cope with.

Except it's not perfect.

The resistors used aren't 100% precise, so the actual values you get from the ADC vary slightly from board to board. To get more precise readings you will have to first calibrate your ADC by providing known stable voltages to the ADC and logging the read values. Or you can measure the resistors used on your board and use those in the calculation to determine actually what value is being seen by the ADC.

Or you can use an external ADC that doesn't require the voltage divider circuit to function, which would be my preferred method, since the internal ADC is not great.

3
  • Thanks for the response. I am aware of the voltage divider, however their tolerances would not be enough to cause a reading of 13 when shorted to ground - surely? 13 is the equivalent of 41mV. Also, I just observed something else - when I start WiFi on the device, the shorted-to-ground reading drops to 3. This is very strange...
    – pwnell
    Commented Dec 21, 2021 at 19:32
  • The ADC is tightly coupled to the WiFi functionality. It's a really really crap arrangement. You really would be better using an external ADC.
    – Majenko
    Commented Dec 21, 2021 at 19:57
  • Just ordered an ADS1115 - will give that a go - thanks again.
    – pwnell
    Commented Dec 21, 2021 at 20:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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