TurnOnToshibaAC.ino 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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_Toshiba.h>
  32. const uint16_t kIrLed = 4; // ESP8266 GPIO pin to use. Recommended: 4 (D2).
  33. IRToshibaAC ac(kIrLed); // Set the GPIO to be used for sending messages.
  34. void printState() {
  35. // Display the settings.
  36. Serial.println("Toshiba 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 < kToshibaACStateLength; 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_Toshiba.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(kToshibaAcCool);
  56. ac.setTemp(26);
  57. }
  58. void loop() {
  59. // Now send the IR signal.
  60. #if SEND_TOSHIBA_AC
  61. Serial.println("Sending IR command to A/C ...");
  62. ac.send();
  63. #endif // SEND_TOSHIBA_AC
  64. printState();
  65. delay(5000);
  66. }