![]() With these we can now program the Arduino to turn on green and red accordingly. Next you need to figure out your middle bounds, when the LED is yellow. Using the voltage divider formula we get: Now that we have our Vout, Z1, and Z2 we are ready to use that to get the input voltage. We will first need to convert our analog value into voltage.įloat Vout = analogRead(A0) * (5.0/1023.0) ![]() We will just need to set the pins for our LED. Part 3: Programmingįirst we need to establish our resistance values for Z 1 and Z 2 for uses by the Arduino. See the diagram for hooking up the battery to your Arduino. If you are using a larger power source you will need to get a 5v voltage regulator that can handle your input voltage. The Arduino Nano can handle voltages between 6v and 20v so if testing a battery make sure if falls into those areas. ![]() In order for the Arduino to read the voltage value you will have to power the Arduino with the same battery. I used pin D2 for the green and D3 for the red. Once you have your battery hooked up you need to link up your LED. I hooked my battery into the A0 pin on the Arduino but any pin will work fine. The circuit on the left is the template for the battery circuit and the one on the right is the diagram for my circuit. Now that we have all of our parts let’s wire our circuit. See the wiring diagram for a clearer view. A nice trick that I am using since I have a 2:1 ratio is placing two 330Ω in series to get my needed 660Ω. I have a bunch of 330Ω resistors lying around so I will use 660Ω for Z 1 and 330Ω for Z 2. I can chose any value for these resistors so long as they maintain the 2:1 ratio. Below is my solution:įor me the ratio of my resistors will be 2:1. Now we can get the ratio of the resistors. I chose 15v for my V in because it is a multiple of 5. This number can also be a nice number to work with. Because all batteries can exceed their max voltage sometimes you should calculate with a number higher than the max voltage. The battery I am using has a max voltage of 14.2v. Using the formula below we can calculate the ratio of the resistors. I have used a voltage divider in the past with the thermometer to calculate the resistance across a thermistor, but we can now use the formula to calculate the input voltage, which will be the power coming from the battery. This can be done by using a voltage divider. Most ADCs on Arduinos have a max input of +5v, but if we wanted to test a battery that is greater than +5v we need to lower the maximum voltage the Arduino will receive. In order for the Arduino to calculate voltage it uses an Analog-Digital Converter.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |