Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

Romantic Lighting Sensor > Prepare the Base Station

Prepare the Base Station

Your base station radio will use a breadboard connected to an Arduino board.

Connect power from Arduino to breadboard

  1. Hook up a red wire from the 3.3 V 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.

Warning

Make sure you are using 3.3 V power.

Coordinator XBee connection to Arduino

  1. With the coordinator XBee mounted on its breakout board, position the breakout board in the center of one of your breadboards 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 (TX/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 (RX/DIN) of your XBee to digital pin 1 (TX) on your Arduino.

Light output

  1. Attach the positive (longer) lead of an LED to Arduino digital pin 11.

  2. Attach the shorter ground lead from your LED to ground.

  1. If you prefer to use another output, like an audio buzzer or pager motor, you can hook it up in the same way. Perhaps your romance chops are best demonstrated by a puff of scented air freshener. Then again, maybe a monkey playing the drums is more your style. The key to romance is being yourself, so don’t hesitate to get creative!

Figure 4-8 shows the layout of the board, and Figure 4-9 shows the schematic.

Romantic lighting sensor BASE breadboard configuration

Figure 4-8. Romantic lighting sensor BASE breadboard configuration

Program the romantic lighting sensor base station

The romantic lighting sensor base station uses the following Arduino program. Upload it to your Arduino board and you’re ready to test the mood:

Warning

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

/*
 * *********ROMANTIC LIGHTING SENSOR ********
 * detects whether your lighting is
 * setting the right mood
 * USES PREVIOUSLY PAIRED XBEE ZB RADIOS
 * by Rob Faludi http://faludi.com
 */

/*
*** CONFIGURATION ***

 SENDER: (REMOTE SENSOR RADIO)
 ATID3456 (PAN ID)
 ATDH -> set to SH of partner radio
 ATDL  -> set to SL of partner radio
 ATJV1 -> rejoin with coordinator on startup
 ATD02  pin 0 in analog in mode
 ATIR64 sample rate 100 millisecs (hex 64)


 * THE LOCAL RADIO _MUST_ BE IN API MODE *

 RECEIVER: (LOCAL RADIO)
 ATID3456 (PAN ID)
 ATDH -> set to SH of partner radio
 ATDL  -> set to SL of partner radio

 */

#define VERSION "1.02"

int LED = 11;
int debugLED = 13;
int analogValue = 0;


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


void loop() {
  // make sure everything we need is in the buffer
  if (Serial.available() >= 21) {
    // look for the start byte
    if (Serial.read() == 0x7E) {
      //blink debug LED to indicate when data is received
      digitalWrite(debugLED, HIGH);
      delay(10);
      digitalWrite(debugLED, LOW);
      // read the variables that we're not using out of the buffer
      for (int i = 0; i<18; i++) {
        byte discard = Serial.read();
      }
      int analogHigh = Serial.read();
      int analogLow = Serial.read();
      analogValue =  analogLow + (analogHigh * 256);
    }
  }

  /*
   * The values in this section will probably
   * need to be adjusted according to your
   * photoresistor, ambient lighting, and tastes.
   * For example, if you find that the darkness
   * threshold is too dim, change the 350 value
   * to a larger number.
   */

  // darkness is too creepy for romance
  if (analogValue > 0 && analogValue <= 350) {
    digitalWrite(LED, LOW);
  }
  // medium light is the perfect mood for romance
  if (analogValue > 350 && analogValue <= 750) {
    digitalWrite(LED, HIGH);
  }
  // bright light kills the romantic mood
  if (analogValue > 750 && analogValue <= 1023) {
    digitalWrite(LED, LOW);
  }

}
Romantic lighting sensor BASE schematic

Figure 4-9. Romantic lighting sensor BASE schematic

Troubleshooting

If things don’t work at first, here are some steps to take to try to figure out what’s wrong:

  1. Check all your electrical connections to make sure there are no loose wires and that all the components are connected properly.

  2. Check the coordinator configuration in X-CTU again, including that the correct modem type (XB24-ZB) and function set (ZigBee Coordinator API) have been selected. Also check that the PAN ID, destination high, and destination low are configured as you expect. Remember the destination is the other radio.

  3. Check the router configuration in X-CTU to confirm that the correct modem type (XB24-ZB) and function set (ZigBee Router AT) have been selected. Also check that the PAN ID, destination high, and destination low are configured as you expect, and that ATJV, ATD0, and ATIR have been configured as described above.

  4. Make sure that the Arduino is programmed with the correct code for this project (the basic version above and the feedback version below have different code and must be matched to the correct board setup and radio settings).

  5. The debug LED on the Arduino board (pin 13) will flash if you are receiving data. If this light is flashing but your output light doesn’t change, try adjusting the sensor threshold values in the Arduino code.

  6. An LED placed from the ASSOC pin of the XBee (physical pin 15) to ground should show a flashing light.

  7. An LED placed from the RSSI pin of the XBee (physical pin 6) to ground should show a steady light when the radio is receiving information. If messages stop coming in, this light will time out and go dark after 10 seconds.

  8. Use a multimeter to see if the voltage at the D0 pin of the XBee (physical pin 20) varies with changes in the lighting. It should be somewhere in the range between 0 and 1.2 volts and change as you shadow the light sensor with your hand.

  9. We are not always able to see our own mistakes. Have a friend check everything for you. Sometimes only a second pair of eyes will catch the one (or more) issues standing in the way of success.

  10. When all else fails: Try taking a break and coming back to the project after a good night’s rest. Many of midnight’s intractable puzzles are morning’s simple fix.