This project uses a joystick to control an RGB LED. When the joystick is at a certain position, the LED changes colors. In my project, the led colors are green, yellow, orange, blue, and pink. The reason I made this project is simple, to improve my Arduino programming/ hardware skills. This is a very easy and fun project to do.
The joystick is connected to the 5 volt connection and ground. The X axis of the joystick is connected to A0, and the Y axis is connected to A1. The RGB LED is oriented in a way that from left to right the pins are red, ground (the longest pin), green, and blue. The red is connected to pin 9, green to 10, and blue to 11 (make sure you use a minimum of 330 ohm resistor, or your led will be destroyed). The pins that the LED are connected are special because they have the ~ character on them. This means PWM or Pulse Width Modulation. You are able to control the duty cycle on these pins allowing you to control the specific color of the RGB LED. For a Common Anode RGB LED connect to 5v instead of ground.
The reason I include the two "contributors" on this page is because I sat down today not knowing how to program an LED or a joystick, and their sites were very helpful. I mashed some code together, and ended up with this.
EXPANDED TECHNICAL DETAILS
Analog Input to PWM Color Mixing
This project maps the 2-axis physical movement of a joystick to the 3-channel color output of an RGB LED.
- Joystick Mechanism: Uses two 10kΩ potentiometers (X and Y axes) and an integrated click-button. The Arduino's ADC translates these positions into values from 0 to 1023.
- PWM Duty Cycle: The firmware uses the
map()function to convert the 10-bit joystick data into 8-bit PWM signals (0-255).
Interactive Logic
- Color Space Mapping: Moving the stick on the X-axis might control the Red intensity, while the Y-axis controls Green. The Z-axis (clicking the stick) can be programmed to toggle Blue or reset the color.
- Aesthetics: This creates a physical "Color Picker" tool, ideal for mood lighting, interactive art installations, or learning about additive color mixing.