WAKE UP


09. Wake up

This example of analog output uses a buzzer to generate the sound of the police siren, the morning alarm and a timer. The circuit can be managed from the Internet via alarm, stop, timer and snooze commands.

Figure 1 - wake up circuit

1. Circuit

Connect the buzzer as shown in figure 1:

  • positive PIN to the PIN d2
  • negative PIN to the PIN GND.

The long PIN is positive.

2. Sketch

Write a sketch K to define:

  • the output connection: sound::d2
  • the commands to control the buzzer: beep, alarm, snooze, stop and timer
sound :: d2   
beep = [sound=6,sound=0 ##1]   
alarm = [beep #2]   
snooze = [beep #0,alarm ##5]   
stop = [sound=0]   
timer = [alarm ##10] 

or simply load the sketch with the command

] load e09_wake_up

Figure 2 - alarm clock and timer commands

3. Try and learn

Using the sound command we will create the sound of the police siren, the morning alarm and a timer.

Try the following commands now:

  • ] sound=6

the buzzer emits an infinite sequence of beeps

  • ] sound=440

the buzzer sounds the note LA

  • ] sound=699

the buzzer sounds the note FA

  • ] police = [sound=440 #2,sound=699 #2 ##1]
  • ] police

to create the sound of the police siren

  • ] stop

to turn off the sound

  • ] beep

generates a beep burst for a second

  • ] alarm

generates the alarm clock to wake you up every morning

  • ] snooze

to continue sleeping for another 5 seconds

  • ] stop

to turn off the alarm

  • ] timer

sets a 10-second timer (wait for 10 seconds to hear the alarm)

  • ] stop

to turn off the timer.

4. Summarizing

In this lesson you learned or repeated:

  • how to use a buzzer
  • the commands: load, sound, #, ##