Power from NodeMCU, Wemos Mini D1 and Arduino

Last modified August 19, 2021

On many occasions, in our projects, we power our microcontroller through a USB cable connected to a mobile or computer charger and we need power peripherals (sensors, displays, LEDs, etc.) that work at 5 volts. Can we do it without problems through the NodeMCU?

Recently, the user Jesús, made a comment on the blog, specifically in the article about the Home CO2 Meter with wifi, really interesting.

I began to answer the comment and as I wrote, the answer was getting longer and longer and I realized that I needed more resources to answer it (images, video, a richer format, etc). I decided it was a very interesting topic that could go a long way, to be able to cover it minimally (every time I tried to explain a point I realized that I had to explain others in order for it to make sense) and that's where the article you are reading comes from.

Basically the topic was, if we can use the external power input of a NodeMCU to power peripherals operating at 5 volts.

All I explain in the article is also valid for Arduino but with some caveats that I will comment later (because there is not just one Arduino, but many, and you have to see each one, because they are different). It also applies to plates such as Wemos D1 Mini, ESP32 DevKit and others like it.

In this article I talk about the example of the supply of an NDIR CO2 sensor but it is just as valid for any other type of sensor or actuator that you want to supply.

The doubt or query

Specifically, the user said the following in his comment:

“I have been documenting myself and it turns out that the ESP is unable to give 5V. The Vin / GND is to supply it with “unregulated” voltage between 5V and 12V. But not to get 5V out of there. In fact, the power supply when connecting with micro USB is a by-product, not a specification. In fact, in any project that needs 5V (motors), you need a specific power supply, you can't pull Vin (from what I've been reading). With the MH-Z19B we are lucky because its input range is wider (although it is so close to the limit that it is almost certain that some of them are not working and they get jumping values), but not with the MH-Z19C. "

It certainly is a very valid observation, and very useful if we need to power certain sensors or peripherals at 5 volts, especially if you need a power supply that is very close to the exact 5V (as is the case with the MH-Z19C CO2 sensor that it needs to function, according to the specifications manufacturer, a voltage between 4.9 and 5.1 volts).

My sincere congratulations to Jesús, because he has found a very important point and, furthermore, as he himself indicates, he has no idea about electronics (and, precisely, to those who have no idea about electronics this article is intended; to help them get out of doubt or find something information founded).

As you know, the problem with affirmations that are read online is that, as with everything in life, there are affirmations of all types and colors and, many times, they are based solely on things that pass by word of mouth without any fairly rigorous technical explanation. Furthermore, people have a tendency to generalize and where one thing is true, in a certain case, there is another similar case in which it is not.

Searching the internet I have found multitude of sites in which the NodeMCU is said to be incapable of providing 5V, stating that the fact that the Vin pin gives voltage when connecting the board via USB is a by-product and not a specification, and other such things.

Little less than some warn you of danger of death if you connect something to the Vin pin while powering the NodeMCU via USB.

The truth is that, not being completely false that the NodeMCU is unable to give 5V, in most cases this will not affect us when connecting peripherals such as sensors and displays.

Luckily, the NodeMCU (and the Wemos D1 Mini, different Arduinos and boards with ESP32) and its components are very well documented, So it is easy to analyze what is reality and in which cases this is true and in which cases it is not.

The bottom line

The question that arises, in the end, is simple.

The NodeMCU is usually feed in two ways:

  • Through a USB port (like a mobile charger, a computer, or similar)
  • By means of a voltage applied to their Vin and GND pins

In most cases we power the NodeMCU or the Arduino with a USB power supply / charger of which we usually use for mobile phones.

Can we, in this case, use the pin that is normally used to power the NodeMCU, or the Arduino, to power other elements that operate at 5 volts without having to look for an independent diet?

Powering the NodeMCU V3

To start analyzing the situation and if there really is a problem or not, let's see how the power of the NodeMCU works.

I am going to refer in this explanation to the NodeMCU V3, which is the most widely used today, and later I will refer to older versions.

This is an extract of the NodeMCU schematic with the circuitry corresponding to the power supply:

The explanation of this scheme is very simple, and I think that any fan can understand it if it is explained with plain and colloquial words (although along the way we miss some hue):

  • ESP8266, which is the microcontroller that is mounted on the NodeMCU board, actually is powered at 3.3 volts.
  • The USB port connects to a voltage regulator (in practice it is usually an AMS1117) that, regardless of the voltage that enters it (within the limits of the regulator) will draw 3.3 volts to power the ESP8266.
  • Pins Vin (positive) and GND (negative) are also connected to the same voltage regulator, except that they do so with an interleaved diode (which only lets current pass one way) so that when you put the voltage through the Vin and GND pins do not exit the USB into the charger or computer and spoil it.

What is explained above has the following effects, peculiarities or things to take into account:

  • Regulator forever it brings out a lower tension than it enters it. Depending on the chosen regulator (they can be many different in different NodeMCUs) that voltage reduction, or voltage drop, is usually of about 1.2 volts. Come on, if we put 4.2 volts on the 3.3 volt regulator, the regulator can give us as much 3.0 volts (the 4.2 volts from the input minus the 1.2 volts minimum difference between input and output).
  • The diode also has a voltage drop. Depending on the type of diode and the current consumed, it can be between 0.2 and more than 1 volt. This means that if we have 5.0 volts on the USB, on the Vin pin (the diode output) we will have between 4.8 and 4.0 volts.
  • The diode is normally of the Schottky type, with a voltage drop of about 0.2 volts. Other types of diodes have a higher voltage drop.

A special case: the NodeMCU V0.9 power supply

Even though the NodeMCU we find most often is called V3 there are still for sale (and some users will have a NodeMCU version 0.9 in their drawers and it will be convenient for them to know).

The power of the NodeMCU version 0.9 is almost the same as the NodeMCU V3 but there is a very important detail (for better and for worse) and that is, in this version, the 5 volts from the USB and the Vin pin are directly linked, without diode. What goes in via USB goes out via Vin and what goes in via Vin goes out via USB.

The good part is that we do not have the voltage drop caused by the diode so the voltage on the Vin pin will be the same as we have on the USB, with no drops (normally 5 volts).

The bad part is that the USB port is not protected. That means that, if we put 12 volts in the Vin pin, the NodeMCU will work perfectly, because the regulator will lower the 12 volts to the 3.3 volts that the ESP8266 needs to work, but, those 12 volts will also come out through the USB port and if we have something connected to it (charger, computer, etc.) it will most likely break down.

Provisional conclusions

With the data we have so far, we can now get some useful conclusions that may be interesting to us and that we will refine later.

From the point of view of the NodeMCU and the USB port (computer / charger):

YES we can connect external elements to the Vin and GND pins to feed them without any problem.

Not even the diode will suffer, neither the USB will suffer, nor will anyone get hurt.

Keep in mind that the USB 2.0 specification does not guarantee more than 500 mA current so if the NodeMCU, plus everything you have connected to Vin consume more than 500 mA, there might not be enough current for everything, it will depend on the charger / computer and its capacity to give more than 500 mA.

In the USB 3.0 specification the guaranteed current goes up to 900 mA.

With the USB 3.1 specification with reversible Type-C connectors the guaranteed current rises up to 2 amps.

Currently, due to the high load requirements of modern mobiles, almost all chargers, USB 2.0 and above, and computer ports, USB 2.0 and above, are rated to supply at least 1 amp, and in many cases 2 amps and more.

From the point of view of what we connect to Vin (sensor, LEDs, buzzer, or whatever):

Here comes the key to the issue. The NodeMCU does not care in the least that we connect something to its Vin pin but have we already connected it, for example, to a sensor? Do you mind being connected to that pin?

This is going to depend on the voltage requirements that that sensor (or whatever we have connected) has.

It's supposed to be 5 volts if it's 5 volts, right? but, however platitudes this may seem, this is not the case, because the devices do not operate at an exact voltage, but in a range of operating voltage.

Are devices powered from 5 volts to 5 volts? (sic)

When we say that something works at X volts, we really always mean that it works at the environment of X volts, or around of X volts.

When we are designing, we always have to go to the manufacturer's data sheet or characteristics and check what is its operating voltage range. The manufacturer will always tell us, at least, its typical, maximum and minimum operating voltage and we will be able to move in that range.

Let's look at some examples with different temperature sensors (to stick to something as an example):

LM35Data sheet2.7 ~ 5.5 V
DS18B20Data sheet3.0 ~ 5.5 V
DHT11Data sheet3.0 ~ 5.5 V
TMP36Data sheet2.7 ~ 5.5 V

As you can see, the manufacturers give some voltage ranges in which the sensor can work.

In general the voltage ranges that we have seen are quite wide, however, not all components have these ranges so great performance.

In the case of the CO2 sensors that we use in our meters, the ranges are as follows:

MH-Z19Data sheet3.6 ~ 5.5 V
MH-Z19BSensor MH-Z19BData sheet4.5 ~ 5.5 V
MH-Z19CData sheet4.9 ~ 5.1 V
Senseair S8 LPData sheet4.5 ~ 5.25 V

As you can see, the operating voltage ranges are much narrower than with temperature sensors, which we had seen before as an example.

In the case of the MH-Z19C sensor the operating voltage range is especially narrow (in fact, it is generally rare for a component to have this very narrow operating voltage range).

This very narrow range of the MH-Z19C sensor poses a problem for us, and that is that the tolerance with which the power supplies are designed is usually greater, so that it is easy that our source of the theoretical 5 volts does not provide a voltage that is between 4.9 and 5.1 volts, but higher or lower.

In the MH-Z19B and Senseair S8 LP sensors we might get to generate a problem, but, as we will see, it is not so easy that it occurs to us because they have a higher operating voltage range.

Do the 5 volt power supplies give 5 volts? (sic)

Of course not.

The "5 volts" of which we always speak, are a standard, «a name«, A way of understanding each other.

Actually, as we have seen before, when we speak of 5 volts we are not referring to a voltage of exactly 5.00 volts, but to a voltage that is in the range of the 5V, approximately.

In the context in which we are, which is that of power through cables that follow USB standards, or USB specifications, as they are often called, we have to look at those specifications to know what that range we are talking about.

According to the official technical specification for a USB 2.0 port, the port should give 5 volts with an allowable variation of ± 5%, that is: the voltage at the USB port would be a minimum of 4.75 Volts and a maximum of 5.25 Volts.

Notice I say «the voltage at the port" and not "the voltage at the connector«. This is because the wire that we usually use to connect the port with the device also has a voltage drop and it would not be strange that having 5.00 volts in the port, we had 4.85 volts, or less, at the end of a meter of cable connected to that port.

The voltage drop in the cable is an important data, can get quite high (especially in cheap cables that tend to have very fine and impure copper), and the manufacturers know it. For this reason, the vast majority of manufacturers of USB ports (the chip that controls the port), USB chargers, etc. they usually design their circuits so that voltage is at the top of the range.

Note that the USB 2.0 standard requires, to avoid the type of problems that I am telling you, that the devices work up to 4.4V and even in the USB 3.0 standard they demand that the devices work up to 4.0V.

Here we already depart from the standard, for practicality, and we talk about real life. Than we normally find.

Nobody guarantees us these results because the standard offers higher ranges, but in the vast majority of cases this is the case.

To check if this is really the case, I have measured all power supplies, chargers, desktops, laptops, SmartTVs, etc. from my house with a precision USB port meter, and these are the results (not of all, because there have been many, but they have all been around here):

As you see virtually all devices had a voltage between 5.10 and 5.25 volts, except for an LG SmartTV that drew 4.98 volts.

What voltage does the Vin pin offer when powered via USB?

The voltage we have in Vin will depend on the voltage of the USB power supply that we use and the voltage drop of the diode.

This means that we could not have 5 volts on the Vin pin, and have something less.

In the NodeMCU 1.0 and 1.1 (which are the most common, sold as boards V3) the 5 volts from the USB and the Vin pin are linked via a Schottky diode (To avoid that if voltage enters the Vin pin when it is connected to the USB that voltage does not enter the computer, charger or whatever; it could charge it).

That Schottky diode causes a voltage drop of about 0.2 volts, which means that if there is 5 volts on the USB at the Vin pin there will be about 4.8 volts.

This means, if we also consider the 5% of variation in the USB that supports the USB 2.0 specification, it would be a minimum of 4.65 Volts and a maximum of 5.05 Volts, which is within the specification of the MH-Z19, MH-Z19B and Senseair S8 LP sensors.

Powering CO2 sensors from Vin

We have already seen that there is no problem using the Vin pin to power external sensors.

Now we are going to see if we are within the ranges determined by the manufacturers to use each of the sensors taking the power from the Vin pin, knowing that this pin, in practice, should give us a voltage of a minimum of 4.65 Volts and a maximum of 5.05 Volts.

Powering the MH-Z19 via the Vin pin

According to the manufacturer it can be powered with a voltage of 3.6 to 5.5 volts, so we can power it without problems through the Vin pin.

Powering the MH-Z19B via the Vin pin

According to the manufacturer it can be powered with a voltage of 4.5 to 5.5 volts, so we can power it without problems through the Vin pin.

Powering the MH-Z19C via the Vin pin

According to the manufacturer it can be powered with a voltage of 4.9 to 5.1 volts, so we could have problems feeding it through the Vin pin.

Then we will see some ideas and tips to fix it.

Powering the Senseair S8 LP via the Vin pin

According to the manufacturer it can be powered with a voltage of 4.5 to 5.25 volts, so we can power it without problems through the Vin pin.

Does this mean that we cannot use the MH-Z19C feeding it from Vin?

Not quite.

It seems that with the maximum voltage we would walk a little fair because if, by chance, we are joined by a USB power supply that has a high voltage with a Schottky diode with a very low voltage drop (0.1 volts), we could go overboard (although it is not very likely).

We can have the problem with the minimum voltage, which is quite possible that we will fall below the 4.9 volts that it needs as a minimum to work (although probably very little).

Fortunately there are a couple of things we can do, but you will need to have a multimeter to check the measurements (before connecting the MH-Z19C):

If you measure the Vin pin with the multimeter and see that the voltage is too high, simply find another feeder that outputs a lower voltage (you sure have an old one). Plug it in, and measure again.

If the voltage is too low, you can do three things:

  1. Find a feeder that has a higher voltage.
  2. Bridge the Schottky diode with a wire (or by removing it from the board and making a bridge).
  3. Take the VCC voltage for the sensor just before the diode as you can see in the next picture (yellow wire).

Note: Please check if your board has a VU pin, as indicated in the next point.

NodeMCU boards with VU pin

There are many different NodeMCU boards with slight variations between them. There are some NodeMCU boards that have a pin marked VU.

This pin, VU, is a direct connection to USB positive. In practice, it is like bridging the diode.

You can take advantage of it to connect the sensor to this pin if it suits you (and I recommend it).

Please note that the VU pin is intended only for draw voltage from USB port, not to feed the plate through it.

VU pin is connected direct to USB so you could fry whatever you have connected to the USB (computer, charger, etc) if you apply external voltage to the VU pin.

In case it is essential to power the NodeMCU through the VU pin, as a power, you could, as long as you make sure to do not connect anything to USB (desoldering the USB connector, for example or blinding it with glue).

Additional notes

One of the possible problems could be that some NodeMCUs (it seems that few, fortunately) do not carry a schottky diode between Vin and the USB port, but a normal diode of silicon. In this case the voltage drop across the diode can be 0.6 ~ 0.8 Volts (for currents lower than 500 mA, which is what we are talking about here, for higher currents the voltage drop can be higher).

Of course, the simplest and most recommended would be measure the voltage at the Vin pin, but here what we are talking about is foresee what that voltage is going to be and if a certain design is going to work, or not, in any situation, whoever mounts it, with sufficient guarantees (at least an acceptable probability index).

If you don't have a multimeter, and the gadget minimally catches your eye, it is best to buy one. I am not telling you to spend 100 euros, but if you spend 20 or 30 euros on one it will be one of the best investments you make.

And what about Arduino?

The situation in Arduino is very similar, although more complex due to the huge variety of models (and variations of each of the models) that exist.

The good news is that all of the above is valid for Arduino and other boards based on other microcontrollers. You will just have to think a bit to know how you have to apply what you have learned in this post. You already have the base.

7 thoughts on “Alimentar desde NodeMCU, Wemos Mini D1 y Arduino”

  1. Hello Mariete, very good article, as always. It is already somewhat clearer to me what I should look at to detect power failures, greetings.

  2. Hello Marite, very good post, as always very explanatory and clear. I wanted to ask you, that meter that you have used for USB, which also gives you amperage data and others, what is it specifically? Could you tell us the purchase link if you have it quality tested? I bought one but it's very bad ... hehehehe thanks

    • Hello Luis.

      The one that I bought and it appears in the photos is this: https://s.click.aliexpress.com/e/_9AVGqn

      At the time I did measurements and the results were quite accurate, although I don't quite remember the exact figures. In addition, it has bluetooth to see the measurements on the mobile or tablet and make graphs and others.

      Good product and very good price. Completely recommendable.

  3. Thanks for my 5 min of fame.

    The truth is that my plate got 4.57 for the vin and the additional power that I have gives just 4.90 without load. So I'm just going.

    I don't like 19C at all. I'll buy myself a good senseair when the first project is done

    And thanks for all the rest of the article. It has been very clarifying

    • hahaha, you're welcome 😀

      Yes, very fair. It's a chore that these sensors are so special with food. The truth is that, at this moment, the Senseair seems to me the best option in every way.

      I am glad that you have enjoyed the article. Maybe a bit technical (I like to make more practical articles that people can follow) but surely there are those who can use the information. Anyway, it was something that had to be done and documented.


Leave a Comment