Blinking an LED with an Arduino Uno is a perfect project for beginners to start with. Do you just got an Arduino uno or you're waiting to get one soon? This is a cool project you can start with, it will make you understand how the Arduino Uno can be use to control simple components like an LED based on the way you intended to control it using sets of programs.
Note: This tutorial is use to demonstrate how the Arduino can be use to control simple components with some codes. If you are getting started with Arduino programming click here to learn.
Materials.
Here are the lists of materials we're gonna use for the project.
- 2k ohms resistor.
- LED
- 9V battery
- Cables
- Bread or solderless board.
- Arduino uno.
Circuit diagram.
The Arduino is powered by a 9v battery connected to the baord via the barrel jack.
LED blinking with Arduino Code.
//*program to blink a led on and off repeatedly for one second*//
int LED = 13;
void setup() {
pinMode(LED,OUTPUT);
}
void loop() {
digitalWrite(LED,HIGH);
delay(1000);
digitalWrite(LED,LOW);
delay(1000);
}
How the blinking works.
The LED is connected to the Arduino Uno as explained earlier, the sketch above is use to control the blinking speed of the LED.
In the code above int LED = 13; means you are instructing the micro chip to represent pin 13 as LED, so we don't have to repeat 13 throughout the code.
"void setup() {
pinMode(LED,OUTPUT);
}" This line of code is use to instruct to the Arduino to set LED="pin 13" an output pin.
pinMode(LED,OUTPUT);
}" This line of code is use to instruct to the Arduino to set LED="pin 13" an output pin.
void loop() {
digitalWrite(LED,HIGH);
digitalWrite(LED,HIGH);
This line of code is use to instruct the Arduino to output 5v at LED="pin 13"
delay(1000);
The line of code is use to instruct the Arduino to keep the LED lit up for one seconds (1000).
digitalWrite(LED,LOW);
This line of code instructs the Arduino Uno to output a voltage of 0v at LED="pin 13" thus the LED doesn't light up.
delay(1000);
The line of code is use to keep the LED off for 1 second.
The Arduino will follow the instruction from the first sentence to the last then repeat from the first sentence again forever.
void loop() {}
The instructions placed inside the void loop setup is repeated from the first to last again and again.
Tags:
Arduino