Advertisement
igendel

Arduino Fake Smoke Alarm Transmitter

Aug 1st, 2013
351
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.31 KB | None | 0 0
  1. // Arduino Fake Smoke Alarm Transmitter Code
  2. // by Ido Gendel
  3. // For the Pro Mini
  4. #include <VirtualWire.h>
  5.  
  6. // Pins for activation button/sensor
  7. #define BUTTON_PIN 12
  8. #define BUTTON_REF 11
  9.  
  10. // Pin definitions for the RF transmitter
  11. // Its 3rd pin should be connected to GND
  12. #define DATA_PIN 2
  13. #define POWER_PIN 3
  14.  
  15. // Numeric code for activation
  16. #define CODE_LENGTH 2
  17.  
  18. // Actual code, could be anything
  19. byte code[CODE_LENGTH] = {170, 205};
  20.  
  21. // Send activation code
  22. void sendTrigger() {
  23.   vw_send(code, CODE_LENGTH);
  24. }
  25.  
  26. void setup() {
  27.  
  28.  // Prepare VirtualWire for sending
  29.  vw_set_tx_pin(DATA_PIN);
  30.  vw_setup(1200); // Bits per sec
  31.  
  32.  // Built-in LED will indicate transmission
  33.  pinMode(13, OUTPUT);
  34.  
  35.  // Power up the transmitter module
  36.  pinMode(POWER_PIN, OUTPUT);
  37.  digitalWrite(POWER_PIN, HIGH);
  38.  
  39.  // Prepare button/sensor input ("open collector")
  40.  pinMode(BUTTON_REF, OUTPUT);
  41.  digitalWrite(BUTTON_REF, LOW);
  42.  pinMode(BUTTON_PIN, INPUT); // Activate internal pull-up
  43.  digitalWrite(BUTTON_PIN, HIGH);
  44.  
  45. }
  46.  
  47. void loop() {
  48.  
  49.   // Command detected?
  50.   if (digitalRead(BUTTON_PIN) == LOW) {
  51.  
  52.     // Give visual indication
  53.     digitalWrite(13, HIGH);
  54.     delay(10);
  55.     digitalWrite(13, LOW);
  56.     // Send activation code, then wait a little
  57.     sendTrigger();
  58.     delay(1000);
  59.    
  60.   }  
  61.  
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement