Do anyone like lamps that change color with magic? then this project for RGB LED Color Control Circuit with LDR and Arduino makes its real.
Using RGB LED and three LDR light sensors, we can create a smart lamp that mix colors based on light around it.
Just a simple circuit and with some code, we can get endless color fun; also this circuit is perfect for beginners and hobby makers.
Arduino Code:
int redPin = 9;
int greenPin = 10;
int bluePin = 11;
int ldrR = A0;
int ldrG = A1;
int ldrB = A2;
void setup() {
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
}
void loop() {
int valR = analogRead(ldrR);
int valG = analogRead(ldrG);
int valB = analogRead(ldrB);
int pwmR = map(valR, 0, 1023, 0, 255);
int pwmG = map(valG, 0, 1023, 0, 255);
int pwmB = map(valB, 0, 1023, 0, 255);
analogWrite(redPin, pwmR);
analogWrite(greenPin, pwmG);
analogWrite(bluePin, pwmB);
delay(50);
}Coding Explanation:
- Red, green, blue pins set as output.
- It reads analog from three LDR.
- Map analog value to PWM range 0 to 255.
- Write PWM to RGB LED pins.
- LED glow as per light falling on LDR.
- Color mix automatically.
Circuit Working:

Parts List:
| Components | Quantity |
|---|---|
| Resistors | |
| 220Ω 1/4 watt | 3 |
| 1k 1/4 watt | 3 |
| Semiconductors | |
| Arduino UNO | 1 |
| LDR | 3 |
| RGB LED (Red, Green and Blue) | 1 |
This is simple Arduino color mixing lamp circuit, which can make room corner look nice; lamp change color when light change in room, and also it work automatic and switch color by light condition.
LDR resistance is low when light fall and LDR resistance is high when its dark.
Then Arduino read voltage at analog pins A0, A1 and A2 and Arduino change PWM output at pins 9 ,10 and 11 and after that PWM control LED brightness.
Red, Green, Blue brightness mix to make different colors, so color of lamp change with light on LDR.
How to Build:
To build a RGB LED Color Control Circuit with LDR and Arduino follow the below steps for connections:
- First, Arduino pin 9 connect to Red pin of RGB LED through resistor R1.
- Next, Arduino pin 10 connect to Green pin of RGB LED through R2.
- After that, Arduino pin 11 connect to Blue pin of RGB LED through R3.
- Then, common cathode RGB LED ground pin go to Arduino GND.
- Now LDR1 connect with resistor R4 and pin A0 of Arduino, LDR2 connect with resistor R5 and pin A1 of Arduino and LDR3 connect with resistor R6 and pin A2 of Arduino
- Also, all LDR other side go to 5V and resistors go to ground.
Conclusion:
To conclude, this RGB LED Color Control Circuit with LDR and Arduino is very simple and very fun project, as RGB LED change color with light sensor.
Furthermore, it is good to learn Arduino, PWM, LDR and RGB mix and we can also use this circuit for smart lamp or room decoration.
Leave a Reply