Project1 - Dual Button Color Control System
1. What You Will Build
In this tutorial, you will learn how to build Project1 - Dual Button Color Control System using Arduino Starter Sheild Kit.
By the end of this tutorial, your project will be able to:
• Control LED 1 using Switch 1
• Control LED 2 using Switch 2
• Change RGB LED colours automatically when both switches are pressed
2. What You Will Learn
After completing this tutorial, you should understand:
How RGB LED colours mixing works
How to control multiple LEDs using digital outputs
How the code works step by step
3. Components Needed
No. | Component | Quantity |
1 | Arduino | 1 |
2 | Arduino Starter Shield Kit | 1 |
4. Software Needed
Use the tools below depending on your board.
Board | Software |
Arduino | Arduino IDE |
Libraries Needed
No library needed
5. Circuit Connection
Connect the components as shown below.
Wiring Steps
Connect Arduino shield kit to the Arduino uno board
6. Code
#define SW1 2
#define SW2 3
#define LED1 13
#define LED2 12
#define RED 9
#define GREEN 10
#define BLUE 11
void setup() {
pinMode(SW1, INPUT_PULLUP);
pinMode(SW2, INPUT_PULLUP);
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(RED, OUTPUT);
pinMode(GREEN, OUTPUT);
pinMode(BLUE, OUTPUT);
}
void loop() {
bool sw1 = !digitalRead(SW1);
bool sw2 = !digitalRead(SW2);
// Kawal LED biasa
digitalWrite(LED1, sw1);
digitalWrite(LED2, sw2);
// Jika kedua-dua switch ditekan
if (sw1 && sw2) {
setColor(1,0,0); // Merah
delay(500);
setColor(0,1,0); // Hijau
delay(500);
setColor(0,0,1); // Biru
delay(500);
setColor(1,1,0); // Kuning
delay(500);
setColor(1,0,1); // Ungu
delay(500);
setColor(0,1,1); // Cyan
delay(500);
setColor(1,1,1); // Putih
delay(500);
}
else {
// RGB OFF
setColor(0,0,0);
}
}
void setColor(bool r, bool g, bool b) {
digitalWrite(RED, r);
digitalWrite(GREEN, g);
digitalWrite(BLUE, b);
}7. Upload / Run the Project
Connect the board to your computer using USB.
Open the code in Arduino IDE.
Select the correct board.
Select the correct port.
Click Upload.
Open the Serial Monitor if needed.
8. Expected Result
When the project is working correctly:
Press Switch 1 → LED 1 turns ON.
Press Switch 2 → LED 2 turns ON.
Press both Switch 1 and Switch 2 → RGB LED changes colors automatically.
9. Troubleshooting
Problem | Possible Fix |
Board not detected | Check USB cable, driver, board, and port selection |
Code upload failed | Select the correct board and COM port |
Sensor not working | Check VCC, GND, and signal pin wiring |
Output not turning on | Check pin number and component polarity |
Wrong readings | Check sensor voltage and calibration |