Contents
- 1 Doubt or query
- 2 Provisional conclusions
- 3 Feeding CO2 sensors from Vin
- 4 NodeMCU boards with VU pin
- 5 Additional notes
- 6 What about Arduino?
On many occasions, in our projects, we power our microcontroller via a USB cable connected to a mobile phone or computer charger and we need to power peripherals (sensors, screens, displays, LEDs, etc.) that operate at 5 voltsCan we do this without any problems through the NodeMCU?
Recently, the user Jesús, made a comment in the blog, specifically in the article of the Home CO2 Meter with wifi, really interesting.
I started to reply to the comment and as I wrote, the reply became longer and longer and I realised that I needed more resources to answer it (images, video, a richer format, etc). I decided that it was a very interesting topic and one that could be used for much moreThe article you are reading is the result of this, and I was able to cover it minimally (every time I tried to explain one point I realised that I had to explain others in order to make sense of it).
Basically, the issue was, whether we can use the external power input of a NodeMCU for powering peripherals operating at 5 volts.
Everything I explain in the article is also valid for Arduino but with some caveats that I will discuss later (because there is not just one Arduino, but many, and you have to look at each one, because they are different). It also applies to boards like the Wemos D1 Mini, ESP32 DevKit and the like.
In this article I talk about the example of powering an NDIR CO2 sensor but it is equally valid for any other type of sensor or actuator you want to power.
Doubt or query
Specifically, the user said the following in his comment:
"I have been doing some research and it turns out that the ESP is incapable of supplying 5V. The Vin/GND is there to supply it with "unregulated" voltage between 5V and 12V. But not to get 5V out of it. In fact, the fact that it gives voltage when connected to micro USB is a by-product, not a specification. In fact, in any project that needs 5V (motors), you need a dedicated power supply, you can't pull from Vin (from what I've been reading). With the MH-Z19B you're lucky because its input range is wider (although it's so close to the limit that it's almost certainly not working for some people and they're getting jumpy values), but with the MH-Z19C it's not."
It is certainly a very valid observationThis is very useful if we need to power certain sensors or peripherals at 5 volts, especially if it requires a power supply that is very close to the exact 5V (as is the case of the MH-Z19C CO2 sensor that needs to work, according to the manufacturer's specifications, a voltage between 4.9 and 5.1 volts).
My sincere congratulations to Jesús, because he has hit on a very important point and, moreover, as he himself points out, he has no idea about electronics (and this article is aimed precisely at those who have no idea about electronics; to help them to find their way out of doubts or to find out something of information founded).
As you know, the problem with the claims you read on the internet is that, as with everything in life, there are claims of all kinds and colours and, in many cases, they are based solely on word of mouth without any halfway rigorous technical explanation. In addition, people have a tendency to generalise and where one thing is true, in a given case, there is a similar case where it is not..
Searching the internet I found multitude of sites saying that the NodeMCU is incapable of providing 5V, claiming that the fact that the Vin pin provides 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 to life if you connect something to the Vin pin while powering the NodeMCU via USB.
The reality is that, not being completely false that the NodeMCU is unable to provide 5V, in most cases this will not affect us. when connecting peripherals such as sensors and displays.
Fortunately, the NodeMCU (and the Wemos D1 Mini, different Arduinos and ESP32 boards) and its components are very well documentedso it is easy to analyse what is the reality and in which cases this is true and in which cases it is not true.
The substance of the issue
The question that arises, in the end, is a simple one.
The NodeMCU is usually feeding in two ways:
- By means of a USB port (such as a mobile phone charger, computer, etc.)
- By means of a tension applied to its pins Vin and GND
Most of the time we power the NodeMCU or the Arduino with a USB power supply/charger of the ones 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 the need to seek independent power supply?
The power supply of the NodeMCU V3
To begin to analyse the situation and whether or not there really is a problem, let's take a look at how the NodeMCU power supply works.
I will refer in this explanation to NodeMCU V3, which is the most widespread today, and later I will refer to older versions.
This is an excerpt from the NodeMCU schematic with the power supply circuitry:
The explanation of this scheme is very simple, and I believe that any amateur can understand it if it is explained in plain, colloquial words (even if we miss a few things along the way). nuance):
- The ESP8266which is the microcontroller that is mounted on the NodeMCU board, actually 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 input (within the limits of the regulator) will draw 3.3 volts to power the ESP8266.
- The Vin (positive) and GND (negative) pins are also connected to the same voltage regulator, except that they are connected to the same voltage regulator. with an interleaved diode (which only allows current to flow in one direction) so that, when you put voltage across the Vin and GND pins, the current will only flow in one direction. does not come out of the USB to the charger or computer and spoil it..
The above has the following effects, peculiarities or things to take into account:
- The regulator always puts out a lower voltage than it puts in. Depending on the regulator chosen (there can be many different regulators in different NodeMCUs), this voltage reduction, or voltage drop, is usually about approximately 1.2 volts. In other words, if we add 4.2 volts to the 3.3 volt regulator, the regulator will be able to give us at most 3.0 volts (the 4.2 volts at 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 from between 0.2 and more than 1 volt. This means that if we have 5.0 volts on the USB, we will have between 4.8 and 4.0 volts on the Vin pin (the output of the diode).
- 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: Powering the NodeMCU V0.9
Although the NodeMCU most often encountered is called V3 there is still a NodeMCU version 0.9 for sale (and some users will have it in their drawers and will want to know about it).
The power supply of NodeMCU version 0.9 is almost the same as NodeMCU V3 but there is one 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 connectedwithout diode. What goes in through USB goes out through Vin and what goes in through Vin goes out through USB.
The good part is that we don't 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 drop (typically 5 volts).
The downside is that the USB port is not protected. That means that, if we put 12 volts on the Vin pin, the NodeMCU will work perfectly, because the regulator will bring the 12 volts down to the 3.3 volts that the ESP8266 needs to work, but the NodeMCU will not be able to work, those 12 volts will also come out of the USB port. and if we have something connected to it (charger, computer, etc.) it will most likely break down.
Provisional conclusions
On the basis of the data we have so far, we can already draw some useful conclusions which may be of interest to us and which we will then refine.
From the point of view of the NodeMCU and the USB port (computer/charger):
YES external elements can be connected to the Vin and GND pins. to feed them without any problem.
Nor will the diode suffer, nor will the USB suffer, nor will anyone be hurt.
It should be noted that the USB 2.0 specification does not guarantee more than 500 mA current so if the NodeMCU, plus everything connected to the Vin consumes 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 rises to 900 mA.
With the USB 3.1 specification with reversible Type-C connectors the guaranteed current rises to 2 amps.
Nowadays, due to the high charging requirements of modern mobile phones, 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):
This is the crux of the matter. The NodeMCU doesn't care if we connect something to its Vin pin, but what about if we have connected it to, say, a sensor, does it care if it is connected to that pin?
This will depend on the voltage requirements of that sensor (or whatever we have connected).
If they are 5 volts, they are supposed to be 5 volts, aren't they? But, as commonplace as it may seem, this is not the case because the devices do not operate at an exact voltage, but within an operating voltage range.
Are 5 volt devices powered at 5 volts (sic)?
When we say that something works at X volts, we really always mean that it works at X volts. environment of X volts, or around of X volts.
When we are designing, we always have to go to the manufacturer's datasheet or characteristics and check which one is its operating voltage range. The manufacturer will always tell us at least their typical operating voltage, maximum and minimum, and we can move within that range.
Let's look at some examples with different temperature sensors (to stick to something as an example):
Model | Image | Datasheet | Voltage | Datum |
---|---|---|---|---|
LM35 | Fact sheet | 2.7~5.5 V | ||
DS18B20 | Fact sheet | 3.0~5.5 V | ||
DHT11 | Fact sheet | 3.0~5.5 V | ||
TMP36 | Fact sheet | 2.7~5.5 V |
As you can see the manufacturers give voltage ranges in which the sensor can operate.
In general the voltage ranges we have seen are quite wide, however, not all components have such large operating ranges.
In the case of the CO2 sensors we use in our meters, the ranges are as follows:
Si2300 | Si2306 | Si2320 | |
---|---|---|---|
You | 20A | 30A | 20A |
Id | 3.6A | 2.8A @ Vgs = 4.5V | 2.4A @ Vgs = 2.5V |
VGS(th) | 1.5V | 1V | 0.65V |
Maximum Vgs | ±12V | ±20V | ±8V |
Rds(on) | 0.085(Ω) at VGS = 2.5 V | 0.094(Ω) @ VGS = 4.5 V | 0.085(Ω) @ VGS = 2.5 V, ID = 3.1A |
As you can see the operating voltage ranges are much narrower than with the temperature sensors, which we have seen before as an example.
In the case of the MH-Z19C sensor the operating voltage range is particularly narrow (in fact, it is generally rare for a component to have such a narrow operating voltage range).
This very narrow range of the MH-Z19C sensor poses a problem, and that is that it the tolerance with which power supplies are designed is generally higherand therefore it is easy for our source of the theoretical 5 volts not to provide a voltage that is between 4.9 and 5.1 volts.but more or less.
In the MH-Z19B and Senseair S8 LP sensors, we could This is a problem, but, as we will see, it is not so easy to have a problem because they have a wider operating voltage range.
Do the 5 volt power supplies give 5 volts (sic)?
Of course not.
The "5 volts" that we always talk about, are a standard, "a name"a way of understanding each other.
Actually, as we have seen before, when we talk about 5 volts we are not referring to a voltage of exactly 5.00 volts, but to a voltage that is in the range of approximately 5V.
In the context we are in, which is that of powering through cables that follow USB standards, or USB specificationsWe have to look at those specifications to know what range we are talking about.
According to the official technical specification for a USB 2.0 port, the port should deliver 5 volts with a permissible variation of ±5%, i.e: the voltage at the USB port would be a minimum of 4.75 Volts and a maximum of 5.25 Volts.
Note that I say "the voltage at the port"and not "the voltage at the connector". This is because the cable that we usually use to connect the port to the device. also has a voltage drop and it would not be unusual to have 5.00 volts at the port, but to have 4.85 volts, or less, at the end of a metre of cable connected to that port.
The voltage drop in the cable is important, can be quite high (especially in cheap cables that tend to have very thin, impure copper), and manufacturers know this. For this reason, the vast majority of manufacturers of USB ports (the chip that controls the port), USB chargers, etc. tend to design their circuits so that this voltage is at the top of the range.
Note that the USB 2.0 standard requires, in order to avoid the kind of problems I'm talking about, that the devices must work in the following way up to 4.4V and even in the USB 3.0 standard require devices to work with up to 4.0V.
Here we depart from the standard, for the sake of practicality, and we talk about real life. From what we normally find.
No one can guarantee these results because the standard offers higher ranges, but in the vast majority of cases this is the case.
To check whether this is indeed the case, I have measured all power supplies, chargers, desktops, laptops, SmartTVs, etc. in my house with a precision USB port meter.The results are in (not all of them, because there have been many, but all of them have been here):
As you can see virtually all devices had a voltage between 5.10 and 5.25 volts.except for an LG SmartTV which put out 4.98 volts.
What voltage does the Vin pin provide when powered by USB?
The voltage we have at Vin will depend on the voltage of the USB power supply we use and the voltage drop of the diode.
This means that we could have no 5 volts on the Vin pin, and have somewhat less.
In NodeMCU 1.0 and 1.1 (which are the most common, sold as NodeMCU 1.0 and 1.1 boards), the V3) the 5 volts of the USB and the Vin pin are linked via a Schottky diode (to avoid that if voltage enters the Vin pin when connected to the USB, that voltage does not enter the computer, charger or whatever; which could charge it).
That Schottky diode causes a voltage drop of about 0.2 volts, which means that if there are 5 volts on the USB at the Vin pin there will be about 4.8 volts.
This means, if we also take into account 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 Voltswhich is within the specification of the MH-Z19, MH-Z19B and Senseair S8 LP sensors.
Feeding 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 for using each of the sensors by taking the power supply from the Vin pin, knowing that this pin, in practice, should give us a voltage of one 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 any problems via 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 any problems via 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 might have problems to power it via the Vin pin.
We will then look at some ideas and tips on how to solve it.
Powering the Senseair S8 LP via the Vin pin
According to the manufacturer it can be supplied with a voltage of 4.5 to 5.25 volts, so we can supply it without any problems via the Vin pin.
Does this mean that we cannot use the MH-Z19C feeding it from Vin?
Not exactly.
It seems that with the maximum voltage we would be a bit short of the maximum voltage because if, by chance, a high voltage USB power supply meets a Schottky diode with a very low voltage drop (0.1 volts), we could overdo it (although this is not very likely).
The problem may be with the minimum voltageIt is quite possible that we will fall below the minimum 4.9 volts it needs to operate (although probably by a very small amount).
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 power supply that puts out a lower voltage (you probably have an old one). Plug it in, and measure again.
If the voltage is too low, you can do three things:
- Look for a power supply with a higher voltage.
- Jumper the Schottky diode with a jumper wire (or by removing it from the board and making a jumper).
- Take the VCC voltage for the sensor just before the diode as you can see in the following picture (yellow wire).
Note: 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 bypassing the diode.
You can use 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 the USB portnot to feed the board 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 supply, you could, as long as you make sure to do not connect anything to the USB (e.g. by unsoldering the USB connector or gluing it).
Additional notes
One of the possible problems could be that some NodeMCUs (fortunately, it seems to be rare) do not carry a Schottky diode between Vin and the USB port, but rather a normal diode of silicon. In this case the voltage drop across the diode can be 0.6~0.8 Volts (for currents below 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 advisable thing to do would be to measure the voltage at pin Vinbut here we are talking about foresee what that voltage is going to be and whether or not a given design is going to work in any given situation, no matter who mounts it, with sufficient guarantees (at least an acceptable probability rate).
If you don't have a multimeter, and you are interested in tinkering, the best thing to do is to buy one. I'm 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 will ever make.
What about Arduino?
The situation on the 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 everything listed above is Valid for Arduino and other microcontroller based boards.. 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 basis.
Thanks for my 5 min of fame.
The truth is that my board was getting 4.57 for the vin and the additional power supply I have gives 4.90 without load. In other words, I'm doing very well.
I don't like the 19C at all. I will buy a good senseair when I finish the first project.
And thank you for the rest of the article. It was very enlightening
hahaha, you're welcome 😀
Yes, very fair. It's a shame that those sensors are so particular about the power supply. The truth is that, at the moment, the Senseair seems to me to be the best option in every way.
I'm glad you liked the article. Maybe a bit technical (I like to make more practical articles that people can follow) but I'm sure some people could use the information. Anyway, it was something that needed to be done and documented.
Hi 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 and other data, what is it in particular? Could you tell us the purchase link if you have it tested for quality. I bought one but it's very bad...hehehehehehe thanks
Hello Luis.
The one I bought and is shown in the photos is this one: https://s.click.aliexpress.com/e/_9AVGqn
At the time I took measurements and the results were quite accurate, although I don't remember the exact figures. It also has bluetooth so you can see the measurements on your mobile or tablet and make graphs and so on.
Good product and very good price. Highly recommended.
Thanks, I'll take a look and get it. Cheers and as always fast and efficient. Regards
Hi Mariete, very good article, as always. It is now a little clearer to me what I should look for in order to detect faults in the feed, best regards.
Thank you very much, Carlos.
I am very glad you found it useful.
Best regards.
Good, first thanks for the article, very detailed and very useful. The doubts arise with the 3.3v pin, I understand that they are for powering the board (in my case a nodeMC).
I am working on a project that needs to be connected to a battery, I have thought about a pair of 18650 in parallel that would be charged with a solar panel by means of the typical TP and I was thinking about using a regulator in load sharing mode, and the output of all this stuff to put it in the 3.3v pin of the nodemcu.
The question is, how do I feed the sensors I have (a dsq8b20)? Do I use the same output that the loadsharing gives? Do I feed it (the sensor) from some pin of the nodemcu?
Thank you very much
J.