Blinking a LED is the most basic project in the Arduino. You basically make some easy connections, write the code and upload it in the Arduino. With that, you can control the blinking rate, the duration for which it was glowing and lot more. To know how to install the IDE, click here. Let’s see the further process.
Items Required
- Arduino Uno
- Connecting cable
- LED
- A resistor (220 ohm)
- Breadboard
- Jumpers
Circuit
- Connect the digital pin (say D5) to one end of the resistor .
- Then connect the other end of the resistor to the positive end of the LED (the one with the longer leg).
- Connect the negative terminal of the LED to the GND (ground) pin of the Arduino Uno.
- Connect the Arduino board to the port of your laptop via the USB cable.
The Sketch
The sketch consists of two functions, in the setup() area, you have to define which pin you will use and also it’s mode. In the loop() area, you have to write the algorithm of your blinking, it’s blinking rate etc. In this code, we will make the D5 pin high for 1 second and then we will make it low followed by delay() function. This all is set in a loop. After writing the code, you just need to upload it. Read this, if you don’t know how to upload the code. The code is written below.
const int led=5;
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(led, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
This is how the real circuit and the blinking would look like. Happy Learning!