ALARM CLOCK


02. Alarm clock

This example of digital output uses a buzzer to generate the alarm sound of a clock. It can be managed from the Internet via alarmOn and alarmOff commands.

Figure 1 - alarm clock 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: buz::d2
  • the commands to control the buzzer: beep, alarmOn, alarmOff
buz :: d2
beep = [buz=!buz # @8]  
alarmOn = [beep #3]
alarmOff = [beep #0,buz=0]

or simply load the sketch with the command

] load e02_buzzer

3. Try and learn

Try the following commands now:

  • ] beep

the buzzer emits 4 beeps ('buz=!buz # @8' switches buz 8 times every tenth of a second)

  • ] alarmOn

the buzzer emits 4 beeps every 3 seconds

  • ] ??
--- Periodic commands
beep #3

shows the periodic commands running

  • ] alarmOff

the buzzer does not emit any beeps

  • ] ??
null

the periodic command beep #3 was deleted

  • ] alarmOn ##30

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

4. Summarizing

In this lesson you learned or repeated:

  • how to use a buzzer
  • the commands: load, ??