RGB LED lamp

Hello,
I'm trying to make a LED lamp consisting of a RGB LED strip.
I only want two colors : White and warm white.

I connected two pushbuttons and want some help in code.

The thing I want is:

  1. It should start with white.
  2. When I press warm white push button it should change to warm white and remain in that color unless I press white. Even if I press warm white again it should not change.
    the same goes for white.

Can anyone help please?

There are a number of considerations here. The code is easy enough.

One might ask why you did not - or do not - simply use a warm white and a cool white LED strip and a simple changeover switch? Why the two buttons and not a simple toggle?

More practically, do you understand how to connect the RGB LED strip to the Arduino? Have you already got that working? Have you mastered the PWM function, and determined what your values are for each setting?

If you have done so, please post - as is always requested in the posting instructions, the code you have used, a diagram of your circuit for us to check (including the button connections), and a picture of your setup.

Without these things, we are not about to run around and play guessing games.

Hello,
I can't use 2 strips because there is no space.

Yes I do know how to connect RGB LED to Arduino.
The RGB pins goes to the PWM pins in Arduino (3,5,6)
I have tried this with a 5mm RGB LED.

The values I have put were:
for white (255, 255, 255)
for warm white (255, 244, 229)

I plan to drive the strip using MOSFET.
Thank you for your answer.

Well, as I said before, you show your code (after reading the instructions), how you plan to connect the buttons, and a picture of your setup, and I will sort out the code for you (if no-one else gets to it first :grinning: ).

Your requirement is very easy as there is no concern about de-bouncing the buttons. You essentially want the code for an R-S flip-flop.

Hello,
Here is my diagram and code.
I know the code doesn't make sense but hope you can help with that.

Thanks!

rgb_led.ino (476 Bytes)

OK, try this code. Note how to post code:

int red = 3;
int green = 5;
int blue = 6;
int pot = 1;
int white = 2;                 // Pushbutton to ground, no resistor
int wwhite = 4;                // Pushbutton to ground, no resistor

void setup() {
  pinMode(red, OUTPUT);
  pinMode(green, OUTPUT);
  pinMode(blue, OUTPUT);
  pinMode(white, INPUT);
  pinMode(wwhite, INPUT);
  digitalWrite(white, HIGH);   // Implements INPUT_PULLUP
  digitalWrite(wwhite, HIGH);
}

void loop() {
  analogWrite(red, 225);
  analogWrite(green, 225);
  analogWrite(blue, 225);
  while (wwhite) {             // wait for warm white to be pressed.
  };
  analogWrite(red, 220);
  analogWrite(green, 223);
  analogWrite(blue, 222);
  while (white) {              // wait for white to be pressed.
  };
}

Note that your pushbuttons should be connected from the pin to ground, and no resistor is required as you use the INPUT_PULLUP function (unless you are using rather long leads, in which case you might require a resistor).

What is the "PWM/Dimmer" component shown in your diagram? This should not be needed, because the Arduino will be doing the PWM/dimming. If you have two devices attempting to control the same leds with PWM, there could be various unwanted problems with flickering and/or pulsating.

If you want to dim the light, attach a pot to an analog pin on the Arduino and write your sketch to read the pot and the switches and set the desired colour and brightness levels

You should also put 10K pullup resistors on the gates of the FETs to prevent overheating in the first couple of seconds between switching the power on and the Arduino sketch starting to run.

PaulRB:
You should also put 10K pullup resistors on the gates of the FETs to prevent overheating in the first couple of seconds between switching the power on and the Arduino sketch starting to run.

Pull-up?

PaulRB:
What is the "PWM/Dimmer" component shown in your diagram? This should not be needed, because the Arduino will be doing the PWM/dimming. If you have two devices attempting to control the same leds with PWM, there could be various unwanted problems with flickering and/or pulsating.

True enough.

PaulRB:
If you want to dim the light, attach a pot to an analog pin on the Arduino and write your sketch to read the pot and the switches and set the desired colour and brightness levels

Ah! That becomes very problematic. :astonished:

Paul__B:
Pull-up?

Or pull-down. Pull-up would cause the leds to come on instantly at full brightness for a second or two until the Arduino starts running the sketch. Pull-downs would keep them off until the sketch starts running. The important thing is not to leave them floating and potentially getting hot. Is that correct Paul?
NOTE: if pulling up, connect the resistor to 5V not 12V!

Paul__B:
Ah! That becomes very problematic. :astonished:

Why? I was thinking:

  • read the switches
  • set the max brightness for r, g, & b channels to either 255, 255, 255 or 255, 244, 229
  • read the pot
  • calculate the actual brightness for r, g & b channels between zero and the max set in the step above for that channel using map()
  • set the brightness for each channel with analogWrite()

Am I over simplifying?

We get into the problem at lower PWM levels, that the divisions that generate the RGB values start to give different proportions for the "warm white" version. An extension of the visible steps problem at low values - and low values are generally desired for dimming.

What happens when you put a value other than 255 or 0 does it give even more colors

zbot473:
What happens when you put a value other than 255 or 0 does it give even more colors

No.

Sir there's a problem I have encountered.
The pwm function seems opposite, 255 returns to OFF and 0 returns ON.
I have to write the values of RGB = 0,0,0 to get full white.
Also the pushbutton code isn't working.
Can you help please?

I tested with Arduino Uno R3 (original) and also with a clone, and a 5mm RGB common anode LED.

Thanks!

yusufes:
The pwm function seems opposite, 255 returns to OFF and 0 returns ON.
I have to write the values of RGB = 0,0,0 to get full white.
...
I tested with ... a 5mm RGB common anode LED.

When you use a common anode led, the led will light when the Arduino output is LOW. When using your strip and FETs, the leds will light when the Arduino output is HIGH. The FETs reverse the logic.

yusufes:
Also the pushbutton code isn't working.

That's not a helpful thing to write. You must describe what does happen and what you want to happen.

Do you want your LEDs to fade from one colour to the other over a second or so?