I am using a ATmega328 with optiboot bootloader with a CP2102 TTL-USB converter, and I am reading the ADC value from a LM35 temperature sensor, with a very simple code of just converting the value to the actual voltage.
The problem is whenever I am opening the serial monitor the first data it prints out is almost double of the actual value, this is happening whenever I am reopening the serial monitor even without re-uploading the code, or resetting/re-powering the board.
This is interfering with my actual project, which sends the data through a wifi-module(ESP8266), so there might be no problem with the TTL-USB converter.
Calling the analogRead and making a delay for the first time solves the problem. I think there is a massive voltage ripple during the time of resetting the MCU which is causing the problem.
By the way, I am also having a voltage sag, which is causing the ADC to measure 200mV less than the actual voltage, due to the power hungry ESP8266 sitting beside it. Maybe using a bigger PSU will solve that.