I want to measure voltages with my Arduino Uno : Some voltages go from 0V to 3V, others from 0V to ~15V.
I want to have the best accuracy, so I would like to divide the voltage only when needed, and with the best value.
Is it possible to make an automatic voltage divider ? I thought about using transistors as switch to trigger parallel resistors for example, I don’t really know how to do it. Maybe the Arduino would change the divider if the voltage read is >1V for example.
Is it possible ? What do I need, and most of all, is it safe for the Arduino ?
Hi, welcome to the forum.
An Arduino pin may not be below 0V and not above 5V (for a 5V Arduino board).
It is however allowed to push up to 1mA into a pin (or pull 1mA).
The impedance of the circuit for an analog input should be 10k or less for good accuracy.
Using transistors to switch will introduce inaccuracy. They can't handle negative voltages, and they have a voltage drop when turned on. Just one circuit for -20 ... + 5V might be more accurate than all kind of fancy automatic things. Is 50mV resolution accurate enough ?
The internal voltage reference can be 5V or 1.1V (for an Arduino Uno). That can be used for higher accuracy.
For more accuracy, you need an external voltage reference. For even more accuracy, use an external ADC with buildin voltage reference.
An alternative is to use two analog inputs. They have each a voltage divider, and the measuring point is connected. One input would clip if used with the wrong range, but then the other input is used.
There is even another option. The range can be altered by an output pin and a few resistors. The pins of an Arduino are very high impedance when set as input, and as output they are better than transistors (only for low currents). It is even possible to combine all three things (internal voltage reference, two analog inputs, outputs that control resistor network).
To protect the Arduino, a resistor might be enough (if no more than 1mA is pushed or pulled from the Arduino pin), but it is better to use clamping diodes to GND and 5V and and extra 1k resistor from the clamping diodes to the Arduino pin.
What accuracy do you want for the different ranges ?
With all the information above, can you make a drawing of a circuit ?
10k in series with the Arduino analog input, 4k7 from that input to another pin.
The resistance of an ATmega output is less than 100 ohm.
Incidentally, if you pull the output HIGH instead of LOW (as you do to measure 0 to 15V) then you can measure voltages in the range -10V to +5V.
You might care to “play safe” and include a 1N914 diode between the analog input and +5V.
The only restriction is that you should give the ADC a little time to settle between switching analog inputs and/ or take two readings and discard the first.
And - of course this is possible, safe and practical. How else do you imagine auto-ranging digital voltmeters operate?
^ That's clever.
Maybe 22k in series with the analogue measuring pin, and 10k from there to a digital pin.
Digital pin can be set as an output, and made high or low. Or can be set as an input (floating).
Use 10n from analogue pin to ground.
You can make two voltage dividers and select one or the other with an SPDT relay. (single pole, double throw). The input side of the relay contacts poles is the output of the voltage dividers. The COM of the relay goes to the analog input. This way the voltage is always within allowed range regardless of which input is selected.
Your ideas sound very exciting.
Would it be possible for one of you to upload a diagram, for the shake of us that have a limited knowledge in electronics?
What is the accuracy that you want for which range ?
What is the absolute maximum voltage that can be measured, before the Arduino gets damaged ?
I still prefer no auto-ranging. A single range of 0 to 15V with 30mV resolution.
I read -15 before, that was what I read on my tablet but you ment up to about 15V
You can do auto ranging.
Here is What I did in a project.
I don't see anything that specifies whether the voltages are Analog or digital in nature. Is everyone assuming Analog?
Should we be asking WHY the OP wants to measure them ?
Maybe the Arduino would change the divider if the voltage read is >1V for example.
You could interpret that to mean a logic high. I think it’s time to ask why the OP wants to measure these
Are you sure the OP isn't just asking for a 3V TTL -> 15V CMOS level converter ?