Thursday, April 19, 2012

Serial Leds using arduino

In this post we will see how we can use arduino to make a set of leds glow in a serial fashion that is one after the other.

We will use

  • 4 leds
  • 1 push button
  • 1 1kohm resistor(Value picked randomly)
  • Arduino uno board.

Connect the anodes of the 4 leds to 4 digital I/O pins on the board say pin numbers 2,3,4 and 5.

Connect the one side of the push button to digital I/O pin 7 .

Connect the other side of the switch to ground through the 1K resistor.

Connect the cathodes of all the leds also the the ground, you can add a 220 ohm resistor while connecting to the ground.

The bread board and the schema connections are shown in the figures below.

In the program :

Pins 2,3,4, and 5 will be set as outputs

Pin 7 will be set as input.

The push button is used to control the order in which the leds glow i.e. 1,2,3,4 or 4,3,2,1.

We write two functions,direction1 and direction2, to light up the leds. One for each direction/order.

In both the functions we start by writing a HIGH to the first pin, pin 2 or pin 5, and wait for one second before writing a low.

Next we do the same to the pin next to it i.e. pin 3 or 4 .

We repeat the steps for all the four pins and again start from the first one.

In the loop, we keep checking for the input from push button.

On receiving a HIGH from the push button, the HIGH is noted by the chaging the value of variable alt.

Using the value of alt we change the direction of leds by calling the relevant function, i.e. if alt his HIGH led would glow in one direction else in the other direction.


Load the above program into arduino and connect the power. We should see the leds lighting up one after the other, to change the direction press and hold the push button atleast for 5 seconds as the control comes back to the loop only after finshing the function it is executing.

No comments:

Post a Comment

Follow by Email