ESP01-S voltage divider short circuit?

Hi all!

This should be simple, but I am hitting a snag and can't find an answer with google.

Objective
I am using ESP01-S to measure if an external power source is sending me 12V or 0V. I use a voltage divider to drop the voltage down. Here is the circuit (I use a nano in the diagram but in reality it is an ESP01-S)

NOTE: I use an ESP01-S, the real diagram is on a thread below. For this Frizting diagram I use an nano for illustration purposes. In reality on the ESP01-S I use GPIO2. I could not find the ESP01-S for Frizting

It works... kinda.... not

If I use a voltmeter at D8 instead of the arduino I get the right voltage and behavior.

If I start my arduino when the external voltage is not 12V but 0V, then the arduino does not boot up. If the power source provides 12V when I start my arduino I get the right behavior, but when I disconnect the external voltage to simulate it giving 0V, the builtin led on the arduino stays on and I get weird behaviors and he code does not execute all the statements (it skips sending me some MQTT message that it shouldn't) ... something is wrong here.

I have a strong feeling I am generating a short somewhere but I cannot see where. I've also tried with a transistor to isolate the external power source voltage (seems overkill) and it also does not work....

Where is the external power source? What sources the 3V3?

  • Are you connecting anything to the lower power + rail, maybe 3V3 ? :thinking:

  • If 12v, is there a common GND to the controller ?

  • Images of actual wiring is helpful.

the top rail is fed by a standard 3v3 regulated power supply

the bottom rail gets 0V or 12V from the external power source. This is what I want to measure (true/false) with my digital pin

See reply above

all the GND are connected together. I have a feeling this is wrong, but I can't get it to work if they are not connected.

I can build the wiring and post a picture tomorrow ... getting kinda late to whip up my breadboard, but the wiring is really that simple. The only thing that differs is that I use 5k+2k
in serie instead of a 7k since I don't have that resistance on hand...

Hi Larry,

To add to your graphic, there is no purple wire as the top rail is fed by 3.3v and bottom rail has the external power ranging from 12V to 0V

For context,
This is a signal from my electrical power company. 12V mean I am on a high $kw/h and low means I am paying less for electricity. I want to monitor that state and do other things with the signal, i.e. trigger a relay, send me an e-mail etc. etc...

Check the actual voltage with a multimeter.

The fact that it sort of works with the grounds connected should be a clue that maybe that is the correct way of doing it. When you specify a voltage you reference something, the default reference is ground. Electronics is the same way and also needs a reference. The output of your voltage divider is about 2.6V, on the sketchy side for a 3V3 processor and low for a 5V processor. You will not be able to measure that with a digital pin, the best you will get is on or off. To measue you need to use an analog input.

1 Like

An ESP only has 1 ADC pin and on an ESP-01 it is not exposed.

If you use D8 on an ESP-01 you are connecting to a pin (GPIO 15) which is not exposed.

On an ESP8266 some of the pins need to have a certain state at boot.

GPIO 0, 1 & 2 should not be pulled LOW. GPIO 15 should not be pulled HIGH (the latter is what you may have run into)
I anyway don't think it is the proper way of connecting to a 12v source on a 3.3v MCU. I suggest you use an Opto-coupler to separate and make sure that the inoput never exceeds 3.3v

Indeed. but this is that I want, I do not care about the voltage, just if I receive it or not.

the power company sends nothing, or sends 12V. That is why I am supposing that a digital pin will sullfice

Try voltage divider R1 = 12k, R2 = 3.9k, 12V in = 2.94V out.

Hi all!

(Thanks for the reply JCA34F, I will try now)

Here is the circuit without the arduino, showing the divider dropping the 12V external source to a measurable 3.54V.

Here is the board with the arduino, this works, but I need to connect the external power source to get the ESP to boot correctly!.

Clearly, there is an issue

This is the same circuit without the external power source. The divider is getting power from the digital pin and dropping it to 1.28V and the builtin blue led staying on. Why am I getting this?

It it better, as I now move from 0.48V to 3.15V, but still I can't boot up the ESP if that 2nd external power source is disconnected...

You say you connect the thing to D8 but again that's impossible on the ESP-01. D8 is a NodeMCU/WeMOS designation of the pins, in an attempt to be more Arduino Uno like. You're confusing yourself and the forum readers by using those indications, which are not even marked on the ESP-01 as such.

On an ESP-01 you have four pins available: Tx (GPIO 1), Rx (GPIO 3), GPIO 0 and GPIO 2.

Tx has a blue LED connected to it; that will light up when you use it as input and bring the pin high.

Rx has nothing special if you do not use the Serial interface.

GPIO 0 is used in the boot sequence, and must be pulled HIGH for the ESP to boot.

GPIO 2 is used in the boot sequence, and is pulled high internally to boot; pulling it LOW externally (e.g. with your voltage divider) will stop it from booting.

So using either GPIO 0 or GPIO 2 for your voltage detector will stop your device from booting.

Please show a schematic of how you have wired things. No Fritzing wiring diagrams. No "I've used a Nano in the image but it's an ESP" laziness, that's useless and only adds confusion as you've seen already. Just use pen and paper if you don't have real schematic software such as KiCAD (which is free!) at hand.

1 Like

I think the OP should read the Arduino Cookbook first as it is obvious the OP is in way over his head and does not know what is happening.

1 Like

Does the Arduino Cookbook cover the ESP8266?
These issues are very specific to this MCU, and have nothing to do with the Arduino line of products.

Thanks for your reply.

I admit I used a Nano and I though I would not have to resort to using the ESP01-S diagram. I could not find the frizting ESP01-S part so I resorted to the Nano.

I now wish I have taken the pen an paper route altogether. I really did not want to confuse any kind soul that would want to help out :innocent:

I will draw the diagram pen & paper style. I also think me using GPIO2 with my voltage divider is the issue.

To note, I just tried the same but with a NodeMCU Lolin v3 wired in and I get the same issue with GPIO2.

Here is the diagram :grin:

I've tried connecting it to GPIO3 (RX)
It boots but does not detect any voltage change ... always the same state

I've tried connecting it to GPIO1 (TX)
It does not boot when connected, doest not detect any voltage change ... always the same state

As long as you don't use Serial in your code (which you didn't post) you can use GPIO1 and 3 as regular I/O pins.

How do you communicate with the device, to know whether you detect voltage or not?

What voltages does your multimeter show at the ESP-01 pin?

When using a NodeMCU you can use D1, D2, D5, D6 or D7 without any special issues.

Apparently boot will also fail if Tx (GPIO1) is pulled low during boot, I didn't know that one yet. More info here.