I plan on measuring the voltage of a battery depending on its charge level. When fully charged, the battery delivers 24V. I plan on using a voltage divider that would divide the voltage by ten, so it's under the 5V limit of the Arduino.
Do I need to use a voltage regulator or a Zener diode as well? And what about the current?
5V zener on the output of your divider for safety is a good idea. As long as your resistors are large enough, current won't be a problem. A good rule of thumb would be to keep your input resistor 10k or higher.
Do you know if the way I power the Arduino matters in that case? I was just planning on pluging it on my computer with the usb port. I was told the following:
"The quality of the voltage measurements is directly linked to the quality of the source that serves as a voltage reference.
With a Uno card there are 3 possible voltage sources:
-the Vcc or 5V USB ± 5% or by internal regulator
-the Aref input
-the internal reference 1.1 V ± 10
If a 3.3 V reference can be used, it is the best choice. The card has a 3.3 V regulator that is never used, so it is clean. Just connect this 3.3 V to Aref."
What seems like the best option to you in that case?
I'm sorry if this is a dumb question but this is the 1st time I'm using an Arduino and I struggle a bit...
The way you power it really won't matter. As far as the reference voltage, use whichever one best suits your purposes. If 5% tolerance is fine (it usually is!), then use the default reference.
If you use the internal 1.1 voltage reference , then your divider can be set to give fsd at 1.1 volts .
That input is still protected to Vcc (3.3v or 5v ), so you can considerably over voltage it ( ~5* 24v) safely .
You can use ‘ map’ in your code and calibrate it by adjusting the mapped to values .
I would disagree with that.
Using a zener diode on the input of something you want to measure will result in inaccurate readings. This is because a zener has an effect even below it's rated voltage. The knee, as the transition is called, is not ideal nor is it infinitely sharp like a lot of text books sometimes show.
Much better are clamping diodes to the power supply.
The pins are protected by diodes on the chip to Vcc and GND. They can stand 1 mA, you should limit the current with a resistor or the resistors of your divider.
The value of the resistance must be calculated to the actual voltage you expect in worst case, to limit the current to less than 1mA.
In this case you want to measure up to 24 Volts. The voltage divider may be enough to meet the demand for current limiting.
On the other hand, the analog inputs of the processor were designed for a source with less than 10k resistance.
The picture shows a solution that meet both demands.
If you connect 3.3V to AREF, be sure to use analogReference(EXTERNAL) or you may fry your processor.
As for the question of Vcc: it’s called 5 Volts, but:
If the board is fed from Vin the voltage is 5 Volts plus or minus a margin determined by the maker of the onboard regulator. If the board is powered by the USB the voltage is the 5 Volts from your computer, also with a margin, minus the voltage of 1 diode.
No they were not. The value of 10K is just the optimum impedance. You can use much higher impedance voltage sources up to 100K. Any higher then you will need to read the same input twice and only use the second reading.
Sorry wrong advice. How can the output voltage ever be plus anything? It is always minus a voltage drop.
Correct advice:-
Never apply 5V to the Vin pin, because the internal regulator will not function and will supply a much lower voltage to processor. This is normally insufficient to make the Uno work. If you have 5V from an external source and want to use that to power the Arduino then connect it to the 5V pin.
The power regulators have all a certain inaccuracy. But if you power the MCU from USB, there is a voltage drop. A normal silicon diode drops about 0.6 Volts. On the Nano Every it’s a Schottkey-diode, about 0.4 Volts. On the UNO R3 it’s a switched MOSFET, about 0.2 Volts. For other boards I’d need to look at the schematics
When reading the position of a potmeter it doesn’t matter, as you’ll use the same supply as the reference.
For reading an independent voltage source, the accuracy of the reference does matter.
The time necessary for charging the S/H capacitor might be more than twice the sampling time of the ADC (up to 10 times with your 100k?), so even the second measurement may not be accurate.
In any well designed ADC with S/H, the holding capacitor must be fully discharged before the next reading is initiated. Otherwise, the new reading will include the residual charge on the capacitor and thus be inaccurate. I do not see that an Arduino has a 'zero' command so I think the capacitor is discharged automatically after the ADC reading is transferred to the output register. If so, the second reading will be very similar to the first. In other words, keep the ADC input resistance at or below 10K ohms for accurate readings.
To expand on this, 10k maximum source impedance is nominally the largest value for which the sample and hold (S/H) capacitance of the ADC is "negligible". "Negligible" means the S/H capacitor has time to charge to it's "final value" in the period between switching to the desired analog input pin and the start of the "hold" part of the ADC conversion cycle.
Sampling twice in succession ensures that the analog input pin was already the desired input so it has a longer window to charge to the "final value" through a higher than 10k source impedance.
Another way to approach this is to have a capacitor much larger than the S/H capacitance across the analog input pin so that charging the S/H capacitor is mostly just charge transfer from the external capacitor rather than current flowing through the voltage divider. For battery monitoring applications, this enables the use of very high resistance (on the order of a megaOhm) resistors in the voltage divider, so there is less parasitic drain on the battery from the voltage monitoring circuit.
I may be fairly new to Arduino, I am not new to electronics. And I am not new to reading datasheets.
If the datasheet says that the inputpin will be connected to the S/H capacitor for 1.5 ADC_CLOCK cycles, I take that at face value. No matter how much delay you put in, the next time the connection will also last 1.5 ADC_CLOCK cycles. Yes, the second time the S/H capacitor starts closer to ‘real’ voltage, thus the measurement will be closer, but will it be GOOD?
No.
Quite simply the residual charge makes the achieving of the final voltage easier. Providing that the last input was zero and the new input the full limit. In which case it takes as long as it would if the residual charge was reduced to zero. There is no advantage and in fact a disadvantage in reducing the residual charge to zero every time.