Table of Contents

Components

This stage involves the following new components.

Setting the Base

After taking the Arduino out of the box the first thing to do is to connect it to the breadboard using wires.

First, we need to wire up the breadboard's power rails that go up each side. The power rails are designed to give easy access to 0V (also known as GND) and 5V.

Once you've done this the breadboard and Arduino should look like this.

Let there be light

Now we will power an LED

(Tip: If you want to zoom in on any of these diagrams, just click on them!)

Remember: With resistors it doesn't matter which way round you put then, but with LEDs it does. See this page for more information.

Blinkenlights

Having an LED lit is cool, but the Arduino is so much more than just a power source! Let's control the LEDs, first by blinking it on and off once per second.

You should now have a circuit that looks like this:

If you have a brand new Arduino that hasn't been used before the LED should start to blink. This is because it comes from the factory with this test program already installed.

We now write our first program to make it blink. Here's the program code:

// Any text after two forward slashes is ignored by computers
// These are called comments and are used to put notes for people inside code. 

// the setup routine runs once when you press the reset button
void setup() {                
  // initialize the digital pin 13 as an output, in has the LED connected
  pinMode(13, OUTPUT);     
}

// the loop routine runs over and over again forever:
void loop() {
  digitalWrite(13, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);               // wait for 1000 milliseconds (1 second)
  digitalWrite(13, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);               // wait for a second
}

Copy this code into your Arduino software and upload it.

If all goes well, you should see your LED start to blink! If not, ask for help :)

Here's your first challenge! Try to complete both tasks. This will help you understand the code.

challenge_yourself.jpg Easier
(1) The LED should be flashing once per 2 seconds. Can you make it flash 5 times per second?
(2) Can you make the LED flash once for 1 second, then once for 0.2 seconds, then again for 1 second and so on in a dot-dash-dot-dash way?

Saying Hello World.

You might already be thinking. How do I know what my program is doing if all the feedback I have is a blinking LED? Well there is a solution in the form of serial communication which allows your Arduino to send messages to a computer. These messages can then be shown on your screen by clicking the button at the top right of the Arduino software.

Note: when handling textual information in the Arduino programming language you need to use double quote marks. In this programming language “digitalWrite” represents text (d followed by an i, followed by a g, and so on, spelling the word digitalWrite), whereas digitalWrite (without the double quotes) is a reference to a feature of the programming language which allows you to control the voltage on various pins.

void setup() {                
  // initialize the digital pin 13 as an output, in has the LED connected
  pinMode(13, OUTPUT);     

  // initialize serial communication at a speed of 9600 bits per second:
  Serial.begin(9600);
  // Sends a line to the computer
  Serial.println("Hello World!");
}

// the loop routine runs over and over again forever:
void loop() {
  Serial.println("LED On");
  digitalWrite(13, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);               // wait for 1000 milliseconds (1 second)
  Serial.println("LED Off");
  digitalWrite(13, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);               // wait for a second
}

Once you've uploaded the program, open the Serial monitor:

You should see the Arduino say “Hello World!” followed by LED On and LED Off once a second. If you are having problems, check that the speed in the Serial Monitor is set to 9600. Otherwise, ask a helper!

So that's the end of the 1st lesson.

Once the rest of the group has got to this point there will be another short presentation on programming concepts before moving onto Tutorial 2.