Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
35 views

Module 1 - LED PDF

This document provides tutorials for three Arduino projects: 1) An LED flasher circuit that blinks an LED connected to pin 10. The code makes the LED turn on for 1 second and off for 0.5 seconds. 2) A circuit with a push button that turns on an LED connected to pin 10 when the button is pressed. 3) A pulsating LED circuit that fades the brightness of an LED on pin 10 up and down using analogWrite to produce a fading effect.

Uploaded by

Mohd Hakim
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views

Module 1 - LED PDF

This document provides tutorials for three Arduino projects: 1) An LED flasher circuit that blinks an LED connected to pin 10. The code makes the LED turn on for 1 second and off for 0.5 seconds. 2) A circuit with a push button that turns on an LED connected to pin 10 when the button is pressed. 3) A pulsating LED circuit that fades the brightness of an LED on pin 10 up and down using analogWrite to produce a fading effect.

Uploaded by

Mohd Hakim
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

ARDUINO UNO

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

int ledPin = 10;

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

void loop()
{
digitalWrite(ledPin, HIGH);

delay(1000);

digitalWrite(ledPin, LOW);

delay(500);
}

Additional Task

** Change delay(500) to delay(100) and observe what happens.

** 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

int ledPin = 10;


int brightness = 0;
int fadeAmount = 5;

void setup()
{
// declare pin 9 to be an output:
pinMode(led, OUTPUT);
}

void loop()
{
analogWrite(ledPin, brightness);

brightness = brightness + fadeAmount;

if (brightness == 0 || brightness == 255)


{
fadeAmount = -fadeAmount ;
}

delay(30);
}

You might also like