This is my first post, my searches didn't find a similar issue on the forum. I am a rank beginner with Arduino, electronics and programming, that said here goes...
I have a very simple circuit setup to learn how a few things work: pushbuttons, LEDs, a pot, digital and analog pins.
- I have 2 pushbuttons, on pins 4 & 5, going through 100Ω resistors, then through the pushbuttons, then to gnd. (my goal is to reverse the logic and use built-in pull-up resistors, but I'm just starting out)
- I have a red and yellow LED, each connected with 330Ω resistors to gnd.
- I have a 10kΩ pot connected to 5V and gnd, with the wiper connected to A4.
- I have the 5V and gnd tied to the rails of my breadboard.
- It is all powered by USB for this experiment.
In my code I read the pot on A4 every few seconds as opposed to each time through the loop (e.g. a 'long' for a counter variable, reading every time it gets to 100000). I have the buttons acting as independent "toggles" (push-on, push-off) to turn on/off each of the LEDs. I added serial output to see the analog value being read from the pot.
It seems for some reason, that I didn't expect, turning on or off the LEDs changes the analog value being read. If I have the pot at 0 (fully clockwise in this case), and I turn on either LED, the analog value goes up to about 30, both LEDs on and it goes up to about 60. The contribution is less at higher pot values (e.g. each LED only adds about 20 when around 800).
I am assuming I've accidentally created some multi-resistor circuit when the LEDs get turned on.
Is there something obvious that I've done wrong that is causing the analog value to fluctuate? Is there some equally simple way to avoid it?
I can post my code and fritzing if those would help, but I suspect I'm just missing some very basic principle here.
Thanks for any insights.