How to blinking led with arduino board

Led blinking is usually first step for arduino learners. You can blinking led only a few codes. In this tutorial we will examine led properties, arduino board connection, and led blinking arduino codes.

 

LED blinking arduino circuit diagram

LED has two legs. The long one is positive and should connect to a digital pin and the short one is typically negative and must connect to GND pin on the Arduino board.

led-blinking-tutorial-led-properties
led-blinking-tutorial-led-properties

To protect the led, you need to use a resistance between the arduino gnd pin and the LED negative (short) leg. For this tutorial we use number 2 digital pin on Arduino board.

arduino-blinking-led-tutorial
arduino-blinking-led-tutorial

LED blinking arduino code example

Firstly you need to define the pin variable in which LED is connected in arduino.

You can use an integer variable. Integer variables are defined as int. You can connect  the led in 1-13 digital pins. We use number 2 arduino digital pin for this tutorial.

You must configure the selected arduino pin as an output. You can do this with pinMode() function.

The pinmode function contains two values. First values is variable name. Second values is OUTPUT or INPUT configuration and you must write these words in capital letters.

In loop function, you have turn the led on or off. You can do this with digitalWrite() function.

The digitalWrite() function contains two values. First values is variable name. Second values is HIGH or LOW configuration and you must write these words in capital letters. You must use HIGH to turn the LED on and  LOW to turn the LED off. we add  delay() function to slow down the blinking led.

The delay function works with milliseconds, so we write 1000 milliseconds for a second.

You can use delay(5000); code to delay 5 seconds.

 

Complete led blinking arduino code

 

In this tutorial we learned how to blinking LED with the Arduino board.

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *