TurnOnKelvinatorAC.ino 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /* Copyright 2016, 2018 David Conran
  2. *
  3. * An IR LED circuit *MUST* be connected to the ESP8266 on a pin
  4. * as specified by kIrLed below.
  5. *
  6. * TL;DR: The IR LED needs to be driven by a transistor for a good result.
  7. *
  8. * Suggested circuit:
  9. * https://github.com/markszabo/IRremoteESP8266/wiki#ir-sending
  10. *
  11. * Common mistakes & tips:
  12. * * Don't just connect the IR LED directly to the pin, it won't
  13. * have enough current to drive the IR LED effectively.
  14. * * Make sure you have the IR LED polarity correct.
  15. * See: https://learn.sparkfun.com/tutorials/polarity/diode-and-led-polarity
  16. * * Typical digital camera/phones can be used to see if the IR LED is flashed.
  17. * Replace the IR LED with a normal LED if you don't have a digital camera
  18. * when debugging.
  19. * * Avoid using the following pins unless you really know what you are doing:
  20. * * Pin 0/D3: Can interfere with the boot/program mode & support circuits.
  21. * * Pin 1/TX/TXD0: Any serial transmissions from the ESP8266 will interfere.
  22. * * Pin 3/RX/RXD0: Any serial transmissions to the ESP8266 will interfere.
  23. * * ESP-01 modules are tricky. We suggest you use a module with more GPIOs
  24. * for your first time. e.g. ESP-12 etc.
  25. */
  26. #ifndef UNIT_TEST
  27. #include <Arduino.h>
  28. #endif
  29. #include <IRremoteESP8266.h>
  30. #include <IRsend.h>
  31. #include <ir_Kelvinator.h>
  32. const uint16_t kIrLed = 4; // ESP8266 GPIO pin to use. Recommended: 4 (D2).
  33. IRKelvinatorAC ac(kIrLed); // Set the GPIO to be used for sending messages.
  34. void printState() {
  35. // Display the settings.
  36. Serial.println("Kelvinator A/C remote is in the following state:");
  37. Serial.printf(" %s\n", ac.toString().c_str());
  38. // Display the encoded IR sequence.
  39. unsigned char* ir_code = ac.getRaw();
  40. Serial.print("IR Code: 0x");
  41. for (uint8_t i = 0; i < kKelvinatorStateLength; i++)
  42. Serial.printf("%02X", ir_code[i]);
  43. Serial.println();
  44. }
  45. void setup() {
  46. ac.begin();
  47. Serial.begin(115200);
  48. delay(200);
  49. // Set up what we want to send. See ir_Kelvinator.cpp for all the options.
  50. // Most things default to off.
  51. Serial.println("Default state of the remote.");
  52. printState();
  53. Serial.println("Setting desired state for A/C.");
  54. ac.on();
  55. ac.setFan(1);
  56. ac.setMode(kKelvinatorCool);
  57. ac.setTemp(26);
  58. ac.setSwingVertical(false);
  59. ac.setSwingHorizontal(true);
  60. ac.setXFan(true);
  61. ac.setIonFilter(false);
  62. ac.setLight(true);
  63. }
  64. void loop() {
  65. // Now send the IR signal.
  66. #if SEND_KELVINATOR
  67. Serial.println("Sending IR command to A/C ...");
  68. ac.send();
  69. #endif // SEND_KELVINATOR
  70. printState();
  71. delay(5000);
  72. }