How to sense 12v or Higher with Arduino?

Here is an example of level-switching - my implemention of an autoselect 2 / 10v voltmeter on the Arduino:

![](http://quantsuff.com/images/Arduino V-meter.jpg)

long readV(int inPort)
/*
 * Returns Volts at inPort in milliVolts
 * Aref must be set to "INTERNAL" for these conversions to work!
 * Warning: The 5v aref may not be accurate with USB!
 * (c) 2009 qs@quantsuff.com
 */
{ 
  long V ;
  /* Take reading from ext Meter and divide with the ADC reading,
   * then mult the previous # to get new adjustment.
   * 1M in series acts as V-divider
   * Parallel 150k to gnd to get 9.5v fs */

  float ref9V5adjust = 9.22983;  // Start: 9.319;
  float ref2V2adjust = 2.121742; //Cal'd against known good meter

  digitalWrite(13,HIGH) ; // 10v scale first
  delay(10);
  V= analogRead(inPin); // 0-1023 on 2v2 scale
  V= (analogRead(inPin) * ref9V5adjust) + .5 ;
  digitalWrite(13,LOW);
  if (V<2200) {
    delay(10);
    V= analogRead(inPin) ;
    V= (analogRead(inPin) * ref2V2adjust) + .5 ; // ignore prev readings
  }
  return(V);

This is the output as the Arduino monitored its own voltages (Aref and 3.3).