AVR Tutorial – Experiment 2

Experiment 2

Hello LED

Objective – Hello LED – Flash LED at a rate such that the LED appears always on. Estimate the onset of the rate when the LED appears to stay on

Pre-Requisites – Arduino Nano (ATmega328P-PU), Mini USB cable, 12V DC Adapter, Software Setup (as described in introduction)

Theory – The LEDs were discussed in experiment 1, where the LED was toggled at observable rate. Flashing the LEDs at different rate could produce different effects, such as the breathing effect where the intensity of LED can be observed as increasing and then decreasing steadily. The structure of LED allows it to be controlled at very high rate. When the LED surpasses a given rate of flashing it will be observed as continuously switched ON, even when the state is being toggled. This happens because of the persistence of vision (POV), where two or more object seen by the eye will merged if the duration between these view will be less than 1/16th of a second.

The experiment can be performed on the onboard LED or any given external LED, following the same process as given in experiment 1. In the given experiment, increment the rate of flashing such that the LED stays ON. For example set the delay as 1000 mS and in each step decrease the delay by 100 mS. The rate at which we observe the LED as always ON will be noted.


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

Connections will be same as experiment 1.


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

/*Change the value of BLINK_DELAY_MS such that the LED appears always on*/
#define BLINK_DELAY_MS 10

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);