// Arduino Smoke Alarm Receiver Code
// by Ido Gendel
#include <VirtualWire.h>
#define SPEAKER_PIN 8
#define DATA_PIN 2
// Sound the alarm - 3 tones of 1 sec
// with 1 sec delay between them
void alarm() {
for (byte j = 0; j < 3; j++) {
tone(SPEAKER_PIN, 3150);
delay(1000);
noTone(SPEAKER_PIN);
delay(1000);
}
}
void setup() {
// Prepare VirtualWire for receiving
vw_set_rx_pin(DATA_PIN);
vw_setup(1200); // Bits per sec
vw_rx_start();
}
void loop() {
uint8_t buf[2];
uint8_t buflen = 2;
// Wait for message
vw_wait_rx();
// Is it a complete "message"?
if (vw_get_message(buf, &buflen)) {
// is it the activation code?
// This check is hard-coded, should be written more generally
// for serious applications
if ((buf[0] == 170) && (buf[1] == 205)) alarm();
}
}
Comments