# Rgb led with color, master dimmer and strobe Potentiometer

Hello

I am a beginner in electronics and Arduino. is my first post here so if I make a mistake tell me to delete it.
I would like your help to make my homework for the electronics class of my school.
To say that I do not necessarily want the code for this, but a direction on how to do it.

Project:
Rgb led with color, master dimmer and strobe Potentiometer

So far I have managed to change the color of the led with three potentiometers one for each color, and display its values on a screen.

Now I would like to add two more potentiometers. A master dimmer where I will dimming the brightness of the led without changing the color. And one for the strobe, where the light will flash, when it is at zero the led will not flash and as it turns it will flash faster and faster

``````#include<LiquidCrystal.h>
LiquidCrystal lcd(13,12,8,7,4,2);

const int ledRed=11;
const int ledGreen=10;
const int ledBlue=9;

const int potRed=A0;
const int potGreen=A1;
const int potBlue=A2;

const int potDimmer=A3;
const int potStrobe=A4;

int RVal,GVal,BVal;
int DVal,SVal;

void setup() {
lcd.begin(16,2);
lcd.setCursor(0,0);
lcd.print("RGB:");
pinMode(ledRed,OUTPUT);
pinMode(ledGreen,OUTPUT);
pinMode(ledBlue,OUTPUT);
pinMode(potRed,INPUT);
pinMode(potGreen,INPUT);
pinMode(potBlue,INPUT);
pinMode(potDimmer,INPUT);
pinMode(potStrobe,INPUT);
}

void loop() {

lcd.setCursor(5,0);
lcd.print("R=");
lcd.print(RVal);
lcd.setCursor(11,0);
lcd.print("G=");
lcd.print(GVal);
lcd.setCursor(0,1);
lcd.print("B=");
lcd.print(BVal);
lcd.setCursor(6,1);
lcd.print("D=");
lcd.print(DVal);
lcd.setCursor(11,1);
lcd.print("S=");
lcd.print(SVal);

delay(50);
}
`````` A master dimmer where I will dimming the brightness of the led without changing the color.

You’ll want another colour space , like HSV, because RGB master dimming will lose colour fidelity.

TheMemberFormerlyKnownAsAWOL: You'll want another colour space , like HSV, because RGB master dimming will lose colour fidelity.

AWOL, why would this be more of a problem in RGB space than in HSV? I agree that HSV would be a better choice for this project and would require one less pot. But I would have thought the colour fidelity problem is caused by the limited pwm resolution or by integer maths, if not handled properly. Colour spaces are after all "perfect models" mathematically speaking. It's the implementation that causes colour fidelity problems, isn't it?

``````    analogWrite(ledRed,analogRead(potRed)/4);
``````

You need to fix this code before you can do any dimming or flashing. For those things to work, you need the code to do some calculations with the variables you are printing to the lcd. But the results of those calculations will be ignored by the code above. Do you see why?

PaulRB: You need to fix this code before you can do any dimming or flashing. For those things to work, you need the code to do some calculations with the variables you are printing to the lcd. But the results of those calculations will be ignored by the code above. Do you see why?

Thanks for the help the only problem I get so far is that when I turn the pot to zero on the lcd it does not give me a value of zero but something more .. I thought it was the fault of tinkercad, I have not tried it yet with real accessories .. I have ordered them and I am waiting

TheMemberFormerlyKnownAsAWOL: You'll want another colour space , like HSV, because RGB master dimming will lose colour fidelity.

thanks for the tip! The idea for the project is to work like dmx lights, where they use rgb color space. the way you say I would save a pot, but I would like if you really can stay in it

PaulRB: Do you see why?

filippos93: the only problem I get so far is

So the answer to my question is: no, you do not see why. It is important to know that it is ok to say you do not understand. When this happens, ask for clarification.

The problem will not be apparent now. When you try to add code for dimming or flashing, perhaps then you will understand.

filippos93: when I turn the pot to zero on the lcd it does not give me a value of zero but something more

I am surprised that you cannot get zero with a simulator. But with a real pot, you will probably not get zero, not reliably. There is always some noise, some random fluctuations when reading an analog value. You will need to set a threshold, below which there will be no flashing.

PaulRB: So the answer to my question is: no, you do not see why. It is important to know that it is ok to say you do not understand. When this happens, ask for clarification.

Yes you are right! the answer is no, I can not see why .. but I would like to know And correct it

You need to perform some calculations in the code, to come up with some modified red, green and blue values, according to the dimming and flashing pots. But those lines of code I indicated will not use those modified values, they will only use the values from the red, green and blue pots. Do you see now?

In return, I will ask you about something I did not understand:

filippos93: the way you say I would save a pot, but I would like if you really can stay in it

Do you want to save a pot, or not?

If you want to understand hsv and rgb colour spaces better, here is an article to read. It will explain why most (all?) colour lights use the rgb colour space, but how hsv is a more natural way for humans to think about and adjust or mix colours.

PaulRB:
You need to perform some calculations in the code, to come up with some modified red, green and blue values, according to the dimming and flashing pots. But those lines of code I indicated will not use those modified values, they will only use the values from the red, green and blue pots. Do you see now?

I’m not sure I understood … what I think is that I have to save the values from the rgb pots and with some calculations add them to the values of the master pot, and after this result to give to the led pins

PaulRB:
In return, I will ask you about something I did not understand:Do you want to save a pot, or not?

no i would not like to save it … my job is to use a lighting console in concerts. so I learned the philosophy of rgb. from this comes the idea of the project … but thank you for the article, I will read it

Sorry for my bad English I’m from Greece

While it clearly does not matter with a simulator, if you ever construct a real project with the "1602" LCD display, do not connect the contrast potentiometer which controls pin 3 of the LCD, to 5 V (Vcc). This is a design mistake propagated persistently through the "hobby" forums. :astonished:

Connecting the potentiometer correctly as a variable resistor - only two connections between pin 3 and ground - makes contrast setting much easier and for what it is worth, saves current.

filippos93: ... and after this result to give to the led pins

Yes, and that is the part that will not work until you change those 3 lines of code. Those 3 lines read the r, g, b pots a second time and use those values.

Paul__B:
Connecting the potentiometer correctly as a variable resistor - only two connections between pin 3 and ground - makes contrast setting much easier and for what it is worth, saves current.

thanks a lot for the advice !
I will try it as soon as the screen I ordered arrives. I would like you to tell me if you can, the connection is the same on the pins on a 20x4 screen. and if I can put a resistor instead of a potentiometer and it always has the “contrast” I want without changing it?

filippos93: I would like you to tell me if you can, the connection is the same on the pins on a 20x4 screen. and if I can put a resistor instead of a potentiometer and it always has the "contrast" I want without changing it?

A 2004 display uses the same HD44780 chip so will require the same contrast circuit.

The contrast is quite sensitive to voltage, so there is no fixed resistor value that is required; that is why a potentiometer/ variable resistor is used. In general, with a supply voltage not exceeding 5 V, connecting "Vo" - pin 3 - directly to ground will usually give a legible but not optimal display and the desired resistance value will be somewhere in the order of 100 to 500 Ohms. :grinning:

Paul__B:
The contrast is quite sensitive to voltage, so there is no fixed resistor value that is required; that is why a potentiometer/ variable resistor is used.

If I measure the ohm of the potentiometer where I will have the “contrast” I want, and put a resistor of the same value in its place would it work properly?
or would it be necessary for best results?

PaulRB: Yes, and that is the part that will not work until you change those 3 lines of code. Those 3 lines read the r, g, b pots a second time and use those values.

I will try to change it according to what you say and I will upload the results. Thank you very much

filippos93: If I measure the ohm of the potentiometer where I will have the "contrast" I want, and put a resistor of the same value in its place would it work properly? or would it be necessary for best results?

That will be fine for a given assembly of parts as long as the supply voltage is not changed. :grinning:

PaulRB:
Those 3 lines read the r, g, b pots a second time and use those values.

I made the changes to the code and it looks like the dimmer master is working. but not so good because you need to convert the values from 1023 to 255. the same goes for the values displayed on the screen. but i do not know exactly where i need to do the conversion in the code

``````#include<LiquidCrystal.h>
LiquidCrystal lcd(13,12,8,7,4,2);

//Led Pins
const int ledRed = 11;
const int ledGreen = 10;
const int ledBlue = 9;
//RGB Pot Pins
const int potRed = A0;
const int potGreen = A1;
const int potBlue = A2;
//Dimmer And Strobe Pot Pins
const int potDimmer = A3;
const int potStrobe=A4;

void setup()
{
lcd.begin(16,2);
lcd.setCursor(0,0);
lcd.print("RGB:");

pinMode(ledRed, OUTPUT);
pinMode(ledGreen, OUTPUT);
pinMode(ledBlue, OUTPUT);

pinMode(potRed,INPUT);
pinMode(potGreen,INPUT);
pinMode(potBlue,INPUT);

pinMode(potDimmer,INPUT);
pinMode(potStrobe,INPUT);
}

void loop()
{
int redPotValue = 0;
int greenPotValue = 0;
int bluePotValue = 0;

int redLedValue = 0;
int greenLedValue = 0;
int blueLedValue = 0;

//Red
redLedValue = (redPotValue * dimmerPotValue) / 255;
analogWrite(ledRed, redLedValue);
//Green
greenLedValue = (greenPotValue * dimmerPotValue) / 255;
analogWrite(ledGreen, greenLedValue);
//Blue
blueLedValue = (bluePotValue * dimmerPotValue) / 255;
analogWrite(ledBlue, blueLedValue);

//LCD
lcd.setCursor(5,0);
lcd.print("R=");
lcd.print(redPotValue);
lcd.setCursor(11,0);
lcd.print("G=");
lcd.print(greenPotValue);
lcd.setCursor(0,1);
lcd.print("B=");
lcd.print(bluePotValue);
lcd.setCursor(6,1);
lcd.print("D=");
lcd.print(dimmerPotValue);
lcd.setCursor(11,1);
lcd.print("S=");
lcd.print(strobePotValue);

delay(50);
}
``````

but i do not know exactly where i need to do the conversion in the code

The way it was done in the code you posted previously should work ok.

PaulRB:
The way it was done in the code you posted previously should work ok.

Thank you very much for your help. now the dimmer works perfectly. I tried it in real form and it’s ok.
Now I will try to fix the potentiometer of the strobe.
I would like some help here too if you want.
I should add this in the same way or he wants a command if? ``````#include<LiquidCrystal.h>
LiquidCrystal lcd(13,12,8,7,4,2);

//Led Pins
const int ledRed = 11;
const int ledGreen = 10;
const int ledBlue = 9;
//RGB Pot Pins
const int potRed = A0;
const int potGreen = A1;
const int potBlue = A2;
//Dimmer And Strobe Pot Pins
const int potDimmer = A3;
const int potStrobe=A4;

void setup()
{
lcd.begin(20,4);
lcd.setCursor(4,0);
lcd.print("5Ch RGB Led:");

pinMode(ledRed, OUTPUT);
pinMode(ledGreen, OUTPUT);
pinMode(ledBlue, OUTPUT);

pinMode(potRed,INPUT);
pinMode(potGreen,INPUT);
pinMode(potBlue,INPUT);

pinMode(potDimmer,INPUT);
pinMode(potStrobe,INPUT);
}

void loop()
{
int redPotValue = 0;
int greenPotValue = 0;
int bluePotValue = 0;

int redLedValue = 0;
int greenLedValue = 0;
int blueLedValue = 0;

//Red
redLedValue = (redPotValue * dimmerPotValue) / 255;
analogWrite(ledRed, redLedValue);
//Green
greenLedValue = (greenPotValue * dimmerPotValue) / 255;
analogWrite(ledGreen, greenLedValue);
//Blue
blueLedValue = (bluePotValue * dimmerPotValue) / 255;
analogWrite(ledBlue, blueLedValue);

//LCD
lcd.setCursor(0,1);
lcd.print("Red  =");
lcd.print(redPotValue);
lcd.setCursor(0,2);
lcd.print("Green=");
lcd.print(greenPotValue);
lcd.setCursor(0,3);
lcd.print("Blue =");
lcd.print(bluePotValue);
lcd.setCursor(10,1);
lcd.print("Dimmer=");
lcd.print(dimmerPotValue);
lcd.setCursor(10,2);
lcd.print("Strobe=");
lcd.print(strobePotValue);

delay(50);
}
``````
{"ft_lang_label":"__label__en","ft_lang_prob":0.60848814,"math_prob":0.864897,"size":1956,"snap":"2021-21-2021-25","text_gpt3_token_len":580,"char_repetition_ratio":0.1664959,"word_repetition_ratio":0.0,"special_character_ratio":0.26329243,"punctuation_ratio":0.23542601,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9530884,"pos_list":[0,1,2,3,4,5,6,7,8],"im_url_duplicate_count":[null,null,null,null,null,null,null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-05-17T23:02:59Z\",\"WARC-Record-ID\":\"<urn:uuid:19ea67fd-a14c-49de-b2c1-f0a122c5d8f8>\",\"Content-Length\":\"72376\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:d44d7659-aca8-4edc-b260-e0e5f7d10be3>\",\"WARC-Concurrent-To\":\"<urn:uuid:eb1a7fd7-d02d-4f17-8fec-e3d2f37d4699>\",\"WARC-IP-Address\":\"184.104.202.141\",\"WARC-Target-URI\":\"https://forum.arduino.cc/t/rgb-led-with-color-master-dimmer-and-strobe-potentiometer/693895\",\"WARC-Payload-Digest\":\"sha1:QYBM4S5HWE5O3OMCTW6ESHLM5YIELDIF\",\"WARC-Block-Digest\":\"sha1:ZBPGCMORNU7HJB3P6BUGAMURFIDXYRPG\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-21/CC-MAIN-2021-21_segments_1620243991870.70_warc_CC-MAIN-20210517211550-20210518001550-00164.warc.gz\"}"}