void loop()

{

 your code must be in between the curly brackets

}

This function will repeat forever, so the main part of your program will go in here.

For example if you write a program that makes an LED flash, the part that turns it on and off will be here.

How to write a program:

The arduino uses a language that is based on C programming. The nice thing about it is that it comes jam packed with a lot of code that works in the background, this means that the instructions that you use to write your programs are simple and easy to learn. It makes the learning curve less steep, so you will very quickly be able to write sophisticated and elegant programs.

On the next page you will find a list of common commands and an explanation of what they mean and whether or not they go in the void setup() function or in the void loop() function.

Below is a program that switches an LED on and off. Have a look at the code below and the explanations on the next page and see if you can figure out what the program does and why each line of code is necessary.

int led = 2;

void setup()

{               

  pinMode(led, OUTPUT);    

}

void loop()

{

  digitalWrite(led, HIGH);  

  delay(1000);              

  digitalWrite(led, LOW);   

  delay(1000);              

}

Why not type this program into the Arduino software and download it onto your arduino?

Then play around with it, change it, break it, fix it….understand it!