Control an RGB LED with a Button | Beginner Arduino Project

preview_player
Показать описание
In this tutorial, you will learn to use Arduino to make a simple RGB LED Light and adjust it's color with a button.
Рекомендации по теме
Комментарии
Автор

Guys i wrote the Code, Here
// define pins
#define BLUE 3
#define GREEN 5
#define RED 6
#define button 2

// define color mode
int mode = 0;

void setup() {
// setup LED lights
pinMode(RED, OUTPUT);
pinMode(GREEN, OUTPUT);
pinMode(BLUE, OUTPUT);
//setup buttons
pinMode(button, INPUT_PULLUP);


}
void loop() {

if (digitalRead(button) == LOW) {
mode = mode + 1;
delay(400);
}
// off
if (mode == 0) {
analogWrite(BLUE, 0);
analogWrite(GREEN, 0);
analogWrite(RED, 0);
}
// White
if (mode == 1) {
analogWrite(BLUE, 225);
analogWrite(GREEN, 225);
analogWrite(RED, 225);
}
// Red
if (mode == 2) {
analogWrite(BLUE, 0);
analogWrite(GREEN, 0);
analogWrite(RED, 225);

}
// Orange
if (mode == 3) {
analogWrite(BLUE, 0);
analogWrite(GREEN, 75);
analogWrite(RED, 225);
}

// Yellow
if (mode == 4) {
analogWrite(BLUE, 0);
analogWrite(GREEN, 220);
analogWrite(RED, 225);
}

//Green
if (mode == 5) {
analogWrite(BLUE, 0);
analogWrite(GREEN, 225);
analogWrite(RED, 0);
}

//Blue
if (mode == 6) {
analogWrite(BLUE, 225);
analogWrite(GREEN, 0);
analogWrite(RED, 0);
}

// Violet
if (mode == 7) {
analogWrite(BLUE, 225);
analogWrite(GREEN, 0);
analogWrite(RED, 100);
}

// Switch off
if (mode == 0) {
mode = 0;
}
}

legend_guyes
Автор

For everybody here saying this code did not work for them. Check your RBG LED and ensure it is a common cathode and not a common anode. I had the same issue and when I installed the correct RGB LED it worked perfectly

codymagasich
Автор

This tutorial was very helpful for me! I wasn't really understanding arduino push button stuff and this helped me a lot! Thank you!

justblboa
Автор

great job! but can you share your arduino code used for this project????

babalolamichael
Автор

This is exactly what I was looking for! Thanks 🙏

Bansheekilr
Автор

Very clear and extremely useful at this point.

Prubotics
Автор

I know you don't want to share your code, but it would help if you made the text on screen bigger, so we could follow along

MrBobWareham
Автор

This tutorial really did merged with my ideas, liked it brother.👍😁

zanejr.
Автор

Well done, clear instructions, and helpful.

Thank you.

MH_Bikes
Автор

for all who wondering that this code is not working your wrong just debug the if (mode == 0) in the end of the code and replace the zero and input 8 if (mode == 8) and it works just watch and focus to the end of the vid 5:17

MALGAPOVANRAILYR
Автор

beautiful and clear explanation, thx!

plamenyankov
Автор

Very underrated youtuber 😢
I hope you get more subs and create more videos

destinyirorere
Автор

simple, but very good! I liked your class. Thanks

wandersonsilva-fxcs
Автор

really good project but for some reason it did'nt work for me

noneofyourbusinesssokemydi
Автор

here is a simple version (works kind off the same):

#define blue 3
#define green 5
#define red 6

int mode = 0;

void setup() {
pinMode(red, OUTPUT);
pinMode(green, OUTPUT);
pinMode(blue, OUTPUT);
}

void loop() {
int bluevalue = random(1, 500);
int redvalue = random(1, 500);
int greenvalue = random(1, 500);
analogWrite(blue, bluevalue);
analogWrite(red, redvalue);
analogWrite(green, greenvalue);
delay(400);
}

//YES i wrote this

abusekak
Автор

How may I set the led to super slow changing colors such as 10 seconds delay transition colors of rgb and switch automatically to music reactive mode when there is playing music or songs on my videoke and turn back automatically to super slow changing colors of red green blue when there's no music playing or in standby mode?

michaeldeloso
Автор

Why can't we connect a single resistor to the cathode? I am going to do that...

anuragnayak
Автор

Cam someone help me with this issue I'm having. I want to put leds on a switch box for back lighting but I want the led the change color when the switch is on. Someone please help me out with this. I would highly appreciate the help..

SiNNeR
Автор

wait it keeps saying pinmode not defined or something like that?

EnderKnigh
Автор

here is code i write it

//define pins
#define BLUE 6
#define GREEN 3
#define RED 5
#define button 2

//define color mode
int mode = 0 ;

void setup() {

pinMode(RED, OUTPUT);
pinMode(GREEN, OUTPUT);
pinMode(BLUE, OUTPUT);

pinMode(button, INPUT_PULLUP);
}

void loop() {

if (digitalRead(button) == LOW){
mode = mode + 1 ;
delay(400);
}
//off
if (mode == 0){
analogWrite(BLUE, 0);
analogWrite(GREEN, 0);
analogWrite(RED, 0);
}
//White
if (mode == 1){
analogWrite(BLUE, 255);
analogWrite(GREEN, 255);
analogWrite(RED, 255);
}
//Red
if (mode ==2){
analogWrite(BLUE, 0);
analogWrite(GREEN, 0);
analogWrite(RED, 255);
}
//blue
if (mode == 3){
analogWrite(BLUE, 255);
analogWrite(GREEN, 0);
analogWrite(RED, 0);
}
//orange
if (mode == 4){
analogWrite(BLUE, 0);
analogWrite(GREEN, 75);
analogWrite(RED, 255);
}
//White
if (mode == 5){
analogWrite(BLUE, 255);
analogWrite(GREEN, 255);
analogWrite(RED, 255);
}
//Violet
//White
if (mode ==6){
analogWrite(BLUE, 255);
analogWrite(GREEN, 0);
analogWrite(RED, 100);
}
//switch off
//White
if (mode == 7){
mode = 0;
}
}

boomer