Interfacing a Single LED with Arduino Board
In this project, we will demonstrate how to interface a single LED (Light Emitting Diode) with an Arduino board. The Arduino board will be programmed to control the LED and make it blink at a specific rate.
Hardware Required:
- Arduino board (e.g., Arduino Uno)
- LED module
- Resistor (220-470 ohms)
- Jumper wires
Circuit Diagram: Connect the components as follows:
Connections:
Arduino Uno | Led Module |
5v | Vcc(5v) |
Digital pin7 | Led pin 1 |
Code: Below is the Arduino code to control the LED:
//Developed by www.projectkitsandparts.com Pune.
// Define the pin connected to the LED
const int ledPin = 7;
void setup() {
// Set the LED pin as an output
pinMode(ledPin, OUTPUT);
}
void loop() {
// Turn the LED on
digitalWrite(ledPin, HIGH);
// Wait for 1 second
delay(1000);
// Turn the LED off
digitalWrite(ledPin, LOW);
// Wait for 1 second
delay(1000);
}
Code Explanation:
- The ledPin variable is declared and set to 13, which corresponds to the pin connected to the LED.
- In the setup() function, the ledPin is set as an output using the pinMode() function.
- The loop() function is where the LED control happens.
- The LED is turned on by setting the ledPin to HIGH using digitalWrite().
- The program waits for 1 second using delay(1000).
- The LED is turned off by setting the ledPin to LOW.
- Another 1-second delay is added.
- The loop repeats, toggling the LED on and off continuously.
Code Manual:
- Connect the Arduino board to your computer via USB.
- Open the Arduino IDE (Integrated Development Environment) on your computer.
- Create a new sketch and copy-paste the code provided into the IDE.
- Make sure the correct Arduino board and port are selected under the “Tools” menu.
- Click the “Upload” button to compile and upload the code to the Arduino board.
- You should see the LED blinking at a 1-second interval.
Note: If you connected the LED to a different pin, make sure to update the ledPin variable in the code accordingly.
You have successfully interfaced a single LED with an Arduino board.
Project Module: