Electronic – Arduino: read different voltage values in a range from -12 to +12V

arduinoresistorsvoltagevoltage divider

I would like to trigger different functions in Arduino related to the following voltage values: -12V, 0V, 6V, 9V, 12V (the range is from -12V to +12V).

According to the value of the voltage read (-12V, 0V, 6V, 9V, 12V) I have to show instantly different light animations on a LED strip.

enter image description here

Considering that the Arduino is not able to read a such voltages directly, I suppose that probably I have to use a voltage divider, but I don't know how to calculate the resistors to use. Can anyone help me?

Thank you.

I was suggested also to use 1 dual op amp do the following:

  1. Create inverting amplifier with a gain of 1, but insert a offset of 12V to the + (non inverting pin), this will max your -12 to 12V range change to a -24-0V range.

  2. To the output of stage 1, connect another inverting amplifier with gain of 0.2 you would get a a positive voltage range of 0-4.8V which is fine to work with the arduino's 0-5V ADC tolerance.

What do you think about this idea?

Best Answer

enter image description here

Figure 1. The voltage levels to be detected.

Since you never have to detect 0 V you can treat any voltage below 6 V as -12 V.


simulate this circuit – Schematic created using CircuitLab

Figure 2. Level converter circuit. D1 protects the ADC against negative voltage inputs. The R1 / R2 divider gives an output of 5/12 times the input voltage.

On your logic you could set thresholds of 10.5 V, 7.5 V and 3 V for each of the analog 'windows'. For a 10-bit ADC these would correspond to \$ 1024 \frac {10.5 \times 5}{12} \$ for the 10.5 V threshold, etc.

If you have the comparator then you could use this to detect each positive going edge - set the threshold to 3 V (1024 * 3 / 12) - and after a short delay sample the voltage.

Note that I chose 7k and 5k to make the voltage divider ratio blatantly obvious. Choose some standard values close enough to do the same job.