Home » DIY LED Projects » Blinking 3 LEDs (R,G,B) Sequentially Using Arduino Circuit # Blinking 3 LEDs (R,G,B) Sequentially Using Arduino Circuit

The post explains how to run or blink three LEDs in sequence using Arduino. The post was written and submitted by: Jack Franko

`PROGRAM`
`/* make RGB LEDs to blink in series one by one at intervalof 1000MS */ `
`int R = 12;int G = 11;int B = 10;`
`void setup(){  pinMode(R,OUTPUT);  pinMode(G,OUTPUT);  pinMode(B,OUTPUT);`
`}`
`void loop(){  digitalWrite(R,HIGH);  delay (1000);  digitalWrite(R,LOW);  delay (1000);  digitalWrite(G,HIGH);  delay (1000);  digitalWrite(G,LOW);  delay (1000);  digitalWrite(B,HIGH);  delay (1000);  digitalWrite(B,LOW);  delay (1000);`
`}`

## DESCRIPTION

Today, We are  going
to learn to turn on and off  3 LEDs (RED, GREEN, BLUE) one by one at the interval of
1000MS that is one second.
int R = 12;int G = 11;int B = 10;

as we are aware of integer statement we had learned before ,
today we will use integer R,G & B which will be set  on arduino pin no 12, 11 and 10 respectively.
We are using R,G and B for led colors  to set on and off it confidentially to make less complicated and easy to understand what we are doing.
After setting all integers as shown in program above, we will set the main program part which is void setup stated as below

`void setup(){  pinMode(R,OUTPUT);  pinMode(G,OUTPUT);  pinMode(B,OUTPUT);`

here we are stating the pine mode as output with previously set integer ie. R for pin no 12, G for pin no 11 & B for pin no 10.  After stating arduino pin with pinmode  as output with integer tis time to set our loop for all pins to work with. Here 2nd main function is void loop as stated below.

`void loop(){  digitalWrite(R,HIGH);  delay (1000);  digitalWrite(R,LOW);  delay (1000);  digitalWrite(G,HIGH);  delay (1000);  digitalWrite(G,LOW);  delay (1000);  digitalWrite(B,HIGH);  delay (1000);  digitalWrite(B,LOW);  delay (1000);`

Here in statement of loop we are telling arduino to work with pin no 12 which is stated as R in integer and output in void setup. We will tell arduino to set pin no 12 at position “high” which means “ON” and wait for one second which 1000MS in arithmetical language with the help of function “delay” . script stated below will set led to on position and it will wait for 1 second but Arduino will not understand that what to do after waiting for 1 second, this will leads to stay led in on position for long.

`digitalWrite(R,HIGH);  delay (1000);`

so after  one second we must tell arduino to set pin no” 12” ie” R” to position” low”  which is “OFF”.

` digitalWrite(R,LOW);`

the statement stated above will set the led off . If we dint comment to wait for 1 second Arduino will continue to read the loop and turn the LED  to “ON” position frequently .so at this stage we have to comment and state the delay function to tell Arduino that after pin no 12 in “ OFF” wait for 1 second which 1000MS.

`delay (1000);`

this is a complete loop for pin no 12 which we had stated for RED LED. This will result to put ON the led and wait for 1 second and OFF the LED and wait for 1 Second. After this we have to set the same loop for GREEN and BLUE LED which is as follows.

`digitalWrite(G,HIGH);  delay (1000);  digitalWrite(G,LOW);  delay (1000);  digitalWrite(B,HIGH);  delay (1000);  digitalWrite(B,LOW);  delay (1000);`

this program will set three LEDs R, G & B to turn “ON” and “OFF” respectively for long time. Her you can program more then 3 LEDs also to turn on and off as you wish. This tutorials are for Newbees to understand the program and to play with Arduino.

SHARING IS CARING! 