Incorrect readings of analog input

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
spm
Normal user
Posts: 11
Joined: 08 Aug 2019, 15:54

Incorrect readings of analog input

#1 Post by spm » 13 Nov 2019, 17:22

Hi,

I'm trying to make some project based on ESP runnig from batteries and I wanted to measure battery voltage to know when it will die. So currently prototype was still powered from USB (ESP12-F board with some USB power connector and voltage regulator) and I connected li-ion battery with resistor divider to ADC pin. First time I did it with bad values and I push cca 2 volts to ADC pin. A fixed that, use values 15k / 82k which I currently had. But trouble is that I'm still reading nonsenses. Well, battery have currently 4,1V. When I connect it to my divider I can measure 0,63V with voltmeter which is correct for these values. But when I connect ADC pin to it, on my voltmeter voltage drops to 0,3V (and I read values which also means about 0,3V...)

Well, I thinked that I smashed my ESP when I first had bad values... so I unpack new one, connected it and... I got exactly same behvaiour, same values. Currently I disconnect everything not needed, now I have only ESP board with ADC pin connected through 15k resistor to GND. And still in this case (where I should read 0) I read values around 300... Next idea was power source - USB hub wasn't the best thing, I had 4,3V on input. So I used phone charger, better cable. Now on input pin to board is 4,99V but result is even worse - values around 700 on analog input :-/

What can be wrong? Is there any other explanation that even the new board is damaged (although it was never used)? Boards currently have latest release of mega, but older release which was there today morning was also doing same thing...

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Incorrect readings of analog input

#2 Post by TD-er » 13 Nov 2019, 19:57

How do you measure the voltage?
Using the ADC plugin, or sysinfo plugin with ADC selected?
What build do you run? One with _VCC in the name?
You should use one without _VCC in the name, since you don't want to read the voltage supplied to the ESP, but one you have on your own resistor network.

Do the ESP and your battery source share the same ground?
If not, then there may be some extra current flowing through one of the resistors, or you are actually measuring only a fraction of the supplied voltage.
Try to measure the voltage between the - of the battery and the GND of the ESP.
It should be 0 Volt.

User avatar
ThomasB
Normal user
Posts: 1064
Joined: 17 Jun 2018, 20:41
Location: USA

Re: Incorrect readings of analog input

#3 Post by ThomasB » 13 Nov 2019, 21:41

If TD-er's comments don't help, then more info is needed.
ESP12-F board with some USB power connector and voltage regulator
What EXACT board are you using? Is it a bare ESP-12F module (tin module only) or is it a development board (ie, nodeMCU or other type) that has a "ESP-12F" module on it?

I suggest posting a clear image or web link to the ESP board; Proposed answers to your problem may depend on what you have.

- Thomas

User avatar
Sasch600xt
Normal user
Posts: 164
Joined: 10 Sep 2018, 16:37

Re: Incorrect readings of analog input

#4 Post by Sasch600xt » 14 Nov 2019, 00:26

Dont forget,

the analog in has an resistor already connected at least if it is a Node MCU LolIn V3.
About the other 8266 i have no idea.

I did the same last summer and reconized there is an resistor already.
So this has come into your math with your voltage divider.

Have a great day
Sascha
"the flat earth society has members all around the globe"

spm
Normal user
Posts: 11
Joined: 08 Aug 2019, 15:54

Re: Incorrect readings of analog input

#5 Post by spm » 14 Nov 2019, 09:15

I'm measuring using analog input in devies. Build without VCC. To be sure I added generic - sysinfo and looked on VCC - it was -1 which is correct. Yes, - of battery was connected to ground of ESP module. In my last test I even pull battery out and just measured ADC pin connected via 15k resistor to ground and I'm still geting some big values (should be 0). In this case I can measure some voltage directly on ADC pin against ground.

It's some small development board, this one: https://www.aliexpress.com/item/3259787 ... b201603_55 . Boards was bought from another source (one I've bought directly on aliexpress, second is from some local supplier), so it shouldn't be one defective series. But that one from local supplier was maybe damaged by first connection with bad resistor divider and putting 2V to ADC pin.

In case of this board it don't look that there is already resistor on ADC pin. If I measure resistance between ADC pin on module itself and place on my board, I get almost 0 Ohms (+- resistance of meter cables). And still I think that even if it will be there some resistors already, I still should get 0 when I connect ADC pin to ground...

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Incorrect readings of analog input

#6 Post by TD-er » 14 Nov 2019, 11:46

It does seem to have an LDR on the board. So that is probably connected to the ADC pin and probably GND. (or 3v3?)
Not sure what the min and max. value of the LDR is, but I guess there will be another resistor somewhere either pulling it to GND or 3v3.
I guess it would make sense to have the resistor between ADC and GND and the LDR between ADC and 3v3, since you then pull it to 0 when not having the LDR connected.
That other resistor should be smaller than the minimum value of the LDR (when LDR does "pull up").
So if the minimum value of that LDR is like 5k, then the resistor is probably something like 2k2. (makes 1V)

If that resistor is still present, it will offset your own calculations quite a bit and also drain probably more power than you would like.

User avatar
ThomasB
Normal user
Posts: 1064
Joined: 17 Jun 2018, 20:41
Location: USA

Re: Incorrect readings of analog input

#7 Post by ThomasB » 14 Nov 2019, 21:53

You have a "Witty Cloud" type development board. The LDR is connected to the ADC input.

This is a typical schematic (your board may be different):
https://www.instructables.com/id/Witty- ... ter-Board/

Some general info:
https://www.schatenseite.de/en/2016/04/ ... ud-module/

- Thomas

User avatar
dynamicdave
Normal user
Posts: 257
Joined: 30 Jan 2017, 20:25
Location: Hampshire, UK

Re: Incorrect readings of analog input

#8 Post by dynamicdave » 14 Nov 2019, 22:40

Well what a coincidence... I've just been writing a tutorial for my IoT students on the Witty module.

Yes it does have an on-board LDR connected to A0 (analog input) as per the schematic linked to above.

The integer readings I'm getting range from 17 (total blackness) to 1024 (full light from the flashlight on my mobile phone).
The ADC is probably a 10-bit device to give this range.

I would take extreme care connecting an external voltage to A0 as the Witty could easily be damaged if A0 goes above 1V.


Note:
The new versions of the Wemos D1 Mini (which is a different animal although being ESP8266-based) have a series resistor which allows A0 to go to 3.3V

PS: Here's a link to the tutorial-guide http://resources-area.co.uk/node-red-fl ... y_node.pdf
Last edited by dynamicdave on 15 Nov 2019, 00:24, edited 1 time in total.

User avatar
dynamicdave
Normal user
Posts: 257
Joined: 30 Jan 2017, 20:25
Location: Hampshire, UK

Re: Incorrect readings of analog input

#9 Post by dynamicdave » 14 Nov 2019, 23:55

Just checked my notes about the Wemos D1 Mini (a ESP8266-based microcontroller).

The (new versions of the) Wemos D1 Mini have a couple of resistors (on-board the PCB board or maybe inside the chip) that act as a voltage divider.
There's a 220K resistor in series with a 100K that connects to ground.
The mid-point goes to A0 (the analogue input of the Wemos).
If you work out Ohms-Law on this it gives a division ratio of 100/320.

So if +3.3V was applied to the free-end of the upper resistor (the 220K), the mid-point would sit at +1V

This means that with this voltage divider the Wemos can handle an input up to +3.3V

I'm sure a similar circuit could be implemented on the Witty providing the LDR and related resistors were disconnected/removed or isolated.

Hope this helps.

Regards, David.

spm
Normal user
Posts: 11
Joined: 08 Aug 2019, 15:54

Re: Incorrect readings of analog input

#10 Post by spm » 15 Nov 2019, 10:17

Aaaah. LDR. What a mystery :-) Several days of playing and... this was it. Yes, I tried to put light on that chip and it's reacting. So this is the reason why it's not working :-) And at least it seems that I didn't smashed first board. Thank you very much, now I can sleep well :-)

Post Reply

Who is online

Users browsing this forum: No registered users and 26 guests