schematic and algorithm for auto-range voltmeter
Here's one simple way:







simulate this circuit &ndash; Schematic created using CircuitLab


When you drive D1, D2 and D3 to Z-state, there will be no voltage divider and you will be able to measure V_IN voltage in range from 0 to AREF
When you drive D3 low, you'll get 1:1 voltage divider, and you will be able to measure V_IN voltage in range from 0 to 2*AREF
In a similar way, driving D2 and D1 low will give you 3:1 and 7:1 dividers and measurement ranges of 4*AREF and 8*AREF respectively.


Algorithmically, you should keep driving D1 low when you connect the probe to V_IN, and progressively decrease divider ratio until the measured value increases to above 50% of your ADC range.

Shameless plug: I have a small project of mine which aims to be simple and educational, and I think I'll implement this auto-range feature next time I touch it.