Lesson 1: Blinking an LED with Arduino
Lesson 1: Blinking an LED with Arduino
Lesson: Blinking an LED with Arduino
Objective: At the end of this lesson, you will be able to make an LED blink using an Arduino board.
Materials Required:
- Arduino board (e.g., Arduino Uno)
- LED (any color)
- 220-ohm resistor
- Jumper wires
Circuit Connections:
- Connect the longer leg (anode) of the LED to digital pin 13 on the Arduino board.
- Connect the shorter leg (cathode) of the LED to the 220-ohm resistor.
- Connect the other end of the resistor to the ground (GND) pin on the Arduino board.
Arduino Code:
void setup() {
pinMode(13, OUTPUT); // Set digital pin 13 as output
}
void loop() {
digitalWrite(13, HIGH); // Turn on the LED
delay(1000); // Wait for 1 second
digitalWrite(13, LOW); // Turn off the LED
delay(1000); // Wait for 1 second
}
Use code with caution. Learn more
Experiment Steps:
- Set up the circuit connections as described above.
- Connect the Arduino board to your computer using a USB cable.
- Open the Arduino IDE software and create a new sketch.
- Copy and paste the provided code into the Arduino IDE.
- Click the "Upload" button to upload the code to the Arduino board.
- Observe the LED blinking on and off at a one-second interval.
- Experiment with modifying the delay values to change the blinking speed.
Explanation:
The Arduino code above uses the pinMode()
function to set digital pin 13 as an output. The digitalWrite()
function is then used to turn the LED on and off by setting the pin to either HIGH or LOW. The delay()
function is used to pause the program for a specified number of milliseconds.
When the program is first run, the LED will turn on. After one second, the LED will turn off. This process will continue indefinitely.
You can experiment with modifying the delay values to change the blinking speed. For example, if you change the first delay value from 1000 to 500, the LED will blink twice as fast.
Challenge: Can you modify the code to make the LED blink in a different pattern? For example, can you make the LED blink three times in a row, pause for two seconds, and then blink three times again?
Here is the link for the testing and Simulating the Project
Comments
Post a Comment