I use atmega328p. I'm trying to read data from a variable resistor using an ADC. The microcontroller also has LEDs connected. If I ignite them, the data from the ADC increases noticeably.
Initializing the ADC:
/***** ADC *****/
ADCSRA |= (1<<ADPS2) | (1<<ADPS1) | (1<<ADPS0); //128
// 16MHz/128 = 125kHz
ADCSRA |= (1<<ADIE); //enable interrupt
ADCSRA |= (1<<ADEN); //enable adc
//ADMUX |= (1<<REFS0) | (1<<REFS1); //1.1В
ADMUX |= (1<<REFS0); //AVcc with capasitor as AREF pin
ADCSRA |= (1<<ADSC); //new start
ADMUX |= (1<<MUX0) | (1<<MUX2); //ADC5
How can I solve this problem?
I apologize for the scheme, but I do not have the right program at hand.
Extra info due to answers:
- In the normal state, the ADC value is 2. If I light the LED, the value is increased to 20. I changed the 220 Ω resistor to 1 kΩ, now value increases from 2 to 7. Voltage comes from USB 3.0.
- In an attempt to make the PSU stronger I tried to solder the second USB connector and energize in parallel. Nothing changed.