This project demonstrates how to blink an LED connected to an Arduino board using basic C++ code.
- Arduino board (e.g., Uno, Nano)
- LED
- 220-ohm resistor
- Breadboard
- Jumper wires
- Connect the longer leg (anode) of the LED to digital pin 13 on the Arduino.
- Connect the shorter leg (cathode) of the LED to one end of the 220-ohm resistor.
- Connect the other end of the resistor to the GND (ground) pin on the Arduino.
int ledPin = 13;
: This line creates a variableledPin
to store the pin number where the LED is connected.void setup()
: Thesetup()
function is called once when the program starts. Inside this function:pinMode(ledPin, OUTPUT);
: This sets theledPin
as an output pin, meaning it will be used to send signals to control the LED.
void loop()
: Theloop()
function runs continuously aftersetup()
. Inside this function:digitalWrite(ledPin, HIGH);
: This turns the LED on by setting theledPin
toHIGH
.delay(1000);
: This pauses the program for 1000 milliseconds (1 second) while the LED remains on.digitalWrite(ledPin, LOW);
: This turns the LED off by setting theledPin
toLOW
.delay(1000);
: This pauses the program for 1000 milliseconds (1 second) while the LED remains off.
- Connect your Arduino board to your computer.
- Open the Arduino IDE.
- Copy and paste the provided code into a new sketch.
- Upload the sketch to your Arduino board.
- Watch the LED blink on and off at 1-second intervals.
This project is open-source and available under the MIT License.
Happy coding!