O'Reilly logo

Building Wireless Sensor Networks by Robert Faludi

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Program the Arduino Doorbell

Warning

When uploading programs to the Arduino boards, disconnect the wiring from digital pin 0 (RX) first, then reconnect the wiring after loading. If you see an error message from “AVR dude,” you probably forgot to do this.

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 enables the board to receive a signal from the button board when its switch is activated and to ring the bell:

/* * ********* Doorbell Basic BELL ******** * requires pre-paired XBee Radios * and the BUTTON program on the receiving 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); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required