Module 1 - LED PDF
Module 1 - LED PDF
TUTORIAL
(Interfacing Arduino Uno with
Common Electronic Components)
Project 1 – LED Flasher
You will write a program to make an LED blink.
Hardware Required
• Arduino Board
• Red LED
• 220-ohm resistor
• Jumper Wires
• Breadboard
Circuit
Code
// Project 1 – LED Flasher
void setup()
{
pinMode(ledPin, OUTPUT);
}
void loop()
{
digitalWrite(ledPin, HIGH);
delay(1000);
digitalWrite(ledPin, LOW);
delay(500);
}
Additional Task
** Try making the LED Flasher is ON for a short time but OFF for a
longer time.
Project 2 - LED & Pushbutton
Pushbuttons or switches connect two points in a circuit when you press
them. This example turns on the LED on pin 10 when you press the button.
Hardware Required
• Arduino Board
• Pushbutton
• Red LED
• 2 x 220-ohm resistor
• Jumper Wires
• Breadboard
Circuit
Code
// Project 2 - LED & Pushbutton
int buttonPin = 2;
int ledPin = 10;
int buttonState = 0;
void setup()
{
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);
}
void loop()
{
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH)
{
digitalWrite(ledPin, HIGH);
}
else
{
digitalWrite(ledPin, LOW);
}
}
Additional Task
1. Try to change the command to “when push button is press the LED
blink for 0.5 seconds in each condition.
2. Try to change when the push button is not pressed the LED lights is
ON , and when the push button is pressed, the LED lights is OFF.
Project 3 - Pulsating LED
We are now going to develop further into a more advanced method of
controlling LED’s. So far we have simply turned LED ON or OFF. How about
being able to adjust its brightness too?
Hardware Required
• Arduino Board
• Pushbutton
• Red LED
• 220-ohm resistor
• Jumper Wires
• Breadboard
Circuit
Code
// Project 3 – Pulsating LED
void setup()
{
// declare pin 9 to be an output:
pinMode(led, OUTPUT);
}
void loop()
{
analogWrite(ledPin, brightness);
delay(30);
}