Arduino project 2

8 green lights

The 8 lights can be programmed to turn on and off

Project 2 for the arduino board is a series of 8 flashing lights, that can be programmed to turn on and off in different sequences.  A program is available to produce three different sequences, and I was able to add my own function fairly easily to add another sequence.  While I’m not fluent in the language by any means, the code was simple enough, and an array meant it was easy to cycle through the lights.  The setup itself was straightforward, although I did clip the wires on the resistors this time so they fitted more neatly.  The colour of the wires used doesn’t matter at this stage, although I suspect it would be easier to use colour coding on more complicated projects.

int ledPins[] = {2,3,4,5,6,7,8,9}; //this produces an array of ledPins - arrays 
                                   //start from 0, so ledPins[0] is the first
                                   //and ledPins[7] is the last light.

This code sets up the LED pins so each can be referred to by its index in the array.


void setup(){
    for(int i = 0; i < 8; i++){ //this is a loop and will repeat eight times
    pinMode(ledPins[i],OUTPUT); //we use this to set each LED pin to output

This is the setup function, that sets each of the connected pins on the arduino in turn to output mode.


void oneAfterAnotherLoop(){
  int delayTime = 100; //the time (in milliseconds) to pause between LEDs
  for(int i = 0; i < 8; i++){
    digitalWrite(ledPins[i], HIGH); //Turns on LED #i each time this runs i
    delay(delayTime); //delay so you can see effect then increase i and loop 

This is one of the functions that can be called in the loop() method.

I copied the structure of this function to write my own to turn the lights off in turn.  There were a few syntax errors (the beloved brackets and semi-colons!) but on the whole it was straightforward.

So I was left with a feeling of achievement, that was soon overwhelmed by a feeling that there’s still so much I can’t do.  However, I remind myself that people are using this quite confidently in a short amount of time, and of course if I don’t try I will never get anywhere.  I can at least see now how I could build simple flashing light sequences.

What would be interesting would be to get a large array of LEDs set up and write functions to draw different things with them.  This, of course, is how things like moving display signs are programmed – the end user will just type in the text they want, and the program will know how to display that text correctly, either still or moving.  So that’s something to head towards maybe.  An 8×8 bi-colour LED matrix is easily available from the same place I got the starter kit, at £3, and could be used as the basis for a project.  What I’m not sure about is how many pins it connects to.  It does cycle through each column of lights in turn, rather than controlling all 64 independently, which would be rather unwieldy.

I assume the limit for the arduino is the number of pins available to connect to – my uno has 14 digital input/output pins, 6 of which can be used as variable outputs (PWM) and 6 analogue inputs.  The arduino mega provides 54 digital I/O pins (14 provide PWM) and 16 analogue input.  Amazingly, I now understand what that all means, which is far more than I knew before I started, so I must be learning something!

Basically, the digital input/output can be used to turn something on or off (output) or receive an on or off signal (input).  Using one as PWM output means that the output load can be varied, rather than on/off, so can be used for dimming a light, for example.  The analogue input can be used to receive signals from sensors, which tend to be analogue (varying) rather than digital (on/off).


About emmyleigh
Writer/editor/proofreader who loves technology

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: