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.

/***** ADC *****/
// 16MHz/128 = 125kHz
//ADMUX |= (1<<REFS0) | (1<<REFS1); //1.1В
ADMUX |= (1<<REFS0); //AVcc with capasitor as AREF pin



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.
• Are you pulsing or pwm these LEDs? That would increase noise in the system. – Nedd Feb 24 '18 at 11:40
• I don't use PWM. Just set the high or low signal on the LED. – Marat Gareev Feb 24 '18 at 11:48
• You did say LEDs, you currently show only one in your example. Another source of noise may come about if you are actively using one of the dual purpose I/O/ADC pins as digital outputs, (for example PC0, PC1, PC2, PC3), while performing a conversion. – Nedd Feb 24 '18 at 13:18
• What if you sink current instead of sourcing to the LEDs? "Turn around" the LED, connect to Vcc and see if it improves anything. – filo Feb 25 '18 at 11:18

Some things to try:

Increase the value of the bypass caps on Aref, Vcc, and AVcc (p20) of the 328P.

Insure that the supply and ground path of the variable resistor are not directly inline with the supply or ground path of the LEDs.

Reduce the load on the 328P by driving the LED's with a transistor or additional gate.

For further critical noise reduction the Atmega328/P data book contains additional improvement methods, see the ADC chapter.