matejadjukic03MakerRobotics
Published © GPL3+

Potentiometer with RGB LED

This uses potentiometers to control a RGB LED.

BeginnerShowcase (no instructions)1 hour12,689
Potentiometer with RGB LED

Things used in this project

Hardware components

RGB Diffused Common Cathode
RGB Diffused Common Cathode
×1
Rotary potentiometer (generic)
Rotary potentiometer (generic)
×3
Jumper wires (generic)
Jumper wires (generic)
×1
Arduino UNO
Arduino UNO
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Code

arduino code

Arduino
RGB
int R = A3; //pin for red LED
int G = A4; //pin for green LED
int B = A5; //pin for blue LED

int potenciometar1= A2; //pin for first potentiometer 
int potenciometar2= A1; //pin for second potentiometer 
int potenciometar3= A0; //pin for third potentiometer 

void setup()
{
  pinMode(R, OUTPUT);
  pinMode(G, OUTPUT);
  pinMode(B, OUTPUT);
  pinMode(potenciometar1, INPUT);
  pinMode(potenciometar2, INPUT);
  pinMode(potenciometar3, INPUT);  
}

void loop(){
  int x=analogRead(potenciometar1);
  int y=analogRead(potenciometar2);
  int z=analogRead(potenciometar3);
  if(x<10 && y<10 && z<10)
       BOJA(0,0,0);
  else if(x>200 && y<10 && z<10)
       BOJA(255,0,0);
  else if(x<10 && y>200 && z<10)
       BOJA(0,255,0);
  else if(x<10 && y<10 && z>200)
       BOJA(0,0,255);
  else if(x>200 && y>200 && z<10)
       BOJA(255,255,0);
  else if(x>200 && y<10 && z>200)
       BOJA(255,0,255);
  else if(x<10 && y>200 && z>200)
       BOJA(0,255,255);
  else if(x>200 && y>200 && z<200)
       BOJA(255,255,255);
}
/*
*   function BOJA(color)
*/
void BOJA(int R_RED, int G_GREEN, int B_BLUE)
{
  analogWrite(R, R_RED);
  analogWrite(G, G_GREEN);
  analogWrite(B, B_BLUE);
}

arduino code

Arduino
RGB
int R = A3; //pin for red LED
int G = A4; //pin for green LED
int B = A5; //pin for blue LED

int potenciometar1= A2; //pin for first potentiometer 
int potenciometar2= A1; //pin for second potentiometer 
int potenciometar3= A0; //pin for third potentiometer 

void setup()
{
  pinMode(R, OUTPUT);
  pinMode(G, OUTPUT);
  pinMode(B, OUTPUT);
  pinMode(potenciometar1, INPUT);
  pinMode(potenciometar2, INPUT);
  pinMode(potenciometar3, INPUT);  
}

void loop(){
  int x=analogRead(potenciometar1);
  int y=analogRead(potenciometar2);
  int z=analogRead(potenciometar3);
  if(x<10 && y<10 && z<10)
       BOJA(0,0,0);
  else if(x>200 && y<10 && z<10)
       BOJA(255,0,0);
  else if(x<10 && y>200 && z<10)
       BOJA(0,255,0);
  else if(x<10 && y<10 && z>200)
       BOJA(0,0,255);
  else if(x>200 && y>200 && z<10)
       BOJA(255,255,0);
  else if(x>200 && y<10 && z>200)
       BOJA(255,0,255);
  else if(x<10 && y>200 && z>200)
       BOJA(0,255,255);
  else if(x>200 && y>200 && z<200)
       BOJA(255,255,255);
}
/*
*   function BOJA(color)
*/
void BOJA(int R_RED, int G_GREEN, int B_BLUE)
{
  analogWrite(R, R_RED);
  analogWrite(G, G_GREEN);
  analogWrite(B, B_BLUE);
}

Credits

matejadjukic03

matejadjukic03

1 project • 3 followers
I just make something
MakerRobotics

MakerRobotics

6 projects • 133 followers

Comments