In this tutorial, I will guide you through creating your first Arduino project, which involves blinking a LED light on and off. This project is simple yet educational, especially if you are new to Arduino.
Before we begin, make sure you have an Arduino board that works at 5V I/O pins. In this tutorial, I will be using an Arduino Uno rev 3 clone board, but you can use any board that meets the requirements.
Here is a picture of the Arduino board we will be working with:
To power the board, you can use a USB-B port or a battery (preferably a 9V battery as the recommended input voltage is 7-12V). Here is a picture showing the power pins and analog I/O pins on one side of the board:
On the other side of the board, you will find the digital I/O pins:
Let’s proceed to build a simple circuit that will light up the LED. You will need a 1kΩ resistor, a yellow 5mm LED, and connect them to the +
and -
pins as usual. The +
and -
pins should be connected to the power pins on the Arduino board (which provide 5V and GND):
When you power the Arduino with a battery, you will notice that the LED turns on:
At this point, the Arduino doesn’t do anything useful except scaling the 9V input provided by the battery to 5V. Let’s make the LED blink by writing our first Arduino program.
To get started, you will need to install the Arduino IDE on your computer. Visit this link and select the version that corresponds to your operating system.
After the software is downloaded, if you are using macOS, move the Arduino
app to your Applications
folder. For installation instructions on Windows and Linux, refer to the respective guides provided on the Arduino website.
Launch the Arduino IDE, and you should see a blank program window:
As mentioned in the Introduction to the Arduino Programming Language tutorial, the setup()
function is executed once, right after the program starts. This is where we typically set up the pin modes. In our program, we will set the digital I/O pin number 13 as an output pin using the pinMode()
function:
#define LED_PIN 13
void setup() {
// Configure pin 13 as a digital output
pinMode(LED_PIN, OUTPUT);
}
Inside the loop()
function, which is executed continuously in a loop, we will write a HIGH level of voltage (5V) to the LED pin, wait for 1 second, write a LOW level of voltage (0V = ground), wait for 1 second, and then repeat this process indefinitely:
void loop() {
digitalWrite(LED_PIN, HIGH);
delay(1000);
digitalWrite(LED_PIN, LOW);
delay(1000);
}
In this program, we use the constants HIGH
and LOW
, which are available by default in Arduino. The digitalWrite()
function is used to write a HIGH or LOW value to a specific digital output pin. We pass the pin number and the voltage level as parameters. The delay()
function is used to pause the program execution for a specified number of milliseconds.
Before you can compile the program and upload it to the Arduino, make sure to save the file. You can save it anywhere you like, but for organization purposes, it is recommended to create a dedicated folder for Arduino projects.
To upload the program, click on the Upload button (the one with a right arrow) in the Arduino IDE. The program will be compiled and installed on the Arduino board. You should observe that the LED starts blinking:
If you disconnect the USB cable from the computer, the LED will turn off because the Arduino is no longer powered. However, if you connect the Arduino to a standard USB charger, the LED will continue to blink. The program we loaded on the Arduino runs independently, and the computer is no longer needed.
Now that you have successfully completed your first Arduino project, feel free to explore more advanced projects and expand your knowledge. Arduino opens up a world of possibilities for creativity and innovation in the field of electronics.
Tags: Arduino, LED, Circuit