AVR Tutorial – Experiment 1

Experiment 1

Flash led at observable rate

Objective – To control and blink a LED at an observable rate.

Pre-Requisites – AVR Mot, Mini USB cable, 12V DC Adapter, Software Setup (as described in introduction)

Theory– LEDs are most readily available electronics components. These are used as indicators, decoration pieces and in lighting systems at different places. All these example include controlling the LEDs at different rate or fashion. A wide variety of LEDs are available based upon the package, size and color. LED is an example of special type of diode. Controlling a LED involves providing suitable turn on voltage (Vf) across the terminals. The Turn ON voltage is decided by the type of color emitted by the LED. It is also required to use a series resistor with LED so as to control the current (If) through the LED. The symbol and image of a LED is provided in figure 1. The table below mentions the voltage and current required for a certain color, for high power LEDs the current requirements may vary.

Figure1 – LED symbol
LED Turn ON voltage and Optimum current
Color Turn ON voltage (V) Optimum current (mA)
Red 1.8 20
Green 3.5 20
Blue 3.6 20
White 4 20

Steps for controlling a LED

The experiment involves controlling the on-board LED available on the Arduino Nano board, using the similar steps external LEDs can also be controlled. The peripheral board MV1 consists of 3 RGB LEDs which can be controlled. The setup for controlling any of the given LED involves connecting a digital output pin to the given color.


Schematic :- To keep this experiment for hello-world of the AVR Experiment simplest in nature, we will use on-board led of Arduino nano on motherboard. In diagram shown below its P13 Led,

Connections :-
Nano <–> MV1
D13 (DDRB5) <–> LED (Red or Green or Blue)


#include <avr/io.h>
#include <util/delay.h>

#define BLINK_DELAY_MS 100

int main (void)
    /* NANO pin 13 (DDB5), set pin 5 of PORTB for output*/
    DDRB |= _BV(DDB5);

    while(1) {
        /* NANO pin 13 (DDB5), set pin 5 high to turn led on */
        PORTB |= _BV(PORTB5);

        /* NANO pin 13 (DDB5), set pin 5 low to turn led off */
        PORTB &= ~_BV(PORTB5);