본문 바로가기
Hardware

ir센서로 에어컨 원격제어, nodemcu(esp8266), kc-005

by 이르가체페 2024. 8. 8.

목표 : 구형에어컨을 30분 주기로 On/Off 반복

도구 : nodemcu(esp8266), kc-005 

 

코드는 esp8266의 예제(LGACSend)를 수정하여 사용.

// Copyright 2015 chaeplin
// Copyright 2017 xpokor22
// This is based on:
// https://github.com/z3t0/Arduino-IRremote/blob/master/examples/LGACSendDemo/LGACSendDemo.ino

#include <IRremoteESP8266.h>
#include <IRsend.h>


IRsend irsend(14);  // An IR LED is controlled by GPIO pin 14 (D5)

// 0 : TOWER
// 1 : WALL
const unsigned int kAc_Type  = 1;

// 0 : cooling
// 1 : heating
unsigned int ac_heat = 1;

// 0 : off
// 1 : on
unsigned int ac_power_on = 0;

// 0 : off
// 1 : on --> power on
unsigned int ac_air_clean_state = 0;

// temperature : 18 ~ 30
unsigned int ac_temperature = 24;

// 0 : low
// 1 : mid
// 2 : high
// if kAc_Type = 1, 3 : change
unsigned int ac_flow = 0;

const uint8_t kAc_Flow_Tower[3] = {0, 4, 6};
const uint8_t kAc_Flow_Wall[4] = {0, 2, 4, 5};

uint32_t ac_code_to_sent;
uint32_t loopcnt;

void Ac_Send_Code(uint32_t code) {
  Serial.print("code to send : ");
  Serial.print(code, BIN);
  Serial.print(" : ");
  Serial.println(code, HEX);

#if SEND_LG
  irsend.sendLG(code, 28);
#else  // SEND_LG
  Serial.println("Can't send because SEND_LG has been disabled.");
#endif  // SEND_LG
}

void Ac_Air_Clean(int air_clean) {
  if (air_clean == '1')
    ac_code_to_sent = 0x88C000C;
  else
    ac_code_to_sent = 0x88C0084;

  Ac_Send_Code(ac_code_to_sent);

  ac_air_clean_state = air_clean;
}

void setup() {
  Serial.begin(115200);
  delay(1000);
  irsend.begin();
}

void Ac_Power_On() {
  ac_code_to_sent = 0x8801C0D;
  Ac_Send_Code(ac_code_to_sent);
  ac_power_on = 1;
}

void Ac_Power_Down() {
  ac_code_to_sent = 0x88C0051;
  Ac_Send_Code(ac_code_to_sent);
  ac_power_on = 0;
}

void loop() {
  Serial.println("Start ===================================================");
  
  Ac_Power_On();      
  delay(50);
  Ac_Power_On();      
  //Serial.println("Power On !!! ");
  //delay(1801000); //1800sec
  delay(1801000); //
  
  Ac_Power_Down();
  delay(50);
  Ac_Power_Down();
  //Serial.println("Power Down !!! ");
  //delay(1801000); //1800sec
  delay(1801000); //
  
  Serial.println(loopcnt);
  loopcnt = loopcnt + 1;
  Serial.println("Finish ===================================================");
  
}

 

 

Nodemcu 배선

녹색 : D5

노랑 : 3V

파랑 : GND

 

주문은 ky-005로 했고, 포장비닐에도 그렇게 쓰여있었지만, 기기에는 HW-483만 인쇄돼있음.

 

 

제어대상 에어컨 및 리모컨

 

임시테스트

신호도달거리가 짧아 바로앞에서 시험

 

 

LGACSend 불러오기

 

 

설치결과

 

 

 

반응형

댓글