Skip to content

Commit e104dda

Browse files
authored
Add ControlSamsungAC example code. (#599)
Created an example of how to control the Samsung AC using the IRSamsungAc class. This is slightly different from normal as power operations require the use of the `sendExtended()` method. Hence the example code.
1 parent c6d7bdb commit e104dda

File tree

4 files changed

+122
-0
lines changed

4 files changed

+122
-0
lines changed

.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ script:
4040
- arduino --verify --board $BD $PWD/examples/TurnOnArgoAC/TurnOnArgoAC.ino
4141
- arduino --verify --board $BD $PWD/examples/IRMQTTServer/IRMQTTServer.ino
4242
- arduino --verify --board $BD $PWD/examples/TurnOnToshibaAC/TurnOnToshibaAC.ino
43+
- arduino --verify --board $BD $PWD/examples/ControlSamsungAC/ControlSamsungAC.ino
4344
# Also check the tools programs compile.
4445
- (cd tools; make all)
4546
# Check for lint issues.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
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+
}
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[platformio]
2+
lib_extra_dirs = ../../
3+
src_dir=.
4+
5+
[common]
6+
build_flags =
7+
lib_deps_builtin =
8+
lib_deps_external =
9+
10+
[env:nodemcuv2]
11+
platform = espressif8266
12+
framework = arduino
13+
board = nodemcuv2
14+
build_flags = ${common.build_flags}
15+
lib_deps =
16+
${common.lib_deps_builtin}
17+
${common.lib_deps_external}

src/ir_Samsung.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -254,13 +254,18 @@ void IRSamsungAc::checksum(uint16_t length) {
254254
}
255255

256256
#if SEND_SAMSUNG_AC
257+
// Use for most function/mode/settings changes to the unit.
258+
// i.e. When the device is already running.
257259
void IRSamsungAc::send(const uint16_t repeat, const bool calcchecksum) {
258260
if (calcchecksum) checksum();
259261
_irsend.sendSamsungAC(remote_state, kSamsungAcStateLength, repeat);
260262
}
261263
#endif // SEND_SAMSUNG_AC
262264

263265
#if SEND_SAMSUNG_AC
266+
// Use this for when you need to power on/off the device.
267+
// Samsung A/C requires an extended length message when you want to
268+
// change the power operating mode of the A/C unit.
264269
void IRSamsungAc::sendExtended(const uint16_t repeat, const bool calcchecksum) {
265270
if (calcchecksum) checksum();
266271
uint8_t extended_state[kSamsungAcExtendedStateLength] = {

0 commit comments

Comments
 (0)