What happens if you try to analogRead a voltage slightly higher than 5 volts?

I'm aware that this can and will damage the Arduino, but I'm more concerned about what the actual analog input value would be and why.

Would this overvoltage result in no input at all? Or could you theoretically get an artificially low input value, like 100 out of 1023?

Thanks for your time.

Why not just use a voltage divider to bring the over 5 volt level down to 5V range?

Imagine if you will a site like this http://www.ohmslawcalculator.com/voltage-divider-calculator where you can start off with 12V for a source voltage and 100K for R1, which will then give R2.

Then you can use some simple code, like this:

void TaskAnalogVoltRead_LIDAR( void *pvParameters )
{
  String localBuffer;
  int iBit = 1;
  float ADbits = 4095;
  float offSET = 0.0f;
  float r1 = 100800.0f; // R1 in ohm, 100k = 100,800.0 //
  float r2 = 38780.0f; // R2 in ohm, 38k = 38000.0 //actual 38780K
  float uPvolts = 3.3f;
  // ADC1 channel 0 is GPIO36
  // ADC1 channel 1 is GPIO37
  // ADC1 channel 6 is GPIO34
  // https://dl.espressif.com/doc/esp-idf/latest/api-reference/peripherals/adc.html
  // to get resistor R2 go to:
  // http://www.ohmslawcalculator.com/voltage-divider-calculator
  //   used 12 volts for the input voltage to calculate R2, used 100K for R1
  for (;;)
  {
    xEventGroupWaitBits( eg, evtAnalogVoltReadTask_LIDAR, pdTRUE, pdTRUE, portMAX_DELAY );
    // read the input
    iBit = iBit << 1;
    //    Serial.println ( iBit );
    if ( iBit == 1073741824 )
    {
      if ( xSemaphoreTake( sema_AnalogVoltRead_LIDAR, xSemaphoreTicksToWait ) == pdTRUE )
      {
        Vbatt_LIDAR += ( ((( uPvolts * adc1_get_raw(ADC1_CHANNEL_6)) / ADbits) / r2 * ( r1 + r2)) + offSET );
        Vbatt_LIDAR = Vbatt_LIDAR /2; // average readings
        xSemaphoreTake( sema_Time, xSemaphoreTicksToWait );
        fMakeTimeStamp ( localBuffer );
        xSemaphoreGive( sema_Time ); // give up semaphore
      } // if ( xSemaphoreTake( sema_AnalogVoltRead_LIDAR, xSemaphoreTicksToWait ) == pdTRUE )
      iBit = 1;
    } // if ( iBit == 1073741824 )
  }
  vTaskDelete( NULL );
}

to take a reading and get the voltage read and not put the uController at risk of making smoke!

The part your most interested in is: Vbatt_LIDAR += ( ((( uPvolts * adc1_get_raw(ADC1_CHANNEL_6)) / ADbits) / r2 * ( r1 + r2)) + offSET ); I like this part too Vbatt_LIDAR = Vbatt_LIDAR /2; // average readings to get an average reading over time, I find the value to be close to spot on.

You analog reading will be the voltage you put onto the input pin. The converted digital reading could be smoke or high heat or max but eventually smoke and or high heat.

If you exceed 5V but not more than 5.5V then you will get 1023 from analogRead().

It doesn't wrap around or anything silly.

Its a successive approximation ADC, so if you know how those work its obviously they
are saturating, not wraparound. Most ADCs are saturating anyway, its really nasty if
they aren’t.

When the internal 1.1V reference is used the output is 1023 whenever the input is above the 1.1V
reference voltage, no damage is possible until the input rises above Vcc even with the 1.1V reference.

Mind: the limit before damaging the ADC is not 5.5V. It is Vcc + 0.5V, which would be 5.5V if Vcc = 5.0V.

For a 3.3V Arduino powered at 3.3V the limit is 3.8V (and readings over 3.3V will be 1023).

For a 5V Arduino powered off a 4.6V USB supply (nominally 5V and it will operate just fine at that voltage) the limit would be 5.1V.

Take care when using the analog inputs. I made the mistake of using it to monitor the robots battery voltage directly to the analog input (no resistor) which worked fine until I unplugged the USB. Then it back powered the Arduino board through the chip burning it and other board components out.

Use voltage dividers and insure to limit the current so not to burn it out.

What burned was the clamping diode, they're rated at 1 mA, and you are allowed to rely on them to keep your pins safe (iirc Atmel even gives a suggestion of reading a 12V signal that way). What you do need is a current limiting resistor - keep your current below 0.5 mA and you're safe.

Your mistake was to not add a protection resistor. A 5V battery connected to a pin at Vcc=0V means you have a 5V difference, so a 10k resistor brings it down to 0.5 mA. That same resistor, being not part of a voltage divider or so, does not affect the voltage as seen by the analog pin.

Be aware that you also shouldn't go much above 10k as then the pin may not be able to follow the voltage well (not an issue for battery monitoring normally).

Another way to monitor your battery voltage is to use the "secret voltmeter" trick, this works great if the battery is actually powering the Arduino directly, as you'd do with e.g. a 3.7V LiPo or 2-3 1.5V AA batteries.

Thanks, the 10K in series is exactly what I know use.