Projects / Cloud AC control with IR

Cloud AC control with IR

Intermediate3 hGuided buildReviewed

Build it step by step

0 of 7 done
  1. ESP32VS1838B

    Wire the receiver

    Test it with any remote.

  2. ESP32

    Capture the on button

    Copy the raw array.

  3. ESP32

    Capture the off button

    Copy the raw array.

  4. ESP32BC54714.8 mA

    Wire the IR LEDs

    Transistor and resistor.

  5. ESP32

    Replay a code

    The AC beeps.

  6. ESP32

    Add MQTT

    Topic home/ac/cmd.

  7. ESP32

    Test from outside

    Through your own network.

In short

How do you build a cloud AC control with IR?

An ESP32 learns your AC remote and lets you turn the AC on from your phone before you reach home. You need ESP32 DevKit V1, IR receiver VS1838B, IR LED 940 nm (5 mm) × 2, BC547 NPN transistor, Resistor 47 Ω and Resistor 1 kΩ. It takes 7 steps and about 180 minutes.

Level
Intermediate
Time
About 180 min
Parts
6

Parts list

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
IR receiver OUTESP32 GPIO14Capture
IR receiver VCC and GNDESP32 3V3 and GNDPower
ESP32 GPIO41 kΩ to BC547 baseTransmit control
BC547 emitterGroundGround
Two IR LEDs in series47 Ω from 5V, to BC547 collectorIR transmitter
ESP32 VIN5 V adapterPower

Code

Point your own AC remote at the receiver, press one button, and the Serial Monitor prints a list of pulse lengths; copy that list into the matching array, once for the on command and once for off. Replaying the list through the IR LEDs at a 38 kHz carrier acts like pressing the button, and the 47 Ω resistor limits the LED current to about 50 mA in short bursts, which the BC547 can switch. Because an air conditioner's remote sends the whole setting (mode, temperature and fan) with every press, capture each combination you want as its own command. Send "on" or "off" to the topic home/ac/cmd from a phone MQTT app or Home Assistant. The IR LEDs must see the AC, so place the unit close to the receiver on the indoor unit. Put your own Wi-Fi details and broker address in the placeholders. Since the remote command is not acknowledged, add a room temperature sensor to confirm that the AC really switched. Use it only on your own appliances, and do not leave an AC running for hours unattended when nobody is home.

Runs on a virtual ESP32 Dev Module in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).

// AC IR bridge: type c in the Serial Monitor to capture a remote button as raw timings, send commands by MQTT.
// Libraries: IRremoteESP8266, PubSubClient. Board: ESP32 Dev Module.
#include <WiFi.h>
#include <PubSubClient.h>
#include <IRremoteESP8266.h>
#include <IRrecv.h>
#include <IRsend.h>
#include <IRutils.h>
const char* SSID = "YOUR_WIFI_NAME";
const char* PASS = "YOUR_WIFI_PASSWORD";
const char* BROKER = "192.168.1.10";
const int RECV_PIN = 14, SEND_PIN = 4;
IRrecv irrecv(RECV_PIN, 1024, 50, true);            // big buffer: air conditioner remotes send long frames
IRsend irsend(SEND_PIN);
decode_results results;
WiFiClient net;
PubSubClient mqtt(net);
// Paste your captured on and off arrays here (from the serial output). Each AC remote button sends a full state, so capture "on at 24 C" as its own button.
uint16_t AC_ON[]  = {0};
uint16_t AC_OFF[] = {0};
const uint16_t ON_LEN = sizeof(AC_ON) / sizeof(AC_ON[0]);
const uint16_t OFF_LEN = sizeof(AC_OFF) / sizeof(AC_OFF[0]);
void onMessage(char* topic, byte* payload, unsigned int len) {
  String cmd; for (unsigned int i = 0; i < len; i++) cmd += (char)payload[i];
  if (cmd == "on" && ON_LEN > 1) irsend.sendRaw(AC_ON, ON_LEN, 38);       // 38 kHz carrier
  if (cmd == "off" && OFF_LEN > 1) irsend.sendRaw(AC_OFF, OFF_LEN, 38);
}
void setup() {
  Serial.begin(115200);
  irsend.begin(); irrecv.enableIRIn();
  WiFi.begin(SSID, PASS);
  while (WiFi.status() != WL_CONNECTED) delay(300);
  mqtt.setServer(BROKER, 1883); mqtt.setCallback(onMessage);
}
void loop() {
  if (!mqtt.connected()) { if (mqtt.connect("ac-ir")) mqtt.subscribe("home/ac/cmd"); else delay(2000); }
  mqtt.loop();
  if (irrecv.decode(&results)) {                    // press a remote button pointed at the receiver
    Serial.println(resultToSourceCode(&results));   // prints the rawData array to copy into the sketch
    irrecv.resume();
  }
}

Test checklist

What you should see at each check. If a reading is far off, stop and use the troubleshooting list.

CheckExpected
Remote button pressA list of timings in the monitor
Send onThe AC turns on
Send offThe AC turns off
RangeWorks from across the room

If it does not work

AC does not respond

Capture again and check the carrier frequency.

Capture is cut short

Increase the buffer size.

IR weak

Check the transistor and aim the LEDs.

No MQTT

Check broker, topic and credentials.

Still stuck? Find the fault step by step with your multimeter →

Ask Lark AI

Common questions

What parts do I need for the cloud AC control with IR?

ESP32 DevKit V1, IR receiver VS1838B, IR LED 940 nm (5 mm) × 2, BC547 NPN transistor, Resistor 47 Ω and Resistor 1 kΩ.

How long does the cloud AC control with IR take to build?

About 180 minutes for a intermediate maker, in 7 steps.

How do I know the cloud AC control with IR works?

Remote button press: A list of timings in the monitor. Send on: The AC turns on. Send off: The AC turns off.

AC does not respond: what should I check?

Capture again and check the carrier frequency.

Capture is cut short: what should I check?

Increase the buffer size.

IR weak: what should I check?

Check the transistor and aim the LEDs.

No MQTT: what should I check?

Check broker, topic and credentials.