Monitoring Voltage on ESP

It is possible to monitor V and A on ESP.
As soon as I was connected to the battery, I would be able to make automation to alert you to a drop in volts.
Well thank you.

2 Likes

There is a ADC on A0 on the esp8266 and many on the esp32. Analog To Digital Sensor — ESPHome

1 Like

I gave up using the internal AD. It was too difficult to get a reliable measurement. Measuring an AC signal from a current transformer was very difficult requiring external Op-amps configured as ideal diodes. I am successful using a ADC1115 in differential mode to measure The output from a current transformer and mains voltage. I am using my ESPHome + wemos d1 mini.

but I would need to measure the output voltage of the 18650 battery mounted on this board. So I know when the battery is low and can recharge it.

I use a similar battery shield to you and by adding a 220K resistor between the battery (B+) positive terminal via the blue line to the A0 it divides the voltage so it doesn’t damage the Wemos and then I can multiply the voltage in my case by 5.18 to give the value I get if I hold a voltage meter between the terminal B -(battery ground by the white line) and B+. The red line is just a connection from the 3.3V connection on the shield (i.e. ignore that).

  - platform: adc
    pin: A0
    name: Outside Battery
    accuracy_decimals: 3
    update_interval: 60s
    filters:
      - multiply: 5.1817

I add the above lines to my esphome code. It’s been reading well for 6 months.

battery voltage

My battery charges from a 6v solar panel so voltage goes up during day.

Hi thanks for the reply.
This is still my wiring diagram.


My battery holder contains a 3.2V solid state output so I plugged the wemos directly.
According to your scheme, I should connect the red wire to A0 and will it work? Or I misunderstood. Because you have the white wire on your circuit directly from the positive pole of the battery on A0 and the red wire goes from 3V3 to the solar panel from nowhere?

Connect the 3v3 pin to A0.

The Wemos has resistors that mean when 3v3 is applied to A0 it will read 1v at the chip, which is the maximum.

Does this mean that the resulting sensor will be multiplied 3x?

  - platform: adc
    pin: A0
    name: Outside Battery
    accuracy_decimals: 3
    update_interval: 60s
    filters:
      - multiply: 3

can I connect directly to pin A0 3.2V or do I need to install a resistor?

I’ve made the pic simpler. The wires connected are just for monitoring the 18650 voltage. The max voltage of it is 4.2V when fully charged even though the battery is meant to be 3.7V. The outputs for the shield is 3V or possibly 3.3v and 5v, which is regulated. The A0 pin on the Wemos can only measure voltage up to 1V (higher voltage will damage it). The wemos also has a large resistor built in for A0 pin. so by adding in 220K resistor there is never >1V across the A0 pin and so it won’t be damaged. The Blue wire connects to the metal strip that in in direct contact with the back of the 18650. There is a large + on the board. I can see that on your board just behind the usb port. The blue wire then connects to the 200k resistor and the other side of the resistor connects to A0. The white wire connects to the - pad at the back of the metal strip in contact with the back or - terminal. The other end of this wire connects to the ground terminal on the wemos.
I have not shown how you by your red and black wires power the wemos. You will have to connect 2 wires then to the Ground terminal on the wemos to power it (my white and your black). I have this all on a circuit board so can connect many things to the ground rail. If you use breadboards then you will understand the idea of a + and - rail, otherwise this may be confusing.
My solar panel connects to the usb port on the battery shield. The shield has over charging and low voltage protection to stop the 18650 going boom. I assume yours does as well.
When the voltage measured by voltmeter across the 18650 is 4.2v the wemos gets 0.868v. I then using the filter multiply it by 5.1817 so the sensor on Home assistant
reads 4.2V. You may need a different multiplication factor.
tl
p.s. I power my wemos from one of the 5v outputs on the battery shield to the 5v terminal of the wemos. I’m not sure connecting through the 3 v will be enough to power it and anything else you like a sensor
p.p.s. Never fully trust the screen printing on any of these battery shields. Sometimes in the factory the + and - are reversed. If you put the 18650 in the wrong way around it could destroy it.

2 Likes

Is correct this wiring diagram?


Wemos i use it as a gas and water consumption data reader.
And since the water meter is far without access to electricity, I have to recharge the battery. That’s why I need a battery level sensor.

You have to tie the back of the battery shield to ground so all grounds are at same level. Grounds on different devices can be at slightly different levels which if not all grounded together will mess up your calculations. The Female usb port at front is how you charge the battery in the shield. The 5v terminals down the hidden side of the battery shield are 5v outputs. Don’t put a charge into these . The battery wont last very long if you don’t put it to sleep between readings. It not very good to run a sensor continuously by battery. My sensor is a temp/humidity sensor and I put wemos to sleep for 5 mins then wake it up for 10 seconds and it sends out a reading by MQTT then goes back to sleep. Without solar charging the battery will last a few months before voltage drops and discharge protection turns output voltage off.

  • I tried to connect GND batteries and GND outputs 5V / 3V with a digital multimeter but they are not connected. Will it be ok if they are all together?

  • This is the other side. There will be an inserted micro usb charger. (why shouldn’t a charger be connected?)

  • Wemos must run continuously. Water and gas consumption measurement cannot determine when the magnetic sensor ignites.

  • What is the real consumption of Wemos without other peripherals (magnetic sensor is actually just a switch)

  • Is it possible to replace 200kohm with 650kohm (I have one at home) multiples I will probably have to calculate from the measured first value?

Demos d1 I think with just wifi running is about 70mA and probably bit higher if use battery shield. 2400mAhr 18650 probably only last 36 hrs. That’s back of a napkin maths.
You can use bigger resistor but reading on A0 will be smaller so need bigger multiplication factor. Battery meter will also use up some power especially if running continuously.

If you want to use a gas meter where 220V is available then there is absolutely the best solution if you turn off the electricity.
Home Assistant as well as all other components of Modem Router Raspberry etc. runs on UPS 12V.
This means that >24 hours is a luxury.

Hi
Missed the bit about charging . You charge battery from the usb port but not the 3x 5v small holes. Those are only for output to your project. It may be dangerous to back charge through them.

This battery holder contains 3x 5V port and 3x 3.3V port, USB output (on off button) and USB micro input for charging (I use this to charge the battery holder)
Is this okay?

Forgot about micro port. I think that’s ok to charge from.

Have you been able to charge the battery in the shield? Some shields don’t work at all. When fully charged you should get a reading 3.7-4.2v putting your multimeter across the + - terminals. If shield doesn’t have working over charge protection it may go bang. :hushed:

Your wemos only has one ground pin and if using 5v and 3v devices you have to connect both to same ground. But you do still have the red wire connected to 3v to run the wemos. Does wemos run ok with the 3v connection to the battery shield 3v?

  • Charging
    Charges the battery in shield to 4.14V according to the multimeter.
    It’s hard to say what the quality of thesebattery holders is from China.

this is a dual battery but from the same brand

  • GND
    The 5V and 3V pins on the shield are connected.
    The GND of the 18650 battery is not connected to these pins.

  • Stability Wemos 3V3
    The connection from the 3.3V shield to the 3V3 pin is noproblem (The problem is more with the range of the wifi router :slight_smile:
    But as I mentioned above, I only use the magnet sensor connection.