802.15.4 Digital Input with a Button
Table of Contents
With digital input, it doesn’t get any simpler than your basic button. Also called “momentary switches,” these components come in all shapes, sizes, and colors. They take care of the mechanical connections between a digital input and high or low voltage.
XBee radios can be configured for up to 8 digital input pins that can directly control the output pins on a second radio. In this tutorial, we’ll walk you through how to program the radio and wire up a simple button to an XBee so that you can use it to make your digital electronics project wireless.
2) Assemble the Parts
- XBee 802.15.4 Radio
- Switch – use any kind you want. We’ll be using a tactile momentary switch that sits perfectly in our breadboard.
- 10K resistor – they’re labeled with colored bands Brown, Black, Orange and then sometimes gold or silver.
- Jumper cables
- XBee Breakout Board – for your circuit.
- XBee Explorer USB – for programming your radio.
- A DC power source, 2.8 – 3.3V – We’ll be using two C batteries in a battery holder from Radio Shack.
3) Configure the Radio
If you’re not familiar with configuring radios using AT commands, review the steps in the Basic XBee 802.15.4 Chat tutorial, which walks you through configuring CoolTerm to program the radios.
- Insert the XBee into the Explorer USB and connect it to your computer.
- Launch CoolTerm and connect to the XBee.
- Here are the commands we’re going to use to configure the radio:
|Reset||ATRE||N/A (resets the radio to its factory settings)|
|PAN ID||ATID||3001 (any address from 0 to FFFE will do)|
|Destination address high||ATDH||0 (indicates a 16-bit address)|
|Destination address low||ATDL||2 (the address of the receiving radio)|
|Pin 0 I/O configuration||ATD0||3 (digital input)|
|Sample rate||ATIR||14 (20 ms, 14 in hexadecimal = 20 in decimal)|
|Pull-up resistors||ATPR||0 (disable internal pull-up resistors on all pins)|
|Write to memory||ATWR||N/A (save the settings to flash memory)|
- Here’s what your terminal session might look like. The user input is in bold:
Note: Remember to issue the ATWR command when you’re done so that the settings are saved in the radio’s flash memory. If you don’t issue this command, the radio will revert to its old settings when it loses power.
4) Wire up the Circuit
- Place the XBee adapter into the breadboard and wire up the power buses to each other.
- Connect the VCC terminal of the XBee adapter to the positive rail and the ground terminal to the negative rail.
- One side of the switch gets connected to I/O pin 0, which is physical pin 20, on the top right side of the XBee. The other side of the switch gets connected to the positive bus.
- Add a 10K resistor between the negative power bus and the side of the switch that connects to the XBee. This acts as a pull down resistor. Since digital inputs must be connected to either high or low levels, it ensures the input is connected to ground (low) when the switch is not being pushed.
- Insert the XBee into the adapter.
- And finally, connect the battery pack.
- Above is a diagram of the circuit. In the photos, we used C batteries. A pair of AA batteries, as shown in this diagram, will work fine.
5) Use it!
Now that you know how to connect a button to the digital input of an XBee radio, take a look at our output tutorials for what you can control. Just be sure that the the transmitter’s address is set as the receiver’s I/O input address setting (ATIA). The video above shows a button connected to a wireless LED.