How to control RGB lights using Joystick

 

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 ?

An analog stick, sometimes called a control stickjoystick, or thumb-stick is an input device for a controller (often a game controller) that is used for two-dimensional input. An analog stick is a variation of a joystick, consisting of a protrusion from the controller; input is based on the position of this protrusion in relation to the default "center" position. While digital sticks rely on single electrical connections for movement (using internal digital electrical contacts for up, down, left and right), analog sticks use continuous electrical activity running through potentiometers. The analog stick has greatly overtaken the D-pad in both prominence and usage in console video games.
 


Joystick is an input device. Analog joystick is sometimes called as Control Stick. It is used to control the pointer movement in 2-dimension axis. The joystick has two potentiometers to read user’s input. One potentiometer is used to get the analog output voltage for X-Direction movement and the other potentiometer is used to get the analog output voltage for Y-Direction movement.  The potentiometers are connected between +VCC and Ground. They simply behave as Voltage Divider NetworkThe joystick has one freewheeling Holder. According to the holder movement, the potentiometer knob changes its position and resistance of the potentiometer.

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:

 


 

 

Just Copy the code and paste it in Arduino IDE
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 }


 

 

If you want to make your customized project. Message me

Telegram / WhatsApp : +919557024177
Instagram Page : eif.08
 
You can check other blogs also :-

Post a Comment

0 Comments