Using internal analog reference in a standalone ATmega328 chip

Hi All,

My first post! I'm using a LM35 temperature sensor connected to analog input 4 of a standalone ATmega328 chip to read out the temperature. The project is going to be battery powered, so I'm expecting that, when the battery depletes over time, the voltage will drop below 5V, and the temperature reading will be incorrect, if I use the default 5V analog reference. Therefore, I decided to use the internal aref of 1.1V. I'm powering the project using a 5V battery pack.

I have added the "analogReference(INTERNAL)" to the setup(), and using the below code to read out the temperature.

sensor = analogRead(4);
voltage = (sensor*1100)/1024;
celsius = (voltage / 10);

But I'm getting a very low temperature reading around 6 degrees Celsius, when the actual temperature is around 30 degrees Celsius. When I do the calculation manually, I can see that if I replace 1100 with 5000, I get the reading that I expect. Am I missing something?

Thanks!

use floats to prevent truncating math?

int sensor = analogRead(4);
float voltage = (sensor*1100.0)/1024.0;
float celsius = (voltage / 10.0);

or in a oneliner

float celsius = analogRead(4) * 0.107422;