01: Blinking LED

Posted on January 27, 2014 by Nick Cousins

Intro:

This is one of the simplest things you can do with an Arduino. We are simply setting pin 13 as an output and toggling the light on and off with software.

 

Materials Needed:

  • 1 Arduino. For these tutorials we will be using the Uno Rev3 Model, feel free to use whatever Arduino you have

Arduino

  • 1 Usb Cable (A to B connection)

usbAtoB

In this project we will get acquainted with the Arduino software platform. We will focus on turning the on-board LED On/Off using a loop in the program.

LED Circled

Procedure:

Hints:

-Save your  sketch in a folder as soon as you open it.

-Make sure that the programming platform recognizes what device your using.

Tools>Board>ArduinoUno

BoardSelect1. Open the Arduino software. The window that pops up is your “sketch”. By default the sketch is titled as the date and revision a,b,c etc. Save your file as whatever you want and save it to your desktop.

Sketch Main

2. Click File>Examples>01.Basics>Blink. A window will pop up preloaded with code to make an LED Blink

BLINKCODE

Uploaded code

 

3. Verify your Code. In the top left corner of the window there is a check mark, this is the verify button. When you click this button the code get compiled and essentially checked for errors. When the program is done compiling your code, it will say “Done Compiling”If there are errors in your code they will pop up in the bottom section of the window. (1 bracket missing can cause multiple errors)

Zoom In on Buttons

Compiling

DoneCompiling

4. Upload code to the board. Now that the code is compiled it is ready to be downloaded to the Arduino. Note: Your code is automatically compiled before being downloaded to the Arduino. Once the sketch is done uploading to the Arduino the bottom left of the screen will say Done Downloading.

5. Observe results

LED1

LED2

Analyzing the Code:

1. Here we are initializing our variable led, as well as setting led to be associated with pin 13.

Initializecode

2. Void Setup is Run one time at the beginning of each program. Generally this space is used for initializing variables. Here we use pinMode to set pin 13 as an output

VoidSetup

3. Void Loop runs forever until you tell the program to stop. We use digitalWrite to set led or pin13 High (5v). We then delay the system for 1 second. We use digitalWrite again to set pin 13 low (0v or GND). Delay the system again for one second and then the loop repeats.

LoopCode

 

Be the first to leave a comment

Leave a Reply