Hey everyone, I'm not so new to Arduinos/programming but I'm still pretty green with the electronics side of things... was given a job to make something to measure the voltage of a car battery rigged to an audio system (so what I'd really be doing is just measuring the car battery voltage) as well as wiring up an IR temperature sensor and printing these readouts to a screen.
But I'm having some difficulty making sense of it because I'm so new to the electronics side. I've gathered as much that the program itself would use the analogRead() function for this part, and once I get the three separate parts working (measuring the voltage, the IR sensor, and the screen) i should be able to just put them together using the right logic/flow control as I've done similarly in the past, but if someone could help explain to me just how to use the voltage divider or how to physically connect this part that would be especially appreciated.
As for the voltage range, it should measure between 16-9.5 volts, and i have quite a variety of resistor values at my disposal for a voltage divider. Thanks!
Did you understand what I posted in the previous thread?
Use a [u]Voltage Divider[/u] (2 resistors). A 1:3 voltage divider can be made with a 1K resistor and a 2K resistor.
With 16V into the 1:3 voltage divider you get 5.33V.
So, a 1:3 divider won't quite get you down from 16 to 5V, but you can change the voltage divider. (Resistors come in "standard" values, so you probably won't find exactly what you want, but it's easy to adjust the math.)
The analog-to-digital converter reads 0-1023, with 1023 corresponding to Vcc (5V). So, you just combine the voltage divider ratio and the ADC ratio to get the voltage. i.e. With the 1:3 voltage divider V = ADC x 3 x (5/1023). With a little algebra (if all my math is right) that simplifies to V = ADC/68.2.
Oh okay, that makes perfect sense. And yes, I do understand the analogRead voltage example you posted above with the potentiometer, but I had only used analogRead with a joystick in a previous project so that clarifies it a lot, thanks!
I will also give that voltage divider tutorial a closer look when I get there, thanks!
Also, the example using the potentiometer leads me to my next question, which is... if I were to try making something to measure a voltage range (such as 16-9v, just for example), could I use a potentiometer in place of a voltage divider because it's a variable resistor? I would imagine that it would be connected to ground, an analog input, and the car battery in this case, but is there any way I could use a voltage divider from the car battery (into the potentiometer) in order to step it down and measure an adjustable range? Sorry if this seems like a dumb question, I know voltage dividers depend on a set number in the first place so I'm not sure if that can even be done, I was just given a range as part of this job so I wasn't sure if there may be some way I could have an adjustable range or if it could only be one set number. Thanks!
Ah, alright. Yeah, I'm sure there would be pretty heavy vibrations going on so if that were the case a potentiometer may not work. And again, only reason I thought of that instead of set resistors is so it could handle a specified range rather than a set voltage, but that may just be what I have to do anyway. Thanks!
Don’t overlook the fact that your measurements, with or without a voltage divider, will always have zero volts as the lower number in the range.
You cannot measure the range of 9 to 16 volts with an Arduino at the full 0 to 1023 count range of the analog section, it will be 0-16 volts being equal to 0-1023 counts. To exapand the analog range to 9 to 16 volts being equal to 0 to 1023 counts would require some op amps and circuitry to offset the voltage so that 9 volts was zero analog counts and 16 volts was 1023.
Another aspect of the Arduino A/D convertor is that 1023 counts is not a guaranteed 5.000 volts. In actuality, it is the voltage at the output of the 5 volt regulator which rarely will be exactly 5.00 volts. 4.95 or 4.92 might be more realistic. The result is that the analog readings will be zero counts at (approximately) zero volts and 1023 counts when the input equals the actual 5 volt supply voltage.
Not very wise to read a voltage with the potentially unstable default (5volt) Aref.
Better to drop that 16volt to ~1volt (with a ~1:15 divider), and measure with 1.1volt Aref enabled in setup().
47k between battery(+) and analogue pin, and 3k3 between pin and ground could work.
Smoothing code could increase resolution to 10mV (two decimal places).
Let us know if you need help with that.
Leo..