In this video we'll be looking at voltage dividers for makers and this guide will hopefully be the only one you need to watch on the topic. We're going to go over what a voltage divider is as well as looking at the diagram for one as well as the voltage divider equation and we'll look at an awesome voltage divider simulation that you can use as well as you know wiring one up and looking at some helpful code for the Pico. So let's get right on into it. A good way to think of a voltage divider is that it's a voltage scaler. It takes one voltage and scales it down to a lower voltage and it only scales down not up and this has a huge amount of applications but the most relevant for us is in microcontrollers. This Pico for example can only read an analog voltage in the 3.3 to 0 volt range and a voltage divider lets us take a higher voltage and scale it down into that range so a Pico can read it. This video is a bit Pico-centric but it's not specifically dedicated to it and we're going to cover much of your voltage divider needs in this video regardless. A very common application of a divider and one you should definitely use whenever you have one is in battery monitoring. If your project is AA or LiPo powered you can use a voltage divider to scale the voltage of the battery down so that your microcontroller can well monitor it. Super helpful stuff. An important thing before we begin though, you can't really power things like motors, servos or lights off a voltage divider. They are for reading voltages, signals and sensors. Trying to power anything more than 10 or 5 milliamps with a voltage divider and you start to run into some issues. If you want to step down a voltage to power something you will need a step-down converter like this one which we'll have some links to below. Really handy and really simple to use. Also if you're looking to turn 5 volt logic into 3.3 logic or vice versa it might be easier to use one of these bi-directional logic converters. Again they're super cheap and way easier to use than a voltage divider.
Let's work with an example. Now we have this LiPo battery here with a voltage of 12.6 volts when it's fully charged and we want to measure that with the pico which can only measure up to 3.3 volts. So what does a voltage divider look like? Well first things first we're going to need two resistors and these are just the symbols for resistors. These little squiggly lines here like so and out of the battery we're going to have the positive 12.6 volts but also the negative or the ground wire. So we're going to go ahead and connect that ground wire to the bottom of this resistor and then on our pico we're going to take one of the ground pins and ensure that this also connects to the battery because everything needs a shared common ground so they know what voltage is what. And then all we're going to do is connect the 12 volts coming out of the battery to the top of the resistor and then connect these two together like so. Now this middle section here is where our output voltage is going to be so we're going to go ahead and connect that to an analog pin of our pico. There's no analog pins on that side but you get the point. One more thing let's name our resistors. The one at the top is pretty much always going to be called R1 and the one at the bottom is pretty much always going to be called R2. Math jump scare time. Now this is our voltage divider equation and don't worry if your brain isn't built for math we have a way to solve this or figure this out without any math whatsoever coming up in a bit. But all this equation is really saying is that the output voltage which will be the voltage here is equal to the input voltage which is our battery times by R2 divided by R1 plus R2. So the values of R1 and R2 here are creating this kind of scaling factor this multiplier that we multiply V in by and get our output voltage. And this is kind of the core concept of a voltage divider. The ratio between R1 and R2 that we pick is how we choose to you know change and scale V out as we need. Now we have to choose the values of R1 and R2 but math aside for a quick it's very important that we make sure that our resistors are sufficiently large enough. A good rule of thumb is to ensure that R1 and R2 are between 1000 and 10 000 ohms but if you need to go outside this range make them a bit bigger so maybe 20 or 30 000 ohms but try and stick within that range. If we make our resistors too small they're going to draw more current and a that's a waste of power but B if you choose it really small like 20 or 30 ohms you might start a fire with how hot these resistors are going to get. So good rule of thumb stick between 1 to 10 000 ohms. So with our equation let's just randomly pick a value for R2 to be equal to 1000 and I'm just going to go ahead and solve this equation. And after arbitrarily picking R2 as a 1000 we find that R1 is 2812 and both of these resistor values are in the 1 to 10 000 range so these are probably going to work.
We're running out of room here but before we go ahead and wire this up there is a fantastic tool we can use called Fousted circuit simulator. This is a free online simulator and it's one of the old reliables of electrical engineering and of course you'll find a link to this in the video description below. Once you're in Fousted head on over to circuits and then go basics and look for a voltage divider. Now this is actually two voltage dividers and as you can see you can actually chain them together like so but we don't need that right now so we're just going to highlight them and then hit backspace to delete them off like so. And we can also use middle mouse click to move us around and scroll to move in we're just going to angle it nicely like so. And now we can have a play around and simulate our voltage divider. I'm just going to double click on our voltage source which will be our LiPo battery and I'm going to set it to our maximum fully charged voltage of 12.6 volts. And just to make it easier to see what's going on I'm going to right click this duplicate it this is just a little voltage meter and if we attach it to the node up here you should see that we have our 12.6 from our battery and you can actually see that this green color here is the voltage as it goes through it starts at 12.6 and it makes its way around and once it gets past the resistors it comes back to zero which will be black or gray. And these yellow dots here you see moving around is actually the current flowing in this circuit. So let's go and double check our math by setting R1 to what was it 2818 and setting R2 to 1000 like so. Oh the current's flowing a little bit too quick let's just slow it down so we can see what's going on and as you can see we get our nice 3.3 volt output. Very nice. We could also use this tool to calculate the values of the resistors we need with trial and error without using the voltage divider equation. Let's say instead we wanted to turn let's just go for something arbitrary 9 volts into 3.3 volts. I'm going to start by just setting R2 to 1000 ohms again and then we can play around with R1 till we get the 3.3 volts we want. Nope we need to go probably a little bit smaller than that let's try 1800 let's try a bit smaller than that 1700. Oh look at that those are two resistor values that get us pretty close and probably as close as we need. But we could have also gotten a few different answers because it's about the ratio between them right so if I double these we could have just as easily gotten 2k and 3.4k like so we get the exact same voltage out. So just remember it's the ratio between the resistors that's important and as long as they're between one and ten thousand any possible combination will work. We do have one more issue here though I'm just going to go back to our 12.6 volt example like so now this says we need a 2818 ohm resistor and the problem is they don't exist resistors don't come in every single size possible they come in different sets of standard sizes.
Here is my trusty book full of standard size resistors and as you can see we do have a one kilo ohm resistor but we don't have a 2.8 kilo ohm resistor let alone 2818 and the closest we have here is 3300 ohms. But we can try this in Falstad and see what happens I'm just going to set this to 3.3k and you can see we don't get our full 3.3 volt output we do get a little under though but that's okay because we can adjust that in code as long as it's in our readable range. If you need it to be precise you can try and use different combinations of resistors to get closer to that voltage for example here I found that 10 kilo ohms and 3.3 kilo ohms gets us a bit closer to 3.3 volts. You can also put resistors in series here I have a 2.2k and a 680 ohm resistor together and these add up to make 2800 both of these are standard sizes and it gets us really close to that 2800 ohm we need. This might be a really good option but for our needs I'm happy to just stick with 1k and 3.3k because we can just go ahead and fix it in code. I really do recommend having a play around with this Falstad simulation as it's a really great way of building that understanding and intuition of electrical circuits.
Okay we know what resistor sizes we need we know that we can actually get a hold of these resistor sizes let's wire it up. We are going to be using a breadboard to build our circuit. First off let's pop our Pico into the breadboard and then we're going to get these two wires here which will connect to our LiPo battery. Ensure that your battery is disconnected because you don't want to work on a circuit when it's powered. Like in the diagram we'll connect our negative wire of the battery to ground and we'll use this ground rail here to do so and then we'll ensure that the Pico shares the same ground. Then we'll place in R1 and R2 our 3.3k and 1k ohm resistors and then we'll connect them to ground and as you can see this forms a nice electrical loop like so and then we'll connect the middle of these resistors to an analog pin of the Pico and this wire connected between the resistors is going to be the output voltage of our divider. Always double check your circuit before powering it on because if you do something like accidentally connecting the Pico to 12 volts directly you're going to damage it quite badly.
Now I have this meter here which is going to show us the voltage of the battery and if I plug it in like so you can see that we're getting a fully charged 12.6 volts and if I grab this multimeter here I'm just going to need to unplug this from the Pico real quick because this is kind of another resistor to ground and if I measure from ground to the pin that will be plugged into our Pico you can see that we're getting close to that 2.9 volts that we saw in Falstad. There may be some slight differences as there usually is translating something into the real world but our voltage divider is working exactly like we want it to and I have some micropython code here you'll find in the written guide below if you want to use it. All we need to do is input the values of R1 and R2 and then we read that analog pin turn it into a voltage between 0 and 3.3 volts just standard Pico stuff and then we're going to use the voltage divider equation to figure out what the battery voltage is based on that analog voltage reading and if we run this see that the voltage is printed off in the shell and if we plug in the battery you can see that we were reading 12.6 and we're calculating it to be about 12.4 12.5 volts which is slightly off but it's within 0.1 and we could calibrate it from here.
Now we haven't actually been using a battery we've been using a power supply which will do the exact same thing and you can see that as we lower the voltage we should be able to match it what our Pico is reading and we could do anything from here like shut down the project if it gets to a certain voltage to save the battery or or if you're using double A's you could send a notification that the batteries need replacing before it runs out of power whatever your project needs you can now achieve it with the power of a voltage divider. Well that about wraps it up for this video we hope you enjoyed it and that you got something out of it and if you need a hand with anything voltage divider related or anything we covered in this video feel free to head on over to our community forums there's an army of makers there who are happy to help. Until next time, happy making.
Makers love reviews as much as you do, please follow this link to review the products you have purchased.