Arduino voltmeter to measure more than 12V, and optoisolator issue

Hi, So Im designing a project where Ill need to read voltage with voltage divider, and a few digital inputs and outputs at the same time. Can anyone tell me why my digital read is cut when increase the voltage past 5.40V? How do I go and do this the right way?

here is my circuit

A schematic is preferable.
A good picture of your wiring is need.
Include a copy of your sketch using </> code tags.

The voltmeter divider needs to be of values to suit the input such that no more than 5v is put on the input pin at your highest test voltage.

Therefore if the highest voltage is 10v, you have two Rs the same, say 10k each. If the the highest voltage is 25v, you need a ratio of 4:1 so you read only a fifth of the voltage. Your software then converts the reading to actual voltage.

The R values chosen should be such that the divider total R is over 10k and under 50k. As you can only get certain values of standard Rs, you will need to build in a calibration factor into your software.

It is preferred that with the digital input that the R goes from 5v to the input and the switch goes to gnd.


The Fritzing diagram shows a voltage divider across Arduino's own 5volt supply. That won't work with default Aref. The divider is always a fixed percentage of the reference voltage, so always returns the same digital value. You can measure the supply voltage by using a 1:4 divider, and measure against internal 1.1volt Aref. Which is usually better (stable) anyway.

Not sure where the opto fits in. Problems with that could be the (unknown) resistor values. Leo..