Skip to content

Doorbells: Basic & Feedback

February 28, 2010

Who ever thought a doorbell could be such an interesting thing to study?  When you think about it though, it provides the perfect opportunity to look at communication at a very basic level: send and receive.  Even with the earliest signal systems (smoke, semaphore), many of the same problems faced today were readily apparent.  You can send a signal, but how do you know it was received, and how do you know it was received correctly?

Rob Faludi gave us three assignments to get two XBee radios talking to each other: build a basic doorbell that sends a signal from one radio to another, reprogram it to send a signal back to the first when the bell rings, and then come up with another signal system altogether.

He gave us the code for the first two exercises, and you can find it here, but I’ve also posted it as I changed a couple of pins.

Basic Doorbell

Sender:

Receiver (XBee removed from Explorer):

Notes: The XBee’s run on 3.3v from the Arduino.  There is a 10K pull-down resistor from digital input 2 to ground to eliminate any noise from the switch when it is open.  Upon the press of the doorbell button, the Send Arduino sends a letter ‘D’ to the receiving Arduino via the XBees, and the receiving Arduino then rings the bell.

Code — Sender:

/*
* ********* 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
  }
}

Code — Receiver:

/*
 * ********* 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;  //WAS 4

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);
    }
  }
}

Basic Doorbell with Feedback

The setup remains the same, but now we are using the LED that is in pin 11 on the Sender (button).  The code is modified in that the receiving Arduino not only rings the bell, but also sends a ‘K’ back to the sender, at which point it lights the LED.

Code — Sender:

/*
* ********* 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);
  }
}

Code — Receiver:

/*
 * ********* Doorbell Feedback 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 = 4;

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);
    }
  }
}

Collaborator: Adib Dada

Advertisements

From → Sociable Objects

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: