RGB LED WITH JOYSTICK CONTROL


40

3

Introduction: RGB LED WITH JOYSTICK CONTROL

Hey,come let's do this interesting project.

Supplies:

Arduino
lcd 16x2 display
joystick
rgb led
potentiometer
jumper wires

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: Connection

Lcd Display:
VSS - Gnd
VDD - 5V
VO - potentiometer
RS - Gnd
RW - 11
E - 12
D4 - 5
D5 - 4
D6 - 3
D7 - 2
Potetiometer:
Middle - lcd's VO pin
Another - 5V or Nothing
Another - Gnd
Joystick:
Gnd - Gnd
5V - 5V
VRX - A0
VRY - A1
SW - 6
RGB led:
long end - Gnd
Other 3 - 8 , 9 , 10 Respectively

Step 2: Coding

#include
#include
int contrast=75;
LiquidCrystal lcd(12,11,5,4,3,2);
#define redPin 9
#define greenPin 10
#define bluePin 8
// Arduino pin numbers
const int SWpin = 6; // digital pin connected to switch output
const int Xpin = 0; // analog pin connected to X output
const int Ypin = 1; // analog pin connected to Y output
int r,b,g,a,n;

void setup() {
pinMode(SWpin, INPUT);
digitalWrite(SWpin, HIGH);
lcd.begin(16,2);
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
r=0;
b=127;
g=0;
a=0;
}

void loop() {
if(digitalRead(SWpin)==0)
{
a=a+1;
};
if(a==4)
{
a=1;
};
switch(a)
{
case 1:
lcd.clear();
lcd.print("Red: ");
n=analogRead(Ypin);
if(n==0&r>0)
{
r=r-1;
}
if(n>1000&r<225)
{
r=r+1;
}
lcd.print(r);
setColor(r,g,b);
break;
case 2:
lcd.clear();
lcd.print("Blue: ");
n=analogRead(Ypin);
if(n==0&b>127)
{
b=b-1;
}
if(n>1000&b<225)
{
b=b+1;
}
lcd.print(b);
setColor(r,g,b);
break;
case 3:
lcd.clear();
lcd.print("Green:");
n=analogRead(Ypin);
if(n==0&g>0)
{
g=g-1;
}
if(n>1000&g<225)
{
g=g+1;
}
lcd.print(g);
setColor(r,g,b);
break;

}
delay(100);

}
void setColor(int red, int green, int blue)
{
analogWrite(redPin, red);
analogWrite(greenPin, green);
analogWrite(bluePin, blue);
}

Step 3: Video YOUTUBE

https://youtu.be/GVxPgRuVwBw

Be the First to Share

    Recommendations

    • Magnets Challenge

      Magnets Challenge
    • Raspberry Pi Contest 2020

      Raspberry Pi Contest 2020
    • Wearables Contest

      Wearables Contest

    3 Discussions

    0
    audreyobscura
    audreyobscura

    7 weeks ago

    Would love to see more written steps from your build and your circuit diagram.

    0
    RksTEch
    RksTEch

    Reply 18 days ago

    Ok

    0
    RksTEch
    RksTEch

    7 weeks ago

    Sorry for the low quality video