Detecting unknown voltages between 5v and 12v

I am trying to figure out how to detect and quantify a voltage that is greater than 5v, but could be 6v, 9v, 12v, etc.

The voltage I will be measuring is not fixed. If it was I could use a voltage divider to drop it down to 5v then use the ADC.

Any suggestions ?

Still a voltage divider, depending upon what you are doing. If it is just to read the voltage with no current requirements, then the divider is the easiest to do.

Set it up so the highest voltage you expect is equivalent to 5V at the center, and the rest of the calculation is done through code.

It might also help to be a bit more descriptive with what you are working on.

Use a voltage divider, and measure the voltage with analogRead(). A 10K + 5K divider will map 0-15V to 0-5V.

For other resistance values see Voltage Divider

Yes. A better description of what I am trying to do is in order.

For my powered breadboard (my design) I have input voltage options of 1.5v, 3v, 5v, 6v and 12v. I will decide which will be the input voltage used depending on what I am doing (1.5v battery simulation, etc.).

I have pots along the side that I can measure and adjust and then engage in the circuit. But the pots do not have a very high wattage rating. So I am using an arduino and an oled to sense what the input voltage is, sense the resistor value and then provide a text warning specifying the max allowable current thru the pot.

I have the ohmeter working fine, but I am wrestling with how to know what values in the sketch to use to get back to, say, 9v (which I need to do to calculate the max current). I am trying to sense which of the 5 voltages is being used, then I can do the math in some if statements.

I am trying to sense which of the 5 voltages is being used

And for some reason, you think that using a 3:1 voltage divider, and actually measuring the voltage, won't accomplish that task?

Then no matter whether the supply voltage is 1.5v or 12v, the VD divides it by 4, which makes it readable to the ADC, which returns a value, and the sketch multiplies that value by 4, which is then used in the power calculation. Right ?

pratto:
Then no matter whether the supply voltage is 1.5v or 12v, the VD divides it by 4, which makes it readable to the ADC, which returns a value, and the sketch multiplies that value by 4, which is then used in the power calculation. Right ?

Exactly

Nitpick: it doesn't multiply it by 4, since analogRead() gives you a value from 0~1023. I would probably map(value,0,1023,0,20000), giving you the voltage in millivolts (thus keeping it as an integer, instead of a float - when possible, you want to avoid using floats in Arduino sketches. The precision of floats is not quite enough to not notice float precision artifacts when doing common arduino tasks, and floating point math bloats the sketch size (ie, if you can eliminate all floats from your sketch, you save a surprising amount of flash).

ok. great. the range you used in MAP, 0-20000. does this give greater precision ?

does this give greater precision ?

No. The most precision you will ever have is in the original measurement.

pratto:
ok. great. the range you used in MAP, 0-20000. does this give greater precision ?

It gives greater precision than converting it to a float and doing math with it as a float.

You don't gain anything from the fact that it's 0~20000 instead of 0~1023 in terms of precision, though it probably makes the code more readable and intuitive to have the voltage represented in units of millivolts vs units of (19.whatever mV)