Sunday, April 19, 2015

computer controlled rgb led with arduino uno R3


Arduino is an open source micro-controller board designed for technical as well as non technical user. School level students to the engineering students and other non technical persons and hobbyists are taking the advantage from the Arduino microcontroller. The today's educational system can be improved by this device and this is fun too. I have posted some simple tutorial about arduino microcontroller with simple projects but today i am going to post a little bit difficult project here. This projects utilizes the serial communication between arduino and computer and the arduino output
 can be controlled by computer. Lets explain slowly.




COMPONENT REQUIRED
1. arduino uno
2. computer or laptop
3. arduino ide (arduino software)
4. rgb led
5. 330 ohms resistor
6. male to male connectors
7. breadboard
CIRCUIT COMPONENT AND DIAGRAM




Connect the circuit as shown in the diagram. In this circuit, the rgb led pins are connected to digital pins 11,12,13 of arduino uno. The ground pin is connected to gnd of the arduino through a 220 or 330 ohm resistor. The circuit diagram is complete and now its turn to write code for the projects. To do this you have to use your computer or laptop and installed arduino ide software which can be easily downloadable from arduino.cc .

1. OPEN ARDUINO IDE IN YOUR COMPUTER
2. WRITE THE FOLLOWING CODE THERE
PROGRAM FOR
int red=11;
int green=12;
int blue=13;



void setup() {
// put your setup code here, to run once:
pinMode(red,OUTPUT);
pinMode(blue,OUTPUT);
pinMode(green,OUTPUT);

Serial.begin(9600);// stabilizes serial communication
Serial.println("press \n red 1 \n blue 2 \n green 3 stop others pin");

}
void loop() {
// put your main code here, to run repeatedly:
while(Serial.available()==0);
int val= Serial.read()-'0';
if(val==1)
{
digitalWrite(red,HIGH);
digitalWrite(blue,LOW);
digitalWrite(green,LOW);
Serial.println(" now glowing red");
}
else if(val==2)
{
digitalWrite(red,LOW);
digitalWrite(blue,HIGH);
digitalWrite(green,LOW);

Serial.println(" \n now glowing blue");
}
else if(val==3)
{
digitalWrite(red,LOW);
digitalWrite(blue,LOW);
digitalWrite(green,HIGH);
Serial.println(" \n now glowing green");

}
else if(val==4)
{
digitalWrite(red,HIGH);
digitalWrite(blue,HIGH);
digitalWrite(green,LOW);

Serial.println(" \n now red and blue");
}
else if(val==5)
{
digitalWrite(red,LOW);
digitalWrite(blue,HIGH);
digitalWrite(green,HIGH);
Serial.println("\n now blue and green");
}
else if(val==6)
{
digitalWrite(red,HIGH);
digitalWrite(blue,LOW);
digitalWrite(green,HIGH);
Serial.println("\n now red and green");
}
else if(val==7)
{
digitalWrite(red,HIGH);
digitalWrite(blue,HIGH);
digitalWrite(green,HIGH);
Serial.println(" \n all are glowing");
}
else
{
digitalWrite(red,LOW);
digitalWrite(blue,LOW);
digitalWrite(green,LOW);
Serial.println("\n all off");
}
Serial.flush();
}



3. Upload above program to your arduino using usb cable. Then open serial monitor in your arduino ide.




TESTING CIRCUIT

now press 1 or 2 or 3 or 4 or 5 or 6 or 7 or 8 or others key.. then see the magic.. congratulation, you have successfully controlled your rgb led using your computer..



No comments:

Post a Comment