10% Off For Your First Order, Code:Elephant10



Arduino Project: Choosing Your Favorite Color

Posted by Fiona Su on

thumb

Introduction:
RGB LED products contain red, blue and green LED's. We like diffused RGB LEDs because their color mix inside instead of appearing as 3 distinct LEDs. Brightness of each color changes with driving voltage.
In this project, we will map analog value of joystick module at X, Y axis and potentiometer into PWM value to control LED voltage, therefore, RGB LED displaying different color.
Hardware Required:

  • Arduino Board *1
  • USB Cable *1
  • LED - RGB *1
  • 220Ω Resistor *3
  • Potentiometer*1
  • Joystick Module*1
  • Breadboard *1
  • Breadboard Jumper Wires
  • Male to Female Dupont Lines

Connection for REV4:

thumb

Connection for Arduino Mega 2560 R3:

thumb

Sample Code :

int redpin = 11; //select the pin for the red LED
int greenpin =10;// select the pin for the green LED
int bluepin =9; // select the pin for the blue LED
int value1;
int value2;
int value3;

void setup() {
  pinMode(redpin, OUTPUT);
  pinMode(bluepin, OUTPUT);
  pinMode(greenpin, OUTPUT);
  Serial.begin(9600);
}

void loop() 
{
value1=map( analogRead(0),0,1023,0,255);
value2=map( analogRead(1),0,1023,0,255);
value3=map( analogRead(2),0,1023,0,255);
analogWrite(11, value1);
Serial.print("value1= ");
Serial.println(value1);
delay(100); 
analogWrite(10, value2);
Serial.print("value2= ");
Serial.println(value2);
delay(100); 
analogWrite(9, value3);
Serial.print("value3= ");
Serial.println(value3);
delay(100); 
}

Result :
After connection and uploading codes, open serial monitor, rotate the potentiometer, rock the joystick; then, the color of RGB LED changes with value1, value2, value3.

thumb 

 

0 comments

Leave a comment

Please note, comments must be approved before they are published