Arduino Lesson 02: Blinking a LED
Arduino Lesson 2

2. Digital Write

Blink a LED with digital write

Components Required



In this example you are learning how to turn on and off a LED or any other actuator which can be controlled by a digital output such as relay, bulb, motor.

Learning Outcomes

From this example, you’ll get an understanding about,
  • Pin Mode
  • Digital Write
  • Delay Functions


A digital output allows you to control a voltage with an electronic device. If the device instructs the output to be high, the output will produce a voltage (generally about 5 or 3.3 volts). If the device instructs the output to be low, it is connected to ground and produces no voltage.Here Magicbit is the device and output voltage is either 3.3V for HIGH and 0V for LOW.


Magicbit equipped with four onboard leds in Magicbit development board, Lets select yellow LED (which is wired to D18)




By setting output state to high of LED pin will turn on the led and by setting output state to LOW will turn of LED.


void setup(){
void loop(){


pinMode(pin, Mode): Configures the specified pin to behave either as an input or an output. Here we use pin as an output

digitalWrite(pin No, State): Write a HIGH or a LOW value to a digital pin.Pin mode must be setup for the same pin in Setup to work this function properly.

delay(ms): Pauses the program for the amount of time (in milliseconds) specified as parameter.(note 1000 milliseconds equals to one second)


Note: Write code for a knight rider pattern using on board leds of Magicbit

Related Posts
Leave a Reply

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