Arduino blinking LEDs

This project series is a means by which I am testing out the various ways of blogging similar projects easily.  So they are not designed to be instructional as such, more a testbed.  Having said that, if they are useful, feel free to use them and have fun!

Blinking LEDS

What the Project Does:

  • We are going to make 5 LEDs turn on and off, one after the other.

What are we Learning?

  • How to write a simple Arduino sketch, with comments
  • How to allocate input/output pins and set them high or low.
  • How to connect LEDs correctly to the Arduino board.

Sketch

Here’s my sketch, which I have also used to record the algorithm.

—————————————————————————————————————————————————————————–
/*
Project 01

Title:   LED Wave
Author:  Mike Isted
Date:    16 June 2014

Description: We are going to connect 5 LEDs to the Arduino and make them flah in turn, making a kind of wave.

Algorithm:

1. Turn on LED 1
2. Wait 0.5 s
3. Turn off LED 1
4. Turn on LED 2
5. Wait 0.5 s
6. Turn off LED 2
7. Do same for LED’s 3,4 and 5.  Then repeat from LED1.
8. Repeat forever.

*/

void setup()
{
pinMode(2, OUTPUT);  //Define required pins as outputs.
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
}

void loop()
{
digitalWrite(2, HIGH);  // Turn on LED1 connected to pin 2
delay(500);             // Wait 500milliseconds (1/2s)
digitalWrite(2, LOW);   // Turn off LED
digitalWrite(3, HIGH);
delay(500);
digitalWrite(3, LOW);
digitalWrite(4, HIGH);
delay(500);
digitalWrite(4, LOW);
digitalWrite(5, HIGH);
delay(500);
digitalWrite(5, LOW);
digitalWrite(6, HIGH);
delay(500);
digitalWrite(6, LOW);

// The process will now repeat because this is an endless loop.
}

—————————————————————————————————————————————————————————–

I’m using the Sparkfun Inventor’s Kit to build many of these projects.  The kit uses a breadboard to allow circuits to be built just by pushing components and wires together.  It also contains alot of fun sensors to experiment with!

Image

So here is the circuit made up:

Image

What did I Learn?

  • Make sure you know which COM port the Arduino is attached to;
  • Make sure the connections are correct across the breadboard – I missed a couple becuase they are small;
  • Make the the resistors are the correct size (330 Ohms).  I accidentally used two 10K resistors at first, which meant that two LEDs didn’t light because the current was too small through them.
Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s