What is RGB?
RGB (red, green, and blue) refers to a system for representing the colors to be used on a computer display. Red, green, and blue can be combined in various proportions to obtain any color in the visible spectrum. Levels of R, G, and B can each range from 0 to 100 percent of full intensity. Each level is represented by the range of decimal numbers from 0 to 255 (256 levels for each color), equivalent to the range of binary numbers from 00000000 to 11111111, or hexadecimal 00 to FF. The total number of available colors is 256 x 256 x 256, or 16,777,216 possible colors.
Understanding RGB Color Model
A color model is a process for creating more colors using a few primary colors. There are two types of color models: the Additive color model and the subtractive color model. In the additive color, model light is used to display colors. While in the subtractive color model, printing inks are used to produce color. The most common additive color model used is an RGB color model, and a CMYK color model is used for printing.
RGB color model is the additive color model using Red, green and blue colors. The main use of the RGB color model is for displaying images on electronic devices. In this process of the RGB color model, if the three colors are superimposed with the least intensity, then the black color is formed, and if it is added with the full intensity of light, then the white color is formed. To make a different array of colors, these primary colors should be superimposed in different intensities. According to some studies, the intensity of each primary colour can vary from 0 to 255, resulting in the creation of almost 16,777,216 colors.
What is Joystick ?
Output Voltage Mapping with XY Position
At Idle position output voltage, will be VCC/2. Now considering VCC = 5 volts, following fig. shows the voltage mapping with different XY position.
When the joystick is at idle position, the output value of the X terminal and Y terminal are Centre (2.5V) of the specified range (0V to 5V). According to the movement of a holder, the output values are varying from minimum limit (0V) to maximum limit (5V).
This Joystick also has a select button/switch that is actuated when the Joystick knob pressed down.
Pin Description:-
Pin 1, 5 - VCC and GND
Supply voltage(+5V) and ground given to Joystick.
Pin 2 –X-OUT
This pin provides an analog output voltage from 0 volts to VCC according to the movement of Holder in X-direction (axis).
Pin 3 - Y-OUT
This pin provides an analog output voltage from 0 volts to VCC according to the movement of Holder in Y- direction (axis).
Pin 4 - Switch
This pin has one tactile switch.
When a switch is not pressed, this pin is connected to VCC through a resistor.
When a switch is pressed, this pin is connected to Ground.
Controlling RGB Light using Joystick:-
In this Project I'll show you How you can control RGB Light using Analog Joystick.
You can control the colors of RGB led using Joystick.
If you take Common Cathode or Common Anode RGB led just take a look at the picture below.
Common Anode RGB led Common pin must be connected to +5v.
Common Cathode RGB led Common pin must be connected to GND.
Parts List:-
1. Arduino Nano : https://amzn.to/3wg9tty 2. RGB Leds : https://amzn.to/3iEougX 3. Joystick Module : https://amzn.to/3Ehr85J 4. Breadboard : https://amzn.to/3vUFRC6 5. Jumper Wires : https://amzn.to/34smHIo
Steps to make this project:
1. Gather all components.
2. Place Arduino Nano on Breadboard.
3. Connect RGB led with 330 ohm resistor.
4. Connect Jumper wires to Joystick module.
5. Do connections from circuit diagram.
6. Upload code and enjoy.
Your Project is ready.
Circuit Diagram:
int R_PIN = 9; //Pin for the red portion of the LED int G_PIN = 10; //Pin for the red portion of the LED int B_PIN = 11; //Pin for the red portion of the LED int JX_PIN = 0; //Pin for the Joystick X Direction (Analog) int JY_PIN = 1; //Pin for the Joystick Y Direction (Analog) int JSW_PIN = 2; //Pin for the Joystick Switch (Analog) int joyX; //Variable to store the Joystick X reading int joyY; //Variable to store the Joystick Y reading int joySW; //Variable to store the Joystick Switch Reading //Setup the Arduino void setup() { pinMode(R_PIN, OUTPUT); //Make the pin you used an output on the Arduino pinMode(G_PIN, OUTPUT); //Make the pin you used an output on the Arduino pinMode(B_PIN, OUTPUT); //Make the pin you used an output on the Arduino } //This function will update the RGB LED when called void setRGB(int rLed, int gLed, int bLed) { analogWrite(R_PIN, rLed); analogWrite(G_PIN, gLed); analogWrite(B_PIN, bLed); } //This code will run infinitely void loop() { delay(100); //Delay 100mS to slow to 10 readings per second joyX = analogRead(JX_PIN); //Read the X position joyY = analogRead(JY_PIN); //Read the Y position joySW = analogRead(JSW_PIN); //Read the Switch, 255 or 0 setRGB(joyX, joyY, joySW); //Set the RGB output to the inputs from the joystick }
0 Comments