AREF Voltage reference not working in code

I had a friend write me some code which works perfectly on a MEGA32U4 PRO MICRO.but i now want to run it on a ATMEGA328P-AU TQFP-32

the code basically displays 4 temperature readings from four TMP36 Sensors

problem is temperature readings are incorrect, by about 2c

5v VCC is not 100% accurate 4.95v so any fluctuations in the voltage messes with temperature readings. i believe aref reference pin connected to vcc stops this issue. so maybe aref not working (code issue?)

i also have to connect vcc (5v) to A5 to stop the temperature reading going to -100

when i connect 5v to A5 i get a reading of 18c and real temperature reading should be 20c
so i believe i just need to fix the aref to 5v and fix the code.

unfortunately i am very new to writing code i have been trying myself but if im honest i dont know what im doing and my friend that originally write the code is away at the minute so was wondering if anyone on here would have a look at the code and hopefully something will stand out to a more experienced user on here.i would be more than happy to send some cash or parts? as a thank you for taking time to help me as i don't expect waste any free time on me. anyone interested i will PM the code to you. thanks from pete

What's an LM36 sensor? Is it ratiometric or absolute?

I think its ratiometric.. SORRY my mistake its a TMP36 Sensor and Not a lm36..
tmp36Sensor INFO

so was wondering if anyone on here would have a look at the code

I guess not, since you didn't post it.

Forum wont let me post code as exceeds limit

here is a txt file of my code that can be downloaded from this LINK

petebirk:
Forum wont let me post code as exceeds limit

here is a txt file of my code that can be downloaded from this LINK

Maybe on your computer. Not on mine.

If you use Reply, not the stupid Quick Reply field, there is a link below the text field where you can attach your code.

Sorry here is the code i was trying the upload the code onto here so can easily be viewed but keeps saying exceeded characters limits.

code.txt (15.7 KB)

petebirk:
I think its ratiometric.. SORRY my mistake its a TMP36 Sensor and Not a lm36..
tmp36Sensor INFO

No its not ratiometric, its absolute.

By default AREF is internally connected to Vcc, if you want a precision reference on
AREF then you need to call

  analogReference(EXTERNAL);

in setup (). Whatever voltage reference you connect to AREF should be
low impedance (normally the decoupling capacitor on the AREF pin does
that job).

Rather than calling analogRead() twice with a 44 ms gap, read it repeatedly for 44ms and
average the reading, then you'll be cancelling noise.

Or, more simply add a capacitor on the pin to ground to filter out noise. Plastic film,
not ceramic for analog signal filtering is best.