Spanish Italian
17454 Users    

Build a 2.4GHz Wireless Programmable Doorbell Chime

  Download PDF version of the Article

In just ten minutes you can easily build a 2.4GHz wireless programmable doorbell chime, using just a pair of CPUSticks, a switch, and a buzzer. Each CPUStick contains a highly-integrated microcontroller (MCU) running “StickOS BASIC”, 48 multi-function I/O pins brought out to 0.1” pads (suitable for use in a solderless breadboard), as well as a 2.4GHz ZigFlea wireless transceiver, all of which can be fully programmed using only a host computer with a terminal emulator, and high-level BASIC algorithmic statements.

Dev.Emcelettronica CPUStick - BUY IT NOW! (24/48h delivery)

“StickOS BASIC” is an entirely MCU-resident interactive programming environment, which includes an easy-to-use editor, transparent line-by-line compiler, interactive debugger, performance profiler, and flash filesystem, all controlled thru an interactive command-line user interface (see Figure 1). In StickOS, external MCU I/O pins may be mapped to BASIC “pin variables” for manipulation or examination, and internal MCU peripherals may be managed by BASIC control statements and interrupt handlers.

Hello Doorbell!

Circuit
To build the 2.4GHz wireless programmable doorbell chime, wire two CPUSticks as follows:

cpustick_doorbell-circuit

On CPUStick #1 (nodeid 1), wire CPUStick pin dtin3 to one end of the switch, and the other end of the switch to ground.

On CPUStick #2 (nodeid 2), wire CPUStick pin dtin0 to one end of the 3V buzzer, and the other end of the 3V buzzer to ground.

Assembly
You can solder male-male headers on the CPUStick I/O pins and install them in solderless breadboards, as shown below. Alternately, you can solder directly to the CPUSticks for a more permanent installation. I used CR-2 batteries for testing, though some other form of power is required for permanent installation.

cpustick-assembly

Note that the top CPUStick is nodeid 1 connected to the doorbell switch, and the bottom CPUStick is nodeid 2 connected to the doorbell buzzer. They communicate with each other via 2.4GHz ZigFlea wireless, all under BASIC program control.

Configuration
nodeid 1
To configure nodeid 1, connect it to the host computer’s USB port, allow signed drivers to install from the Internet for Windows, and connect to it via the terminal emulator as described in the StickOS User’s Guide. Then enter the following:

Welcome to StickOS for Freescale MCF52252 v1.70e!
Copyright (c) 2008-2009; all rights reserved.
http://www.cpustick.com
support@cpustick.com
(checksum 0xe62b)

> nodeid 1
> 10 dim i
> 20 dim notes[9]
> 30 dim switch as pin dtin3 for digital input debounced inverted
> 40 dim buzzer as remote on nodeid 2
> 50 rem major scale starting at a-440
> 60 data 440, 494, 554, 587, 659, 740, 831, 880, 0
> 70 for i = 0 to 8
> 80   read notes[i]
> 90 next
> 100 rem our song
> 110 label song
> 120 data 3, 0, 1, 0, 8, 2, 3, -1
> 130 rem main loop
> 140 while 1 do
> 150   rem if the switch is pressed...
> 160   if switch then
> 170     rem play the song
> 180     restore song
> 190     do
> 200       read i
> 210       rem if the song is not over...
> 220       if i!=-1 then
> 230         rem play the note on the remote cpustick
> 240         let buzzer = notes[i]
> 250         sleep 200 ms
> 260       endif
> 270     until i==-1
> 280     let buzzer = 0
> 290   endif
> 300 endwhile
> save doorbell1
> autorun on
> _

This program simply configures a variable named “switch” that is bound to the dtin3 pin, which is configured for inverted digital input. It then configures a remote variable on the other CPUStick named “buzzer”. Next, it defines the frequencies of a major scale in the “notes” array, and then finally plays the specified song (i.e., the specified sequence of notes) on the other CPUStick’s doorbell buzzer whenever the doorbell switch on this CPUStick is depressed.

nodeid 2
To configure nodeid 2, connect it to the host computer’s USB port, allow signed drivers to install from the Internet for Windows, and connect to it via the terminal emulator as described in the StickOS User’s Guide. Then enter the following:

Welcome to StickOS for Freescale MCF52252 v1.70e!
Copyright (c) 2008-2009; all rights reserved.
http://www.cpustick.com
support@cpustick.com
(checksum 0xe62b)

> nodeid 2
> 10 dim buzzer as pin dtin0 for frequency output
> save doorbell2
> autorun on
> _

This program simply configures a variable on nodeid 2 named “buzzer” that is bound to the dtin0 pin, which is configured for frequency output. The program then ends and the CPUStick simply waits for the other CPUStick (nodeid 1) to manipulate the pin variable, and hence manipulate the dtin0 pin.

Customization
The song that is played can be customized by changing the data statement at line 120 on nodeid 1; the values 0-7 correspond to the notes a-g; the value 8 is a rest.

Run
Once both CPUSticks are set to autorun, when they power on, they start running their programs immediately. Pressing the doorbell switch on CPUStick #1 will cause the song to be played on the buzzer connected to CPUStick #2.

Diagnostics
What if your program doesn’t work? What if you have a bug in your switch or buzzer circuitry? StickOS supports fully interactive control of the MCU.

You can start running the program on nodeid 1 by typing “run” and then press to stop it and you will see:

> run

STOP at line 160!

At that point you can print the current value of the switch, with:

> print switch
0

If you press the switch and print the value again, you’ll see:

> print switch
1

You can (remotely) turn on the buzzer on nodeid 2 with:

> let buzzer = 1000

You can (remotely) turn it off again with:

> let buzzer = 0

You can even continue the program from where it left off:

> cont

You can use breakpoints, assertions, watchpoints, single-stepping, execution tracing, live variable and pin examination and manipulation, and even edit-and-continue as part of the StickOS interactive debugging experience.

Dev.Emcelettronica CPUStick - BUY IT NOW! (24/48h delivery)

More Information
Full StickOS documentation and downloads for various supported MCUs can be found at: http://www.cpustick.com/index.htm

There is also a skeleton source code project with all of the StickOS initialization and pin and peripheral manipulation routines, for those wanting to port their finished BASIC programs to C.

Read also:
StickOS and CPUStick - Build a Simple Toaster Oven Temperature Profile Controller 1/2
StickOS and CPUStick - Build a Simple Toaster Oven Temperature Profile Controller 2/2

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
1 + 0 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.

Who's new

  • fernand
  • Ligrock
  • paolo_0665
  • chanuei
  • JM
  • samsilva77
  • araghube
  • stoll
  • mt
  • orionkw

Who's online

There are currently 0 users and 41 guests online.