Lab-Wireless

Parts

  • breadboard
  • hook up wire
  • Arduino
  • LEDs
  • 220 ohm resistors (or similar)
  • 10K ohm resistor
  • momentary switch for input
  • buzzer for output
  • XBee radio (Series 1 running 802.15.4 protocol)
  • XBee USB Serial adapter (XBee Explorer, Digi Evaluation board or similar)
  • USB cable for XBee adapter
  • wire stripper

Connect Power from Arduino to Breadboard

  1. Hook up a red wire from the 3.3V output of the Arduino to one of the power rails on the breadboard
  2. Hook up a black wire from either ground (GND) connection on the Arduino to a ground rail on the breadboard
  3. Hook up power and ground across the breadboard so that the rails on both sides are live.

Make sure you are using 3.3V power. The XBee will NOT run on 5 volts, and any more than 7 volts will permanently damage it.

XBee Breakout Board

Your XBee radio has pins spaced 2 mm apart. This helps keep the component small, but will not allow you to use it directly on a standard 0.1″ spaced solderless breadboard. To mate it with the breadboard, you need to use a “breakout board” which simply connects the XBee’s closely spaced pins to pins with the standard breadboard spacing. These simple breakout boards have no other electrical components. Another option is to use certain XBee USB-serial adaptors, such as the XBee Explorer, Adafruit XBee Adaptor or MCPros XBee Simple Board, all of which come with standard spaced holes where you can solder on male headers. In this example, we’ll just work with a basic breakout board.

  1. Solder regular 0.1″ spaced male headers onto the two center rows of holes on your basic XBee breakout board. The male headers come in long strips, and must be cut down to fit the breakout board before soldering. It helps to place the male headers into the breakout board and insert them into the breadboard, as this helps with stability while soldering.
  2. Next, flip the board over and solder two strips of female 2 mm-spaced sockets onto the opposite side of the breakout board. The female sockets are 2 sockets too long, and must be cut down to fit the breakout board before soldering.
  3. Test-fit the XBee into the female sockets, being careful not to bend its pins.

male-headers

solder-1

female-sockets

in-board

in-board2

XBee Connections

  1. With the XBee mounted on its breakout board, position the breakout board in the center of your breadboard so that the two rows of male header pins are inserted on opposite sides of the center trough.
  2. Use red hookup wire to connect pin 1 (VCC) of the XBee to 3.3 volt power.
  3. Use black hookup wire to connect pin 10 (GND) of the XBee to ground.
  4. Use yellow (or another color) hookup wire to connect pin 2 (DOUT) of the XBee to digital pin 0 (RX) on your Arduino.
  5. Finally, use blue (or another color) hookup wire to connect pin 3 (DIN) of your XBee to digital pin 1 (TX) on your Arduino.

It’s not a bad idea to use a 1µF capacitor to decouple the power supply and eliminate certain types of noise. The Arduino usually has enough decoupling on its own, however it’s a good habit and won’t do any harm. Decoupling is essential if you use a separate 3.3 V voltage regulator. Simply place the negative leg of the capacitor in ground and the positive leg into power, as near as you can to where your XBee is in the circuit.

Doorbell Introduction

Radios aren’t much fun on their own, so you’ll be working with a partner in this lab to make a simple doorbell and one with feedback. One of your boards will have the doorbell button input and the other will have a buzzer, speaker or other noisemaker to act as the doorbell output. The code for the button side will also be different from the code for the bell side.

Switch Input

  1. Pick which of your boards will be acting as the doorbell button. On that board:
  2. Attach a momentary switch between power and Arduino digital input 2. Make sure you use a 10K ohm pulldown resistor (connected to ground) that attaches to digital input 2 as well so that the pin has a reference to zero voltage when the switch is open.

buzzer0

… and Buzzer Output

  1. Your second board will be acting as the bell part of the doorbell. On the second board:
  2. Attach the red power lead of your buzzer to digital pin 5 of your Arduino board.
  3. Attach the black ground lead from your buzzer to ground.

You can also use a speaker or other sound output device, in which case employ what you already know about analog output to make the proper connections and adjust the Arduino code for that device. Remember that there’s a lot of ways to make sound, especially when you know how to work a servo, or decide to hack a toy, in which case a relay might take the place of the buzzer. Imagination counts, and will amuse your classmates.

speaker

Configure your XBees

There are many ways to configure your XBee radios from your computer. You can use the X-CTU terminal program that’s provided for free by Digi International as long as you have access to a Windows computer where you can install software. There are also a variety of serial terminal programs that can communicate with the XBee radios. Finally, there are some simplified configuration tools, such as the XBee Config Terminal we’ll be using, which allow you to interact with an XBee as long as its in the factory default setup, running at 9600 baud.

We’ll be using an XBee USB Serial adapter board, as discussed in class. There are a wide variety of these adapters but they all basically allow access from your computer’s USB port to the TTL serial protocol that your XBee employs locally for its serial conversations.

configure

  1. Label one XBee with a zero (0) and place it into the USB Serial adapter board.
  2. Plug the USB Serial adapter board into your computer.
  3. Run the XBeeConfigTerminal program.
  4. Select the appropriate serial port, which will probably have the words “usbserial” in its name.
  5. Select a PAN ID between 0×0 and 0xFFFF to define your personal area network
  6. Enter ATID followed by the PAN ID you selected into the Tx: field. For example, if you selected ox2001 as your PAN ID then you would enter ATID 2001 and press the Send button. You should receive OK as a reply.
  7. Enter ATMY followed by your my address. For the first radio this will be zero so ATMY o in the TX area and then press Send.
  8. Enter ATDL followed by your radio’s destination address. This is the address of another radio that will be receiving messages from yours. In this case we’re making a pair of radios so each one will have the other as its destination. Type ATDL 1 into the Tx: field and press Send.
  9. To save your new settings as the radio’s default, type ATWR and press Send.

You’ll set up your second radio in the same way.

  1. Label the second XBee with a one (1) and place it into the USB Serial adapter board.
  2. Plug the USB Serial adapter board into your computer.
  3. Run the XBeeConfigTerminal program.
  4. Select the appropriate serial port, which will probably have the words “usbserial” in its name.
  5. Select the same PAN ID that you entered for your first radio above.
  6. Enter ATID followed by the PAN ID you selected into the Tx: field. You should receive OK as a reply.
  7. Enter ATMY followed by your my address. For the second radio this will be one so ATMY 1 in the TX area and then press Send.
  8. Enter ATDL followed by your radio’s destination address. This radio is sending to the first one so type ATDL 0 into the Tx: field and press Send.
  9. Again, save your new settings as the radio’s default by typing ATWR and pressing Send.

Both of your radios are now configured as a pair. Sometimes when people are first starting out with XBees, it takes a few tries to get everything typed in just right to pair the radios. If they don’t work at first, don’t panic, usually it’s just because you missed a single step or made a typo. Try again.

Program the Arduino Doorbell

When uploading programs to the Arduino boards, disconnect the wiring from digital pin 0 (RX) first, then reconnect the wiring after loading.

There are two programs that run the doorbell system. One goes with the button and the other goes with the output buzzer or bell. Load this program onto your button board:


/*
* ********* Doorbell Basic BUTTON ********
* requires pre-paired XBee Radios
* and the BELL program on the receiving end
* by Rob Faludi http://faludi.com
*/

#define VERSION "1.00a0"

int BUTTON = 2;

void setup() {
pinMode(BUTTON, INPUT);
Serial.begin(9600);
}

void loop() {
// send a capital D over the serial port if the button is pressed
if (digitalRead(BUTTON) == HIGH) {
Serial.print('D');
delay(10); // prevents overwhelming the serial port
}
}

Program your second board with the bell code. This receives a signal from the button board when its switch is activated and rings the bell:

/*
* ********* Doorbell Basic BELL ********
* requires pre-paired XBee Radios
* and the BUTTON program on the sending end
* by Rob Faludi http://faludi.com
*/

#define VERSION "1.00a0"

int BELL = 5;

void setup() {
pinMode(BELL, OUTPUT);
Serial.begin(9600);
}

void loop() {
// look for a capital D over the serial port and ring the bell if found
if (Serial.available() > 0) {
if (Serial.read() == 'D'){
//ring the bell briefly
digitalWrite(BELL, HIGH);
delay(10);
digitalWrite(BELL, LOW);
}
}
}

Feedback Doorbell

The next project builds on the previous one-way signal to provide two-way feedback that the bell unit has received the doorbell button press and has rung. This would be useful so the person at the door would know they had actually rung the bell.

Feedback Light

  1. Add an LED as an output from Arduino digital pin 11 on the button board, with a 220 ohm resistor going to ground.

buzzer

Program the Arduino Feedback Doorbell

Use the following code for the button board with its new feedback light:

/*
* ********* Doorbell Feedback BUTTON ********
* requires pre-paired XBee Radios
* and the BELL program on the receiving end
* by Rob Faludi http://faludi.com
*/

#define VERSION "1.00a0"

int BUTTON = 2;
int LED = 11;

void setup() {
pinMode(BUTTON, INPUT);
pinMode(LED, OUTPUT);
Serial.begin(9600);
}

void loop() {
// send a capital D over the serial port if the button is pressed
if (digitalRead(BUTTON) == HIGH) {
Serial.print('D');
delay(10); // prevents overwhelming the serial port
}

// if a capital K is received back, light the feedback LED
if (Serial.available() > 0 ) {
if (Serial.read() == 'K') {
digitalWrite(LED, HIGH);
}
}

// when the button is released, turn off the LED
if (digitalRead(BUTTON) == LOW) {
digitalWrite(LED, LOW);
}

}

On the second bell board, use this code which accepts the incoming ring request and responds back that the bell has been rung OK.

/*
* ********* Doorbell Feedback BELL ********
* requires pre-paired XBee Radios
* and the BUTTON program on the sending end
* by Rob Faludi http://faludi.com
*/

#define VERSION "1.00a0"

int BELL = 5;

void setup() {
pinMode(BELL, OUTPUT);
Serial.begin(9600);
}

void loop() {
// look for a capital D over the serial port and ring the bell if found
if (Serial.available() > 0) {
if (Serial.read() == 'D'){
//send feedback that the message was received
Serial.print('K');
//ring the bell briefly
digitalWrite(BELL, HIGH);
delay(10);
digitalWrite(BELL, LOW);
}
}
}

EXTRA: Nap Doorbell (optional)

There are many ways to take this project one step further. For example, let’s imagine a situation where you wanted to take a nap and not be disturbed by the doorbell unless it was extremely urgent. In this case initial presses of the doorbell button might only illuminate a signal light, rather than waking you with a bell. Eventually, after a large number of presses, the system would kick over into bell mode and wake you up. The caller would initially see a red light at the button to indicate that the bell hadn’t been rung yet, then eventually after a large number of presses would see a green light to confirm that the bell had finally rung. Try creating this system or another of your choosing by extending the Feedback Doorbell system with new, useful features.