Arduino RGB Led Control With POTENTIOMETERS

Hello world! Today i made a Arduino RGB Led Control project which is fun for kids to learn Electronics and how to control a RGB led. We are using a Solderless breadboard!
The complete Fritzing file + PCB Files & Fritzing file are included below as downloads.
PCB Files.zip
RGB led Control with POTENTIOMETERS.fzz

PCB files.
With the PCB files you can make your own Printed Circuit Board for your Arduino RGB Led Control.!
You can send those files to a company or individual who produces PCB’s, you can order them through fritzing to.
Another way to make your own PCB’s is etching HOW TO ETCH? <-click here to find out how. Schematic:
Arduino RGB Led Control
Simply wire everything like the schematic shows, upload the code and it should work!

Parts list:
arduino nano, (Arduino Uno will do to! or others.)
3 Potentiometers
3 x 1k Resistor
RGB Led Common Cathode, Or Common Anode. You can use the KY-016 RGB Led Module to
Breadboard
Jumper wires set MM

Common Anode & Common Cathode RGB leds explanation.
Check if you are using a Common Anode or Common Cathode RGB Led
If you led does not light up when connected to GND, Try connecting it to 5v.
Add common anode to 5v and Common Cathode to GND.
The longest pin on the RGB Led is the Cathode or Anode pin.
If it does not work on GND it is a Anode.
If it does not work on 5v it is a Cathode.

Good luck building your Arduino RGB Led Control!

Code:

/*
Author: Danny van den Brande, Arduinosensors.nl. BlueCore Tech.
NOTE:There is a difference in RGB Leds, Common Anode and Common Cathode
Add common anode to 5v and Common Cathode to GND.
The longest pin on the RGB Led is the Cathode or Anode pin.
If it does not work on 5v it is a Anode.
If it does not work on GND it is a Cathode.
 */
 
int redPin = 9; //Pin for the red RGB led pin
int greenPin = 10; //Pin for the green RGB led pin
int bluePin = 11; //Pin for the blue RGB led pin
 
int potPin_red = A2;  //declare pin for the potentiometer for the red LED
int potPin_green = A1;  //declare pin for the potentiometer for the green LED
int potPin_blue = A0;  //declare pin for the potentiometer for the blue LED
 
int readValue_red; //declare variable to store the read value from the potentiometer which controls the red LED
int readValue_green; //declare variable to store the read value from the potentiometer which controls the green LED
int readValue_blue; //declare variable to store the read value from the potentiometer which controls the blue LED
 
int writeValue_red; //declare variable to send to the red LED
int writeValue_green; //declare variable to send to the green LED
int writeValue_blue; //declare variable to send to the blue LED
 
void setup() {
  pinMode(potPin_red, INPUT); //set potentiometer for red LED as input
  pinMode(potPin_green, INPUT); //set potentiometer for green LED as input
  pinMode(potPin_blue, INPUT); //set potentiometer for blue LED as input
  
  pinMode(redPin,OUTPUT); //set pin for red LED as output
  pinMode(bluePin,OUTPUT); //set pin for green LED as output
  pinMode(greenPin, OUTPUT); //set pin for blue LED as output
}
 
void loop() {
  readValue_red = analogRead(potPin_red); //Read voltage from potentiometer to control red LED
  readValue_green = analogRead(potPin_green); //Read voltage from potentiometer to control green LED
  readValue_blue = analogRead(potPin_blue); //Read voltage from potentiometer to control blue LED
  
  writeValue_red = (255./1023.)*readValue_red; //Calculate the value to write on the red LED (add point to change to float point)
  writeValue_green = (255./1023.)*readValue_green; //Calculate the value to write on the green LED
  writeValue_blue = (255./1023.)*readValue_blue; ///Calculate the value to write on the blue LED
  
  analogWrite(redPin,writeValue_red); //write value to set the brightness of the red LED
  analogWrite(greenPin,writeValue_green); //write value to set the brightness of the green LED
  analogWrite(bluePin,writeValue_blue); //write value to set the brightness of the blue LED
}
Danny van den Brande

http://www.arduinosensors.nl

Programmer, Game Designer, 3D Designer, Web Designer, Graphic Designer. Jup this website looks crappy.. :) But enjoy the projects! Everything you need is here.

Leave a Reply

Your email address will not be published. Required fields are marked *