TurnOnMitsubishiAC.ino 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /* Copyright 2017, 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_Mitsubishi.h>
  32. const uint16_t kIrLed = 4; // ESP8266 GPIO pin to use. Recommended: 4 (D2).
  33. IRMitsubishiAC ac(kIrLed); // Set the GPIO used for sending messages.
  34. void printState() {
  35. // Display the settings.
  36. Serial.println("Mitsubishi 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 < kMitsubishiACStateLength; 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_Mitsubishi.cpp for all the options.
  50. Serial.println("Default state of the remote.");
  51. printState();
  52. Serial.println("Setting desired state for A/C.");
  53. ac.on();
  54. ac.setFan(1);
  55. ac.setMode(kMitsubishiAcCool);
  56. ac.setTemp(26);
  57. ac.setVane(kMitsubishiAcVaneAuto);
  58. }
  59. void loop() {
  60. // Now send the IR signal.
  61. #if SEND_MITSUBISHI_AC
  62. Serial.println("Sending IR command to A/C ...");
  63. ac.send();
  64. #endif // SEND_MITSUBISHI_AC
  65. printState();
  66. delay(5000);
  67. }