Measuring 12v on ESP32 or ESP8266

Thanks for your immediate reply and the YAML. I have ordered these voltage dividers and waiting for its delivery. I am connecting it to esp32 as voltage input sensor to do further automation. I will reach here if I am finding anything different or stuck somewhere.

I have received my voltage stepdown unit (same product that you are using) and tested it, It is working fine. I want to keep the input voltage within safe value that GPIO pin can support, using 5V as input and getting 1V output from that unit.

I have connected above mentioned step down to esp32 devkit GPIO as voltage sensor. However when the step down unit is disconnected from esp32, only esp32 is powered on, random voltages are shown in the web page of esp32. This is triggering false positive and the conditions mentioned is getting executed. Adding any physical resistor is required to prevent this? Or do we need to call out Pullup or Pulldown on the supported pins in the YAML? I would like to keep the voltage as zero when the step down is not receiving any power from input or disconnected with esp32.

  - platform: adc
    pin: GPIO33
    name: "Sensor Voltage"
    id: sensor_voltate
    attenuation: auto
    accuracy_decimals: 2
    update_interval: 5s
    filters:
       - multiply: 1.01
    on_value_range:
      - above: 0.51
        below: 3.0
        then:
          - if:
              condition:
                switch.is_off: motor_power
              then:                     
                - switch.turn_on: relay1

I am not using any physical resistors as you asked. When the generator is not running, I am getting 0.0000v from that sensor. It’s hard to say why you would be getting some random voltages. Without seeing how you have everything tied in, it’s hard to diagnose.

Thanks for your immediate reply on this. On further investigation, when I just connect the cable from stepdown (Pin S) to GPIO33 and Ground (Pin -ve) on ESP32. I have connected directly without any resistor or capacitors any where.

Step down → PIN S ----> GPIO33 → ESP32
Step down → PIN -ve → GND ------> ESP32

I am getting the voltage as 0.00 or 0.2v even though the stepdown is not connected to any power. However if we remove these cables, the GPIO33 is getting random voltage shown on esp32 web, but on the actual GPIO33 there is no voltage detected using multi meter. I tried even setting to attenuation: 11db. Just thought of sharing here.

Hello everyone,
I am interested in constructing a system that can detect when my UPS is about to power off and subsequently shut down my NAS. My initial idea involves using the ESP32 along with a voltage divider connected to the 12-volt batteries of my UPS. The first step would be to monitor the UPS voltage in order to determine the threshold at which it powers off. This threshold could then be used as a trigger to shut down my Synology NAS.

I would greatly appreciate any suggestions or insights based on your experiences.

@ the-buzz-man
How you can be advised if the ESP32 goes offline? in fact what is worring me is that in case of blackout the internet could be down with the risk that the ESP32 could not communicate with home assistant.

Thanks.

Did you try using the search box in here? A google search box? If you would have tried a search, you’d have seen stuff like this.

Or this stuff also…

Also, you should really do some reading and get a basic understanding of how esphome and HA work. One of the main reasons so many people like it is its ability to run localy or no internet needed. You dont need internet for an esp32 to communicate with HA you just need power and wifi. If you dont spend time learning and understanding the basics and instead jump straight to buying and building stuff, unfortunately your going to waste a lot of time and money.

Also, its very helpful if when asking a question that you include details about your hardware, any config/yaml that applies, log outputs that apply, and specifying which esp32 your using because, there are about 200 varietions of “esp32” and it matters sometimes.

Help us help you by providing details in your questions.

Thanks Fallingaway24 for your kindly reply,
yes I know about NUT and I know about UPSs that can be connected to NAS via USB or via SNMP but I have a very low cost UPS with no communication ports.
I was also suspecting that ESP32 was working without internet but you have kindly confirmed it. So it seems I’m on the right direction.

Regarding the type of ESP32 is the one I have used for this application

Thanks again

Gotcha! Ya, when i read your question I started having my own questions about it. Is this UPS able to fit in a shoe box or does it use an entire room?? Is this a DIY project on a budget or a high end unlimited budget? These are things people will base their answers on, so the more details you provide, the better the answers are you get.

Is everything all in one room? Is it close enough to wire things or is wireless needed ? What kind of batteries does it use? Pb? Li Ion? LifePO 4? What kind of hardware is monitoring the battery?

Instead of monitoring the battery and trying to determine when or at what voltage/load will it power down your NAS. Why not take over the whole process? You’re going to be monitoring the batteries so why not do your own low voltage shut off instead of only guessing when it will happen?

Ok, let’s go step by step.

  1. My UPS is a simple low-cost UPS but it cannot be moved because it powers a backup electrical circuit for various equipment (computers, router, wifi, etc.) located in different areas of the house, including the NAS that I want to protect from uncontrolled shutdowns.

  2. It’s a DIY project without a budget, meaning there are no budget constraints. I could easily solve the problem by purchasing another UPS with an SNMP port dedicated to the Synology NAS, and the problem would be solved. Since I like to ‘play’ with home assistants and find alternative solutions, I thought of doing this project. Essentially, creating an alternative NUT solution that reads the minimum voltage value of the UPS before it shuts off and uses it for controlled shutdown of the NAS through the Synology integration of Home Assistant. I already have the ESP32 and I am waiting for the voltage divider to arrive. However, if there are better suggestions, they are welcome.

  3. I didn’t understand this part, can you explain it better?

Instead of monitoring the battery and trying to determine when or at what voltage/load will it power down your NAS. Why not take over the whole process? You’re going to be monitoring the batteries so why not do your own low voltage shut off instead of only guessing when it will happen?

Thanks

Hello,

I finally built the circuit I had in mind. With three resistors, I managed to create a double voltage divider to reduce the UPS battery voltage. One to power the ESP32 through VIN, and another to reduce the maximum voltage of 26 volts to 3.3 for the ESP32’s pin 32.

On paper, everything is perfect. In fact, the UPS voltage of 26 volts is reduced to 3.3 for pin 32 and to 6.6 for the VIN pin. However, the ESP32 does not “turn on” with the VIN voltage of 6.6 volts.

At this point, I tried to power the ESP32 with the USB cable, leaving only the pin (gray cable) and the GND (white cable) connected. The ESP32 turned on, but when I tried to connect the GND, the house circuit breaker tripped.

I can’t understand why.


You can’t power esp with voltage divider. Voltage divider voltage depends on current draw.

This might help:
Here’s your divider with just voltmeters connected. Outputs 6.6V and 3.3V

Esp32 draws around 100-250mA, so let’s add 0.5W load to this circuit:


How are the voltages??
Obviously those readings will never happen because Esp32 will never turn on…

1 Like

Why don’t you use a step down to power the esp32?

1 Like

Understood!
image
I measured the resistance between GND and VIN pins, with the Esp32 off, of circa 2000 ohm.
With these schema it should work, correct?


Or should I consider also the resistance between Pins 32 and GND?

you mean something like this?

https://it.aliexpress.com/item/1005004904872120.html?spm=a2g0o.productlist.main.1.3cb06f83K5Mlvg&algo_pvid=86632f94-566c-443c-b0c5-1db51a03cedd&algo_exp_id=86632f94-566c-443c-b0c5-1db51a03cedd-0&pdp_npi=4%40dis!EUR!3.69!3.69!!!4.02!4.02!%402103894417271007217707840e9598!12000030968453858!sea!IT!2692602029!X&curPageLogUid=XQeVPUj1Qra6&utparam-url=scene%3Asearch|query_from%3A

There in no way to use voltage divider to power something that draws variable current.
Esp can draw anything between 0 and 250mA and the voltage has to remain between 2.5V and 3.6V. Make your math… Otherwise who would buy expensive linear voltage regulators and buck converters… :wink:

1 Like

Yes, I use several like this.

Yes and no.
Yes - your blind spot was due to the loads w/ ESP32, which being an SOC, there are maybe millions, if not more, of transistors keeps on and off, doing all kinds of stuff… essentially a bunch of mini switches for your programming…

And no, you should not consider doing voltage divider at all. Use buck converters please.

1 Like

Ok, understood! Something like this.
I’m ordering the buck converter.

I have a quick question. From the picture below, it seems that the connections for Input, GND, and Output should be made to both pins of each pair. I assume it means one of the two pins and not both, correct?
image

Thanks to all for the suggestions

correct, one is enough.

1 Like