|
| 1 | +/* Copyright 2019 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_Samsung.h> |
| 32 | + |
| 33 | +const uint16_t kIrLed = 4; // ESP8266 GPIO pin to use. Recommended: 4 (D2). |
| 34 | +IRSamsungAc ac(kIrLed); // Set the GPIO used for sending messages. |
| 35 | + |
| 36 | +void printState() { |
| 37 | + // Display the settings. |
| 38 | + Serial.println("Samsung A/C remote is in the following state:"); |
| 39 | + Serial.printf(" %s\n", ac.toString().c_str()); |
| 40 | +} |
| 41 | + |
| 42 | +void setup() { |
| 43 | + ac.begin(); |
| 44 | + Serial.begin(115200); |
| 45 | + delay(200); |
| 46 | + |
| 47 | + // Set up what we want to send. See ir_Samsung.cpp for all the options. |
| 48 | + Serial.println("Default state of the remote."); |
| 49 | + printState(); |
| 50 | + Serial.println("Setting initial state for A/C."); |
| 51 | + ac.off(); |
| 52 | + ac.setFan(kSamsungAcFanLow); |
| 53 | + ac.setMode(kSamsungAcCool); |
| 54 | + ac.setTemp(25); |
| 55 | + ac.setSwing(false); |
| 56 | + printState(); |
| 57 | +} |
| 58 | + |
| 59 | +void loop() { |
| 60 | + // Turn the A/C unit on and set to cooling mode. |
| 61 | + // Power changes require we send an extended message. |
| 62 | + Serial.println("Sending an extended IR command to A/C ..."); |
| 63 | + ac.on(); |
| 64 | + ac.setMode(kSamsungAcCool); |
| 65 | + ac.sendExtended(); |
| 66 | + printState(); |
| 67 | + delay(15000); // wait 15 seconds |
| 68 | + |
| 69 | + // Increase the fan speed. |
| 70 | + Serial.println("Sending a normal IR command to A/C ..."); |
| 71 | + ac.setFan(kSamsungAcFanHigh); |
| 72 | + ac.send(); |
| 73 | + printState(); |
| 74 | + delay(15000); |
| 75 | + |
| 76 | + // Change to swing the fan. |
| 77 | + Serial.println("Sending a normal IR command to A/C ..."); |
| 78 | + ac.setSwing(true); |
| 79 | + ac.send(); |
| 80 | + printState(); |
| 81 | + delay(15000); |
| 82 | + |
| 83 | + // Change to Fan mode, lower the speed, and stop the swing. |
| 84 | + Serial.println("Sending a normal IR command to A/C ..."); |
| 85 | + ac.setSwing(false); |
| 86 | + ac.setMode(kSamsungAcFan); |
| 87 | + ac.setFan(kSamsungAcFanLow); |
| 88 | + ac.send(); |
| 89 | + printState(); |
| 90 | + delay(15000); |
| 91 | + |
| 92 | + // Turn the A/C unit off. |
| 93 | + // Power changes require we send an extended message. |
| 94 | + Serial.println("Sending an extended IR command to A/C ..."); |
| 95 | + ac.off(); |
| 96 | + ac.sendExtended(); |
| 97 | + printState(); |
| 98 | + delay(15000); // wait 15 seconds |
| 99 | +} |
0 commit comments