Light Switch XBee

Table of Contents

  1. Introduction
  2. Assemble the Parts
  3. Prepare The Light Switch’s Radio
  4. Construct the Light Switch Circuit
  5. Assemble the Light Switch
  6. Prepare The Simple Receiver’s Radio
  7. Breadboard the Receiver
  8. Use it!
  9. More Info


Introduction

The Light Switch XBee is a wireless wall switch that can control lamps, fans, motors or your homemade robot. This project can serve as a model for almost any digital input device you’d like to build. You can substitute any number of digital inputs, like a pressure mat, magnetic contacts or even a soft switch made of conductive fabric in its place. If it goes on and off, now you can make it wireless!


1) Assemble the Parts


Lightswitch

  • 1 PVC Light Switch Kit (Wiremold/Legrand NM2-S or similar, available from Ace Hardware, Home Depot and many other retailers) or any single pole light switch, plastic enclosure and plastic faceplate. (Metal enclosures will significantly attenuate the radio signal, but may work for short-range solutions.)
  • Hook-up wire or jumper wire kit (AF 153, DK 923351-ND, SFE PRT-00124)
  • 1 3-volt lithium battery (CR123A is a good choice)
  • 1 battery holder (DK BH2/3A-3-ND works with CR123A)
  • 1 10K Ohm resistor (DK P10KBACT-ND, SFE COM-08374)
  • 1 XBee Series 1 802.15.4 radio, configured with version 10E8 or later (Digi: XB24- PWI-001, DK XB24-PWI-001-ND)
  • 1 XBee breakout board with 2mm female headers installed (AF 126, SFE BOB-08276 & PRT-08272)
  • XBee USB Serial adapter (XBee Explorer, Digi Evaluation board or similar) (AF 247, SFE WRL-08687)
  • USB cable for XBee adapter (AF 260 , SFE CAB-00598)
  • Wire strippers (AF 147, DK PAL70057-ND, SFE TOL-08696)
  • Soldering iron (AF 303, DK WES51-ND, RS 55027897, SFE TOL-10553)
  • Solder (AF 145, RS 64-025, SFE TOL-09163)
  • Helping hands (AF 291, DK 243-1018-ND, RS 64-079, SFE TOL-09317)

Receiver
These are the parts needed for a simple receiver setup that you can use to test output from the Light Switch XBee. It uses a basic LED, but can also control a small motor, solenoid, or any other digital output device.

    • 1 solderless breadboard (MS MKKN2, AF 64, DK 438-1045-ND, SFE PRT-09567)
    • Hook-up wire or jumper wire kit (AF 153, DK 923351-ND, SFE PRT-00124)
    • 1 3-volt lithium battery (CR123A) and…
    • 1 battery holder (DK BH2/3A-3-ND works with CR123A)

…or

  • 2 AA battery holder with connection wires (RS 270-408, SFE PRT-09547) and…
  • 2 AA batteries (alkaline or NIMH rechargeable, fully charged) (RS 23-873, SFE PRT-09100 or PRT-00335)
  • 1 5mm LED (DK 160-1707-ND, RS 276-041, SFE COM-09590)
  • 1 XBee Series 1 802.15.4 radio, configured with version 10E8 or later (Digi: XB24-AWI-001, DK XB24-AWI-001-ND)
  • 1 XBee breakout board with male headers and 2mm female headers installed (AF 126 (add SFE PRT-00116), SFE BOB-08276 & PRT-08272 & PRT-00116)
  • XBee USB Serial adapter (XBee Explorer, Digi Evaluation board or similar) (AF 247, SFE WRL-08687)
  • USB cable for XBee adapter (AF 260 , SFE CAB-00598)
  • Wire strippers (AF 147, DK PAL70057-ND, SFE TOL-08696)

2) Prepare The Light Switch’s Radio

Using a serial terminal program and AT commands (or X-CTU if you have access), configure the XBee Series 1 radio with the settings in the table below. If you're not sure how to do this, follow the steps for setting up the radio in Basic XBee 802.15.4 (Series 1) project.

Function Command Parameter
PAN ID ATID 3001 (any address from 0 to FFFE will do)
MY Address ATMY 1 (any address from 0 to FFFE will do)
Destination High ATDH 0
Destination Low ATDL 0 (or the receiving radio’s address)
Digital I/O pin 0 ATD0 3 (digital input)
Input sample rate ATIR 64 (hex 64 is 100 in decimal for milliseconds)
Samples before transmit ATIT 1 (send each sample individually)

When you’re finished, check your work by reissuing each AT command without any parameter so the radio can show you the addresses and register settings that it’s using. As a final step, use the ATWR command to write the new configuration to your radio’s firmware so it’s saved for the next power-up.

NOTE: You should get an OK response after issuing each command to set parameters, and another OK response when you write the changes to firmware. If you don’t get an OK response, most likely you took more than ten seconds to issue the command and you’ve dropped out of command mode. This can happen quite frequently when you’re starting out, but you’ll get better at it as you go along. The other common mistake is not issuing the ATWR command to save your changes, then losing your configuration when the radio is powered down.

Adding Sleep Mode
If you would like to save battery power, then the following commands can be added to the setup. This will make the radio sleep in a low power mode when it isn’t transmitting, extending the battery life by approximately 400%. You can extend the sleep period (ATSP) longer to make the battery life even greater, at the expense of responsiveness in the switch itself since no samples will be transmitted when the radio is sleeping.

Function Command Parameter
Sleep Mode ATSM 5 (cyclic sleep mode with pin wake)
Sleep Period ATSP 19 (* 10 ms = 250 ms of sleep time)
Time Before Sleep ATST 0 (20 ms of idle before sleeping begins)
Guard Time ATGT 14 (20 ms guard time for command mode)

Don’t forget to check your work, and to issue the ATWR command to write the new configuration to your radio’s firmware so it’s saved for the next power-up.

3) Construct the Light Switch Circuit


XBee Breakout Board
Your XBee radio has pins spaced 2 mm apart. This helps keep the component small, but it means you can’t use it directly on a standard 0.1″ spaced solderless breadboard. In this case we won’t be using a breadboard, however using the breakout board with the female headers is preferable to soldering directly to the XBee’s pins for several reasons. First of all, the XBee pins are very close together. Secondly, if we solder directly to the XBee it becomes very difficult to remove it from the light switch project for reprogramming or replacement. Therefore we are better off soldering to the lower-cost breakout board and plugging the XBee into its sockets.

  • Solder two strips of female 2 mm-spaced sockets onto the top side of the breakout board. (Both sides are the same electrically, so if you mess up and get it backwards all that will be off is the labeling.)
  • Test-fit the XBee into the female sockets, being careful not to bend its pins.

Soldering Tips
If you’re new to soldering that’s great! It’s very easy to learn. Check out some of the many example videos online and practice soldering a few wires together before you start on the steps below. Good solder joins are key to making this project work reliably. Use the helping hands to position and hold the wires and components in place while you solder. It’s worth some patience to get them positioned well before starting. It may be helpful to twist together two wires that go to the same connection point so that one or the other doesn’t fall out of place while you’re soldering. Make sure you heat the wires, pins and leads all at once, and only then touch the solder to the components to flow it over everything. While it’s tempting to melt solder onto the iron itself and then “paint” it on to your connections, this will typically result in poor joins that either don’t connect at all or crumble apart very easily.

XBee Connections

  • Solder a 10K ohm resistor between pin 10 (GND) of the XBee breakout board and pin 20 (AD0). It may be helpful to insulate the leads of the resistor so that it does not touch other pins by accident. Stripping a bit of insulation off one of your hookup wires and sliding it over the resistor’s leads is one way to accomplish this. (see above)
  • Use black hookup wire to connect pin 10 (GND) of the XBee to the negative terminal of your battery holder.
  • Use red hookup wire to connect pin 1 (VCC, 3.3V) of the XBee to the positive terminal of your battery holder. See below:


Light Switch Connections

  • Solder a short length of red hookup wire to the positive terminal of the battery holder.
  • Solder a short length of white (or any other color) hookup wire to pin 20 (AD0) of the XBee as shown in the photo below.
  • Strip the other end of each of these wires and connect to the screw terminals on the light switch as shown in the photo below. It doesn’t matter which wire connects to which of the two terminals on the light switch.

Note: Ignore any green (ground) terminal on the light switch. External grounding isn’t needed for low-voltage applications. If your light switch has other terminals, consult the schematic that came with it, or use continuity test mode on a multi-meter to find two terminals that connect and disconnect when the switch is thrown.

Breadboard Diagram:

Schematic:

4) Assemble the Light Switch

  • Place the light switch into its PCV plastic housing, arranging the XBee on one side and the battery holder on the other as shown above. Use the two longer screws to attach the switch to the housing.
  • Put a battery in the battery holder, being careful to use the correct orientation of positive and negative (usually indicated on both the battery and in the holder).
  • Screw on the faceplate, using the two smaller screws.

5) Prepare The Simple Receiver’s Radio

Using a serial terminal program and AT commands (or X-CTU if you have access), configure the XBee Series 1 radio with the settings below:

Function Command Parameter
PAN ID ATID 3001 (any address from 0 to FFFE will do)
MY Address ATMY 0 (any address from 0 to FFFE will do)
Destination High ATDH 0
Destination Low ATDL 0 (this is only a receiver, destination optional)
Digital I/O pin 0 ATD0 4 (digital output, low to begin with)
Input sample rate ATIA FFFF (accept I/O commands from any radio)

When you’re finished, check your work by reissuing each AT command without any parameter so the radio can show you the addresses and register settings that it’s using. As a final step, use the ATWR command to write the new configuration to your radio’s firmware so it’s saved for the next power-up.

6) Breadboard the Receiver


Power Connection to Breadboard

  • If you are using the CR123A battery holder, solder a red wire to the positive lead and a black wire to the negative lead. The 2AA battery holders usually come with wires attached, so if you have chosen that as your power supply you’re ready to go.
  • Insert the red wire coming from your battery’s positive terminal into one of the power rails on your breadboard.
  • Insert the black wire coming from your battery’s negative terminal into one of the ground rails on your breadboard.
  • Hook up power and ground across the breadboard so that the rails on both sides are live.

XBee Connection to Power

  • With the XBee mounted on its breakout board, position the breakout board in the center of your other breadboard so that the two rows of male header pins are inserted on opposite sides of the center trough.
  • Use red hookup wire to connect pin 1 (VCC) of the XBee to the 3-volt power rail.
  • Use black hookup wire to connect pin 10 (GND) of the XBee to the ground rail.

LED Output
This project uses a simple LED as output. Because the XBee inherently limits the current on its output pins, even if we don’t use a resistor the LED will not burn out. However if you feel more comfortable adding a current-limiting resistor it can go in series with either lead of the LED.

  • The LED has two leads. Connect the longer, positive lead to pin 20 (AD0) of the XBee.
  • Connect the LED’s shorter, negative lead to one of the ground rails as shown in the diagram above.

Schematic:

7) Use it!



This Light Switch example is just the beginning. You can use the same circuit and radio configuration to create a security alarm, for example, by substituting a pressure mat for the wall switch. Or invent your own switch using any two pieces of metal or conductive material. Maybe you want shoes that turn on your toaster. Or a cat door that plays “The Cat Came Back” each time Fluffy returns from an outing. Even complex sensor ideas can often be boiled down to a simple switch solution. Start making stuff!

 

8) More Info

Actuator Example

Would you like to turn on and off A/C mains powered appliances? Chapter 6 of “Building Wireless Sensor Networks” concludes with a Direct Actuation example that uses the PowerSwitchTail A/C relay shown in the photo above. You can use the Actuator Boards show in that example with the Light Switch XBee. Simply replace the Series 2 Zigbee radio discussed in the book’s example with a Series 1 XBee configured as a Simple Receiver (above). Now your light switch can switch on your lava lamp, spin your disco ball or fire up your daiquiri blender.

Tags: 802.15.4