Monday, 4 May 2015

Hello World, Lets get started with a Flashing LED

Lets get cracking with the first project.

This one is nice and simple, this program will make the inbuilt LED, shared on pin 13, flash on and off every second until you turn off the Arduino.

You can also find this starter project elsewhere on the Internet it might be called the "Arduino Hello World" or "Blink".


*You will need*

For this project you will need;
  1. Arduino UNO or NANO, 
  2. Your computer
  3. A compatible USB cable for your Arduino
  4. Arduino IDE software installed.
That's it, really simple no need for anything fancy!

*The set up*

None at all plug your Arduino in to the USB port on your computer.

*The code*

Copy the code below directly in the IDE removing or overriding the text already there. If you wish you can type it letter by letter if it helps you learn.

void setup() {
  pinMode(13, OUTPUT);
}

void loop() {
  digitalWrite(13, HIGH);
  delay(1000);
  digitalWrite(13, LOW);
  delay(1000);
}


*The theory behind the code* 



RED:
  1. Setting what is in the bracket (13)  as an "OUTPUT"
  2. Tells the Arduino that you are configuring a pin "pinMode" on that is the first part of the bracket, in this case its setting pin 13 as a output.
  3. This line is a command for the Arduino to turn on pin 13, "digitalWrite" in human means; "digital output needed - "digital", set it now "Write", on pin 13 with variable "HIGH" or on"
  4. All delays are timed on milliseconds so 1000 equals one second.
  5. It is the same as line 3 but this time set the pin "LOW" or off
  6. Another delay of a second.
ORANGE:
 
     7. Everything in the "setup" loop will run once. This is there all the setting up for Arduino
     8. This loop repeats and the running program code until you power it off


* Further experiments*

When you are feeling more confidant try changing the speed that the LED flashes!

No comments:

Post a Comment