Author Topic: Turn on / off the air conditioner via mobile phone with WEMOS D1 MINI (ESP8266)  (Read 1505 times)


  • Newbie
  • *
  • Posts: 2

From the previous article Measure the room temperature with the WeMos D1 Mini (ESP8266). Notice to LINE. Advice and encouragement beyond expectations. Therefore had the strength to hurry to dismantle the old project that was thought of but not to do that Remote Air with Mobile But that Thinking for a long time, but not taking action, not getting results Okay, so it's not a waste of time. Go to see details better.

What can it do?
Can turn on / off the LG brand air conditioner via mobile phone
Can turn on / off the LG brand air conditioner via computer
Set temperature 20 ° C and 25 ° C
Controlled from the network under the same Wi-Fi
What equipment are used?
WeMos D1 mini
KY-005 Infrared emission sensor

Let's start!
The cable can be used as usual. The sensor uses 5V power as usual, but the time required to use must aim the sensor to match the air exactly.

IR Emission + <–> WeMos 5V
IR Emission - <–> WeMos G
IR Emission Data <–> WeMos D3

Write control program
In this article, I have studied the example of the Infrared remote library for ESP8266. There is a way to create a server to support the receipt of a remote code And send the code via IR Emission Sensor to the air again And I personally searched until I found the code to use Here is the LG brand air conditioner. As for other brands in the example, there are some. Try searching.

Open = 142607621
Closed = 143392849
Adjust the temperature to 20 ° C = 142640397
Adjust the temperature to 25 ° C = 142641666

To replace the Wifi SSID and Password into the code and then upload it. Oh, for UI, I cut out the decoration part. Fearing that it will be taken online and will be subject to copyright concerns But if you are interested in the latter, let's talk.

 The code bits of each brand I searched out in the library code for this. In my example as LG, use the irsend.sendLG (code, 28) command;

Brand Bit Command Example
NEC 32 sendNEC (data, nbits)
SONY 12 sendSony (data, nbits)
JVC 16 sendJVC (data, nbits, 0)
LG 28 sendLG (data, nbits)
SAMSUNG 32 sendSAMSUNG (data, nbits)
WHYNTER 32 sendWhynter (data, nbits)
COOLIX 3 sendCOOLIX (data, nbits)
DAIKIN 99 *** There is a unique position like this.

#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
#include <IRremoteESP8266.h>
const char* ssid     = "xxxx"; //your wifi's ssid
const char* password = "xxxx"; //your wifi's password

MDNSResponder mdns;

ESP8266WebServer server(80);

IRsend irsend(0);

void handleRoot() {
 server.send(200, "text/html", "<html> <head> <title>kittipongint AC Remote Control</title> <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"><style type=\"text/css\"> * {-webkit-touch-callout: none; -webkit-user-select: none; box-sizing: border-box; } *:before, *:after {box-sizing: border-box; } html {background: linear-gradient(141deg, #0fb8ad 0%, #1fc8db 51%, #2cb5e8 75%); } html, body {margin: 0; padding: 0; width: 100%; height: 100%; overflow: hidden; font-family: serif; } .remoter .btn {width: 60px; height: 60px; border-radius: 50%; border: 3px solid #2d2f2e; margin: 10px 0 0 10px; position: relative; } .remoter .btn:hover {cursor: pointer; border-color: #464948; } .remoter {border-color: #5f6361; } .remoter .dark {background: #2d2f2e; } .remoter .icon {font-size: 2em; font-weight: bold; position: absolute; top: 50%; left: 50%; -webkit-transform: translate(-50%, -50%); transform: translate(-50%, -50%); -webkit-transform: translate(-50%, -50%) scale(0.6); transform: translate(-50%, -50%) scale(0.6); } .remoter .icon a {text-decoration: none; color: #2d2f2e; } .remoter .dark .icon a {text-decoration: none; color: #a3a3a3; } .remoter .vol-label {font-size: 12px; font-weight: bold; position: absolute; top: 230px; right: 15px; -webkit-transform: scale(0.7); transform: scale(0.7); } </style></head> <body> <div> <div class=\"remoter\"> <div class=\"btn btn-on dark\"> <div class=\"icon\"><a href=\"ir?code=142607621\">ON</a></div> </div> <div class=\"btn btn-off dark\"> <div class=\"icon\"><a href=\"ir?code=143392849\">OFF</a></div> </div> <div class=\"btn btn-20\"> <div class=\"icon\"><a href=\"ir?code=142640397\">20&#8451;</a></div> </div> <div class=\"btn btn-25\"> <div class=\"icon\"><a href=\"ir?code=142641666\">25&#8451;</a></div> </div> <label class=\"vol-label\">kittipongint AC Remote</label> </div> </div> </body> </html>");

void handleIr(){
  for (uint8_t i=0; i<server.args(); i++){
    if(server.argName(i) == "code")
      unsigned long code = server.arg(i).toInt();
      irsend.sendLG(code, 28);

void handleNotFound(){
  String message = "File Not Found\n\n";
  message += "URI: ";
  message += server.uri();
  message += "\nMethod: ";
  message += (server.method() == HTTP_GET)?"GET":"POST";
  message += "\nArguments: ";
  message += server.args();
  message += "\n";
  for (uint8_t i=0; i<server.args(); i++){
    message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
  server.send(404, "text/plain", message);
void setup(void){
  WiFi.begin(ssid, password);

  // Wait for connection
  while (WiFi.status() != WL_CONNECTED) {
  Serial.print("Connected to ");
  Serial.print("IP address: ");
  if (mdns.begin("esp8266", WiFi.localIP())) {
    Serial.println("MDNS responder started");
  server.on("/", handleRoot);
  server.on("/ir", handleIr);
  server.on("/inline", [](){
    server.send(200, "text/plain", "this works as well");

  Serial.println("HTTP server started");
void loop(void){

Upload the code into the WeMos drought. Open the Serial Monitor (Ctrl + Shift + M). Look at the IP address line. In my example,

Pick up the phone and open the browser. Go to

Or go to the computer and open the browser to as well

Reference and thanks
Design - remote UI
Infrared remote library for ESP8266
It should be enough to be an idea. In particular, the remote UI mask looks better than ever. From now on, if anyone will be able to continue to build up and jam, please ask. Can you help each other? We will have more good things to share with each other. Online system from outside the circle.


  • Newbie
  • *
  • Posts: 6
Wow, amazing like this can be controlled from a distance. Thank you for sharing.
แจ็คพอต สล็อต