Advertisement
GeorgeIoak

Hunter Douglas Blind Control

Jan 16th, 2017
800
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.33 KB | None | 0 0
  1. #include <IRremoteESP8266.h>
  2. //#include <IRremoteInt.h>
  3.  
  4. //#include <Arduino.h>
  5. #include <ESP8266WiFi.h>
  6. #include "fauxmoESP.h"
  7.  
  8. #include "credentials.h" //WiFi SSID and password
  9.  
  10. #define SERIAL_BAUDRATE 115200
  11. #define LED 16 // LED on Board
  12. #define RELAY_PIN 5 //
  13. #define OPen2Pin 12 // Open Blinds pin
  14. #define Close2Pin 14 // Close Blinds pin
  15. #define khz 40 // 40kHz carrier frequency for the Hunter Douglas
  16.  
  17. IRsend irsend(4); //
  18.  
  19. unsigned int OPen2Signal[80] = {2800, 2800, 1050, 2800, 1050, 1050, 1050, 1050, 1050,
  20. 2800, 2800, 2800, 1050, 2800, 1050, 1050, 1050, 1050, 1050,
  21. 2800, 2800, 2800, 1050, 2800, 1050, 1050, 1050, 1050, 1050,
  22. 2800, 2800, 2800, 1050, 2800, 1050, 1050, 1050, 1050, 1050,
  23. 2800, 2800, 2800, 1050, 2800, 1050, 1050, 1050, 1050, 1050,
  24. 2800, 2800, 2800, 1050, 2800, 1050, 1050, 1050, 1050, 1050,
  25. 2800, 2800, 2800, 1050, 2800, 1050, 1050, 1050, 1050, 1050,
  26. 2800, 2800, 2800, 1050, 2800, 1050, 1050, 1050, 1050, 1050, 1975
  27. }; //Open2
  28.  
  29. unsigned int Close2Signal[80] = {2800, 2800, 1050, 2800, 1050, 1050, 1050, 2800, 1050,
  30. 1050, 2800, 2800, 1050, 2800, 1050, 1050, 1050, 2800, 1050,
  31. 1050, 2800, 2800, 1050, 2800, 1050, 1050, 1050, 2800, 1050,
  32. 1050, 2800, 2800, 1050, 2800, 1050, 1050, 1050, 2800, 1050,
  33. 1050, 2800, 2800, 1050, 2800, 1050, 1050, 1050, 2800, 1050,
  34. 1050, 2800, 2800, 1050, 2800, 1050, 1050, 1050, 2800, 1050,
  35. 1050, 2800, 2800, 1050, 2800, 1050, 1050, 1050, 2800, 1050,
  36. 1050, 2800, 2800, 1050, 2800, 1050, 1050, 1050, 2800, 1050, 1975
  37. }; //Close the lower blinds
  38.  
  39.  
  40. // variables will change:
  41. int butOpen2State = 0; // variable for reading the pushbutton status
  42. int butClose2State = 0; // variable for reading the pushbutton status
  43.  
  44. fauxmoESP fauxmo;
  45.  
  46. // -----------------------------------------------------------------------------
  47. // Wifi
  48. // -----------------------------------------------------------------------------
  49.  
  50. void wifiSetup() {
  51.  
  52. // Set WIFI module to STA mode
  53. WiFi.mode(WIFI_STA);
  54.  
  55. // Connect
  56. Serial.printf("[WIFI] Connecting to %s ", WIFI_SSID);
  57. WiFi.begin(WIFI_SSID, WIFI_PASS);
  58.  
  59. // Wait
  60. while (WiFi.status() != WL_CONNECTED) {
  61. Serial.print(".");
  62. delay(100);
  63. }
  64. Serial.println();
  65.  
  66. // Connected!
  67. Serial.printf("[WIFI] STATION Mode, SSID: %s, IP address: %s\n", WiFi.SSID().c_str(), WiFi.localIP().toString().c_str());
  68. }
  69.  
  70. void callback(unsigned char device_id, const char * device_name, bool state) {
  71. Serial.print("Device ID "); Serial.print(device_id);
  72. Serial.print("Device "); Serial.print(device_name);
  73. Serial.print(" state: ");
  74. if (state) {
  75. Serial.println("ON");
  76. } else {
  77. Serial.println("OFF");
  78. }
  79.  
  80. if ( (strcmp(device_name, "relay") == 0) ) {
  81. // adjust the relay immediately!
  82. if (state) {
  83. digitalWrite(RELAY_PIN, HIGH);
  84. } else {
  85. digitalWrite(RELAY_PIN, LOW);
  86. Serial.println("I'm turning it OFF");
  87. }
  88. }
  89. }
  90.  
  91. void setup() {
  92. // Init serial port and clean garbage
  93. Serial.begin(SERIAL_BAUDRATE);
  94. Serial.println("FauxMo demo sketch");
  95. Serial.println("After connection, ask Alexa/Echo to 'turn <devicename> on' or 'off'");
  96.  
  97. // Wifi
  98. wifiSetup();
  99.  
  100. // Buttons
  101. pinMode(OPen2Pin, INPUT);
  102. pinMode(Close2Pin, INPUT);
  103.  
  104. // LED
  105. pinMode(LED, OUTPUT);
  106. digitalWrite(LED, LOW);
  107.  
  108. pinMode(RELAY_PIN, OUTPUT);
  109. digitalWrite(RELAY_PIN, LOW);
  110.  
  111. //pinMode(LED_BUILTIN, OUTPUT); // This is D0 or 16
  112. //digitalWrite(LED_BUILTIN, HIGH);
  113.  
  114. // Fauxmo
  115. fauxmo.addDevice("relay");
  116. fauxmo.addDevice("pixels");
  117. fauxmo.onMessage(callback);
  118.  
  119. }
  120.  
  121. void loop() {
  122.  
  123. // Since fauxmoESP 2.0 the library uses the "compatibility" mode by
  124. // default, this means that it uses WiFiUdp class instead of AsyncUDP.
  125. // The later requires the Arduino Core for ESP8266 staging version
  126. // whilst the former works fine with current stable 2.3.0 version.
  127. // But, since it's not "async" anymore we have to manually poll for UDP
  128. // packets
  129. fauxmo.handle();
  130.  
  131. // read the state of the pushbutton value:
  132. butOpen2State = digitalRead(OPen2Pin);
  133. butClose2State = digitalRead(Close2Pin);
  134. //Serial.println(butOpen2State);
  135.  
  136. if (butOpen2State == HIGH) {
  137. // send IR code:
  138. //irsend.sendRaw(OPen2Signal, sizeof(OPen2Signal) / sizeof(OPen2Signal[0]), khz);
  139. irsend.sendRaw(OPen2Signal, 80, 40);
  140. Serial.println("Open2 Button Pushed");
  141. digitalWrite(LED, HIGH);
  142. }
  143.  
  144. if (butClose2State == HIGH) {
  145. // send IR code:
  146. irsend.sendRaw(Close2Signal, sizeof(Close2Signal) / sizeof(Close2Signal[0]), khz);
  147. Serial.println("Close2 Button Pushed");
  148. digitalWrite(LED, LOW);
  149. }
  150.  
  151. /* D0 is the Blue WiFi LED on the ESP Module
  152. digitalWrite(LED, HIGH);
  153. delay(1500);
  154. digitalWrite(LED, LOW);
  155. delay(1500);
  156. */
  157.  
  158. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement