Self Timer and Musical Notes using the Arduino - Penn Engineering - DOC - DOC by decree


									                                     UNIVERSITY OF PENNSYLVANIA
                               DEPARTMENT OF ELECTRICAL ENGINEERING
                                  ESE UNDERGRADUATE LABORATORY
                               ESE 205: Electrical Circuits and Systems I Laboratory

                          Self-timer and Musical Notes using the Arduino Board
     1. To use the Arduino Board as a self-timer.
           a. The LCD display interfaced to the Arduino board should display the countdown
           b. The buzzer should go off when the timer countdown reaches zero.
     2. To play musical notes using the buzzer interfaced with the Arduino board.
     3. Extra Credit: Use the self timer mode to play musical notes.

Parts Required
     1.   Arduino Board
     2.   USB Cable
     3.   Sound Buzzer (CX-0905)
     4.   16X2 LCD Display
     5.   Wires

a. Build the sound buzzer circuit as shown in Figure 1

                                           Figure 1: Sound Buzzer Circuit

                                            Figure 2: Arduino Board

D:\Docstoc\Working\pdf\b4676ca3-6120-4e0c-98f7-0b7faf322e4f.doc           Page 1 of 6
b. Compile and download the following working code to the Arduino Boardusing Arduino IDE

#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

int runTimer = 1; // true condition for timer

int serialData = 0; // false condition for serial communication

int speakerPin = 8;

int data = 0; // default condition

void setup() {

    pinMode(speakerPin, OUTPUT);

    // set up the LCD's number of rows and columns:

    lcd.begin(16, 2);


void loop() {

    // To execute timer only once

    if(runTimer == 1){

    // Print a message to the LCD.


    lcd.print("Timer: ");

    //Start timer



    runTimer = 0;



    // Sound Buzzer
    for(int duration = 0; duration < 100; duration ++){

        digitalWrite(speakerPin, HIGH);
D:\Docstoc\Working\pdf\b4676ca3-6120-4e0c-98f7-0b7faf322e4f.doc    Page 2 of 6

        digitalWrite(speakerPin, LOW);






void timer(){

    // For loop to run the COUNT-DOWN in Seconds

        for(int timer = 10; timer > 0; --timer){

        // Set the Curosr to the space after the display "TIMER: "

        if(timer >= 10)







        // Display the COUNT-DOWN Seconds





        // Bring the Cursor to the initial position





D:\Docstoc\Working\pdf\b4676ca3-6120-4e0c-98f7-0b7faf322e4f.doc      Page 3 of 6
c. Timer Display
In order to display the timer you will have to wire the 16x2 LCD display (Figure 3) to 6 Digital
Output pins of the Arduino board.
Wire the pins according to the following assignments:

  LCD         1         2        3         4      5         6     7 8 9 10 11 12 13 14 15                16

        GND +5V GND 12 GND 11 -                                     -   -   -   5      4      3   2   +5V GND

                                       Figure 3: 16x2 Liquid Crystal Display

d. Self-Timer and Sound Buzzer
Press the RESET Button of the Arduino board, the timer will countdown from 10 seconds, as
programmed. Once the timer countdown reaches 0s, the buzzer will go on and the LCD display
will blink “Buzzer!”
The program is reset every time you press the RESET Button of the Arduino board and the timer
countdown begins again.
e. Questions
   i.     How will you make the timer countdown from 100 seconds?
  ii.     How will you make the Buzzer buzz only for a fixed amount of time after the timer
          countdown reaches 0s?

Demo the answers to the above questions to your TA and get it verified.

D:\Docstoc\Working\pdf\b4676ca3-6120-4e0c-98f7-0b7faf322e4f.doc                 Page 4 of 6
                 Figure 4: Timer Countdown Display of Selftimer using Arduino Board

                         Figure 5: Buzzer Display of Selftimer using Arduino Board

D:\Docstoc\Working\pdf\b4676ca3-6120-4e0c-98f7-0b7faf322e4f.doc     Page 5 of 6
f. Play Melody
Use the sound buzzer (CX-0905) to produce musical notes. Refer to the following links

Musical Note Frequencies from
Note: there are 5 columns in the matrix – these refer to difference octaves. For the purposes of
this assignment, choose your favorite octave (preferably one near the middle) and go with it.
(ignore sharps (#) and just go with plain A B C, etc)

Music Theory & Note Reading from
Note: we will assume a whole note is 1 second long

Program the Arduino board using the code available from the following link:
Note: Arduino is open source. The Arduino website provides links to various other interesting

g. Extra Credit

   i.     Program the Arduino to play three different musical notes. Each musical note gets 5

  ii.     Program the Arduino to count down from 20s and play a musical note of your choice for
          two cycles. (5 points)

D:\Docstoc\Working\pdf\b4676ca3-6120-4e0c-98f7-0b7faf322e4f.doc   Page 6 of 6

To top