Advertisement
igendel

Arduino Smoke Alarm Receiver Code

Aug 1st, 2013
381
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.88 KB | None | 0 0
  1. // Arduino Smoke Alarm Receiver Code
  2. // by Ido Gendel
  3. #include <VirtualWire.h>
  4.  
  5. #define SPEAKER_PIN 8
  6. #define DATA_PIN 2
  7.  
  8. // Sound the alarm - 3 tones of 1 sec
  9. // with 1 sec delay between them
  10. void alarm() {
  11.  
  12.   for (byte j = 0; j < 3; j++) {
  13.     tone(SPEAKER_PIN, 3150);
  14.     delay(1000);
  15.     noTone(SPEAKER_PIN);
  16.     delay(1000);
  17.   }  
  18.  
  19. }
  20.  
  21. void setup() {
  22.  
  23.  // Prepare VirtualWire for receiving
  24.  vw_set_rx_pin(DATA_PIN);
  25.  vw_setup(1200); // Bits per sec
  26.  vw_rx_start();    
  27.  
  28. }
  29.  
  30. void loop() {
  31.  
  32.   uint8_t buf[2];
  33.   uint8_t buflen = 2;  
  34.  
  35.   // Wait for message
  36.   vw_wait_rx();
  37.  
  38.   // Is it a complete "message"?
  39.   if (vw_get_message(buf, &buflen)) {
  40.    
  41.     // is it the activation code?
  42.     // This check is hard-coded, should be written more generally
  43.     // for serious applications
  44.     if ((buf[0] == 170) && (buf[1] == 205)) alarm();  
  45.    
  46.   }
  47.  
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement