Incorrect value reading from the analog input set up from the ADC ATmega328p

Hello everyone. I need help understanding what’s going on with the analog pin reading. I have programmed the ADC of the seeeduine v4.2 that I’m using, which has an ATmega328p, to read an analog input pin. The result I get is 1023 all the time and I am monitoring the sensor with a multimeter at the same time to check the reading value, which varies very low from 5V. Then something very strange happened to me since I am a beginner with Arduino. The code worked correctly when the Arduino Mega DDK board was wrongly chosen (I don’t know how it happened because I had the seeeduinov4 board installed all along) with the following message
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_getsync(): timeout communicating with programmer

From this message, I realized that the correct board was not configured. I chose seeeduinov4 again but it was no longer on the list. I reinstalled it, tried this board and it still gives me 1023 all the time. When I changed the board to Arduino Mega DDK in the IDE, I also see 1023 now. I don’t understand either why it doesn’t work now and if it can, installing new boards will deconfigure something else in the IDE.
Also I have doubts with the libraries. I installed a generic library (the adafruit avrprog) and my code specifies the avr/io.h and the avr/interrupt.h. Maybe those 2 libraries I need are not included in the one I installed?

I would appreciate it if someone could help me since I need to advance with urgency in this project. Thank you very much in advance. I leave the code commented below.

#include<avr/io.h>
#include<util/delay.h>
#include<avr/interrupt.h>

#define SET(port,bit) port|=(1<<bit)
#define CLR(port,bit) port&=~(1<<bit)
#define TOGGLE(PORT,BIT) PORT^=(1<<BIT)

//Variables declaration for the timer interruption
int cont50=0; //milliseconds counter
int FLAG50=0; //milliseconds flag to change the on-off leds sequence

//Variables declaration for the photodiode
uint8_t pin=0;//analog input pin
uint16_t readch2=0; float voltagech2=0.0; //chanel 2 photodiode value (it is the photodiode placed on the headband)
int delay_send=0; //

//Set up Timer0
void timer0_init() {
CLR(TCCR0A,WGM00);//Set Timer0 to normal mode
CLR(TCCR0A,WGM01);//Set Timer0 to normal mode
CLR(TCCR0B,WGM02);//Set Timer0 to normal mode
TCNT0=0X00; //timer0 account starts equal to 0
SET(SREG,7); //global interruptions enabled
SET(TIMSK0,TOIE0); // Timer0 Overflow interruption enabled
}

//Set up internal ckl source clocked by the prescaler clk/1024
void enable_timer() {
SET(TCCR0B,CS00);//set clk prescaler to 1024
CLR(TCCR0B,CS01);//set clk prescaler to 1024
SET(TCCR0B,CS02);//set clk prescaler to 1024
}

void ADC_init(){

ADMUX|= (1<<REFS0); //AVcc 5V as voltage reference and ADC0 pin (A0 pin) selected by default
DIDR0=(1<<ADC0D);//digital input disabled

//frequency division set up => 16000kHz/128 = 125kHz
ADCSRA |= (1<<ADPS0);
ADCSRA |= (1<<ADPS1);
ADCSRA |= (1<<ADPS2);

ADCSRA|=(1<<ADSC);//Start conversion in the single mode
while(ADCSRA & (1<<ADSC));//fictition reading
}

uint16_t ADC_GetData (uint8_t pin){

ADMUX=(ADMUX&~(0X1F))|(pin&0x1F);//channel selected without modifying the others bits in ADMUX register
ADCSRA = (1<<ADEN); //conversion enabled
//_delay_us(10);//warming up the AD converter
ADCSRA |= (1<<ADSC); // Start conversion
while (ADCSRA & (1<<ADSC)); // wait for conversion to complete
ADCSRA|=(1<<ADSC);//flag set up again
return (ADCW);//THIS VALUE IS A NUMBER BETWEEN 0-1023
}

int main() {

Serial.begin (9600);

//analog inputs definition for the photodiodes (pins in port C)
DDRC|=(0<<PC0); //A0 pin set up as input (photodiode placed on the headband=ch2)

// DDRC|=(0<<PC1); //A1 pin set up as input (photodiode placed on the breadboard)

//AD converter set up

ADC_init();
//digital pins set up for the leds as outputs (port B). The order is the same as the leds are placed on the breadboard (change it in the future as it will be different in the headband)
DDRB|=(1<<PB4); //pin12, infrared LED (left)
DDRB|=(1<<PB3); //pin11, red led (left)
DDRB|=(1<<PB2); //pin10, red led (right)
DDRB|=(1<<PB1); //pin9, infrared led (right)

timer0_init(); //starts the count
enable_timer(); //with prescaler clock

while(1) { //analog to void (loop)

readch2=ADC_GetData (0);
voltagech2=readch2*5.0f/1024.0f;

Serial.print(readch2);
Serial.print(",");
Serial.println(voltagech2);
}//end endless loop
} //fin main

//Timer0 OVF rutine service interruption
ISR(TIMER0_OVF_vect) {

if (FLAG50==0) {
cont50++;
delay_send++;

/* if(delay_send==100){

readch2=ADC_GetData (0);
voltagech2=readch2*5.0f/1024.0f;

Serial.print(readch2);
Serial.print(",");
Serial.println(voltagech2);

delay_send=0;
}*/

if (cont50==306) { //now it is 3seconds - turn on the red leds and turn off the IR - “Hb” measuremment
cont50=0;
SET (PORTB, PB4);//led infrarojo (left), pin 12
SET (PORTB, PB2);//led rojo (right),pin 11
CLR (PORTB, PB3);//led rojo (left), pin 10
CLR (PORTB, PB1);//led infrarojo (right), pin 9
FLAG50=1; //now I have to invert the on-off sequence
}

}//end if flag50

if (FLAG50==1) {
cont50++;
delay_send++;

/* if(delay_send==100){

readch2=ADC_GetData (0);
voltagech2=readch2*5.0f/1024.0f;

Serial.print(readch2);
Serial.print(",");
Serial.println(voltagech2);

delay_send=0;
}*/
if (cont50==306) { //now it is 3seconds - turn off the red leds and turn on the IR - “Hb02” measuremment
cont50=0;
CLR (PORTB, PB4);
CLR (PORTB, PB2);
SET (PORTB, PB3);
SET (PORTB, PB1);
FLAG50=2; //now I have to turn off every led to measure the environmental light
}
}

if (FLAG50==2) {
cont50++;
delay_send++;

/* if(delay_send==100){

readch2=ADC_GetData (0);
voltagech2=readch2*5.0f/1024.0f;

Serial.print(readch2);
Serial.print(",");
Serial.println(voltagech2);

delay_send=0;
}*/

if (cont50==306) { //tur off every led - environmental light measuremment
cont50=0;
CLR (PORTB, PB4);
CLR (PORTB, PB2);
CLR (PORTB, PB3);
CLR (PORTB, PB1);
FLAG50=0; //to repeat the cicle
}
}

}