Advertisement
igendel

Remote Outlet Arduino Control

Dec 17th, 2020
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // K-Digital Remote Outlet control
  2. // Connect pin 13 to the 433MHz RF Kit transmitter data pin
  3.  
  4. #define SIG_BITS 24U
  5.  
  6. // Signals for button "1": Last three bits are 111
  7. uint8_t on_sig[SIG_BITS] = {0,1,1,1,1,1,1,1,1,0,0,1,1,0,0,0,0,0,0,0,1,1,1,1};
  8. uint8_t off_sig[SIG_BITS] = {0,1,1,1,1,1,1,1,1,0,0,1,1,0,0,0,0,0,0,0,0,1,1,1};
  9.  
  10. uint8_t all_off_sig[SIG_BITS] = {0,1,1,1,1,1,1,1,1,0,0,1,1,0,0,0,0,0,0,1,1,0,0,0};
  11.  
  12.  
  13. void _sendSignalOnce(uint8_t *p) {
  14.  
  15.   uint8_t n;
  16.   uint16_t uS;
  17.  
  18.   // Transmit actual bits
  19.   for (n = 0 ; n < SIG_BITS ; n++) {
  20.  
  21.     if (0 == *p++) {
  22.       uS = 300;
  23.     } else {
  24.         uS = 900;
  25.       }
  26.  
  27.     digitalWrite(13, HIGH);  
  28.     delayMicroseconds(uS);
  29.     digitalWrite(13, LOW);
  30.     delayMicroseconds(1200 - uS);
  31.    
  32.   }
  33.  
  34.   // "Stop" signal
  35.   digitalWrite(13, HIGH);  
  36.   delayMicroseconds(300);
  37.   digitalWrite(13, LOW);
  38.  
  39. }
  40.  
  41.  
  42. // Send the signal multiple times to emulate a press
  43. void sendSignal(uint8_t *p, uint8_t times) {
  44.  
  45.   while (times--) {
  46.     _sendSignalOnce(p);
  47.     // Inter-transmission delay
  48.     delay(10);      
  49.   }
  50.  
  51. }
  52.  
  53.  
  54. void setup() {
  55.  
  56.   pinMode(13, OUTPUT);
  57.  
  58.   // "Associate" transmission
  59.   sendSignal(on_sig, 6);
  60.  
  61. }
  62.  
  63.  
  64. void loop() {
  65.  
  66.   // Power outlet Blinky!
  67.   sendSignal(on_sig, 2);
  68.   delay(3000);
  69.   sendSignal(off_sig, 2);
  70.   delay(3000);
  71.  
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement