LED Lab details

Objective:  make one LED blink on and off


 

Parts List

  Qty
LED (any color) 1
Resistor: 330ohm 1
Wire (red) 1
Wire (black) 1
Wire (Any color) 1
Arduino Uno* 1
Breadboard* 1
USB cable* 1

* you will need these parts for all labs in this website


 

Parts Set Up

(This is listed in two ways.  Instructional is for people to read what to do and follow.  Graphic is to follow a picture.  You may use whatever helps you the most!)

Instructional Parts Set-Up

(These are written instructions on how to hook up each part in the lab and serves as an alternative to the diagram below)

(This requires you to have a breadboard where you can see the numbers on each row and letters on each column)

**do NOT power up or plug in your Arduino while you are inserting parts!

Part Connection 1 Connection 2
LED F9 (longer wire/anode) F10
Resistor J10 any -ve column hole on the right
Wire (any color) J9 Arduino Digital Pin 13
Wire (black) any breadboard -ve column hole Arduino GND (any)
Wire (red) [OPTIONAL] any breadboard +ve column hole Arduino 5V

Visual Parts Set-Up

(This will show you the set-up with labelled pictures)

NOTE:  The red wire from 5V to the red column is OPTIONAL!  It does not do anything for this lab and is there for future experiments when you will add things.

Leaving it out does not affect anything in this lab!

 

**You could put the LED on columns F, G, H, I or J and it would not make a difference because the power flows along Row 9 for all these pins

**Example: You can put the LED on H9 and H10 with the longer anode lead on H9 and it would still work!


Lab 1 Code

Without Comments

int ledPin = 13; 

void setup() 

pinMode(ledPin, OUTPUT); 
}

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

With Comments

Line

Code

Comments

1 int ledPin = 13;                                                                   this line creates an integer (a whole, positive or negative number) called "ledPin" and making it equal to 13.  Remember int = integer.
2 void setup() this declares the setup() function to define what pins on our Arduino will do.    It is a void type function which means it's job is not to talk to any other part of the code.
3 { this bracket shows us the start of the setup function
4 pinMode(ledPin, OUTPUT); pinMode allows us to define if a pin is an input or output.  In this case ledPin is an output.  And ledPin equals 13 from line 1.  So pin 13 is an OUTPUT.
5 } this bracket shows us where the end of the setup function is
6 void loop() this declares a function which will loop forever.   It is a void type function which means it's job is not to talk to any other part of the code.
7 { this bracket shows the start of the loop function.
8 digitalWrite(ledPin, HIGH); digitalWrite turns on power to a specific pin (0-13) at a specific value (1 to 255).  In this case we are powering ledPin or pin 13 at a value of "HIGH".  HIGH = 255 (maximum).
9 delay(1000); delay tells Arduino to wait a number of milliseconds before going to the next instruction.  In this case, it is waiting 1 second or 1000 milliseconds.  Without this delay, the Arduino would run the next line of code instantaneously!
10 digitalWite(ledPin, LOW); this digitalWrite is setting the power of ledPin (pin 13) to LOW or 0.
11 delay(1000); this tells the Arduino to wait one second before looping to the top of the function.  After 1 second the program will go to line 8 and start again.
12 }  this bracket ends or closes the void loop function.

Lessons Learned:

Setting A Variable For A Pin

The void setup() function

The void loop() function

Further Lessons:

LED brightness control

Fading LED