Shiv G
Published © GPL3+

RGB LED Controller

This project encompasses the control of an RGB LED module using three potentiometers, each one representing red, green, or blue light.

BeginnerFull instructions provided1 hour306
RGB LED Controller

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Breadboard (generic)
Breadboard (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1
RGB LED module
×1
Rotary potentiometer (generic)
Rotary potentiometer (generic)
×3

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

RGB LED Controller Circuit Diagram

Circuit diagram for RGB LED Controller.

Code

RGB LED Controller Code

Arduino
Code for RGB LED Controller.
/*
CREATED BY SHIV GARG
8/28/2023
*/

//declaring pins for RGB LED module
int LED_pin_red = 11;
int LED_pin_green = 10;
int LED_pin_blue = 9;

//declaring pins for each potentiometer
int pot_pin_red = A0;
int pot_pin_green = A1;
int pot_pin_blue = A2;

//declaring variables used to store the values read from the potentiometers
int readValue_red;
int readValue_green;
int readValue_blue;

//declaring variables used to store the values to be sent to the RGB LED module
int writeValue_red; 
int writeValue_green;
int writeValue_blue;

void setup(){
  //setting up potentiometers as input
  pinMode(pot_pin_red, INPUT);
  pinMode(pot_pin_green, INPUT);
  pinMode(pot_pin_blue, INPUT);
  
  //setting up RGB LED pins as output
  pinMode(LED_pin_red, OUTPUT);
  pinMode(LED_pin_blue, OUTPUT);
  pinMode(LED_pin_green, OUTPUT);
}

void loop()   {
  //reading voltage from each potentiometer
  readValue_red = analogRead(pot_pin_red);
  readValue_green = analogRead(pot_pin_green);
  readValue_blue = analogRead(pot_pin_blue);
  
  //calculating the value to write (set) for each color of RGB LED module based on potentiometer value
  writeValue_red = (255.0 / 1023.0) * readValue_red;
  writeValue_green = (255.0 / 1023.0) * readValue_green;
  writeValue_blue = (255.0 / 1023.0) * readValue_blue;
  
  //writing calculated value to set the brightness of each LED
  analogWrite(LED_pin_red, writeValue_red);
  analogWrite(LED_pin_green, writeValue_green);
  analogWrite(LED_pin_blue, writeValue_blue);
}

RGB LED Controller Code

Code for RGB LED Controller.

Credits

Shiv G
1 project • 0 followers

Comments