알렉사로 TV 제어하기: 아두이노 & ESP8266 설정 가이드
부품 및 소모품
| 부품 | 수량 | 용도 |
| 아두이노 우노 | 1 | IR 송신 다이오드로 TV 명령 전송 |
| NodeMCU ESP8266 브레이크아웃 보드 | 1 | 와이파이 모듈, 알렉사 앱에서 'WeMo' 디바이스로 인식. 각 디바이스별 펄스를 아두이노로 전송 |
| IR 송신기/수신기 | 1 | 100Ω 저항과 직렬 연결하여 TV로 IR 명령 전송 |
필요한 도구
앱 및 온라인 서비스
프로젝트 개요
알렉사로 TV 제어하기!
소개: 이 프로젝트는 알렉사에게 말하여 TV를 제어하는 방법입니다. TV 리모컨으로 가능한 모든 기능을 알렉사로도 할 수 있습니다. 리모컨의 IR 신호를 녹화한 후, 음성 명령 시 같은 신호를 재전송하는 방식입니다. 단계별 가이드 또는 유튜브 영상을 참조하세요.
1단계: 필수 라이브러리 다운로드
다음 라이브러리를 아두이노 IDE 라이브러리 폴더에 설치하세요:
2단계: NodeMCU (와이파이 모듈) 프로그래밍
ESP8266-Alexa.ino 스케치를 열고 NodeMCU에 업로드하세요 (보드 매니저에서 ESP8266 보드 정보 설치 필요). 와이파이 자격증명과 디바이스 이름만 수정하면 됩니다.
디바이스 이름은 ESP8266-Alexa.ino에서, 나가는 신호는 IR-Alexa-Send.ino에서 커스터마이징 가능합니다.
디바이스 이름 설정 부분
3단계: TV 리모컨 IR 신호 읽기
IR_REMOTE_read.ino 스케치를 아두이노에 업로드하여 리모컨 버튼별 IR 신호(HEX 코드)를 읽고 기록하세요.
4단계: 알렉사 명령으로 TV IR 신호 전송하도록 아두이노 프로그래밍
IR-Alexa-Send.ino를 아두이노 IDE에서 열고 아두이노 우노에 업로드하세요 (보드 선택: Arduino Uno).
두 모듈에 전원 공급하고 연결 와이어 연결. IR 송신기는 아두이노 3번 단자에 연결. 회로도 참조:
아두이노 - NodeMCU - IR 송신기 연결도
5단계: 알렉사로 테스트
아마존 알렉사 앱(모바일/PC)에서 '스마트 홈' → '기기 추가'로 ESP8266-Alexa.ino에 설정한 명령어들을 찾습니다.
알렉사 앱에서 발견된 디바이스들
다음 명령 구조로 테스트하세요:
- "알렉사, 디바이스 이름 켜줘"
- "알렉사, 디바이스 이름 켜"
- "알렉사, 디바이스 이름 켜줘"
- "알렉사, 디바이스 이름 켜"
코드
ESP8266-Alexa.ino (NodeMCU용)
NodeMCU에 업로드하여 'WeMo' 디바이스 에뮬레이션
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include "fauxmoESP.h"
#define WIFI_SSID "your_wifi_ssid"
#define WIFI_PASS "your_wifi_password"
#define SERIAL_BAUDRATE 115200
fauxmoESP fauxmo;
void wifiSetup() {
WiFi.mode(WIFI_STA);
Serial.printf("[WIFI] Connecting to %s ", WIFI_SSID);
WiFi.begin(WIFI_SSID, WIFI_PASS);
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(100);
}
Serial.println();
Serial.printf("[WIFI] STATION Mode, SSID: %s, IP: %s\n", WiFi.SSID().c_str(), WiFi.localIP().toString().c_str());
}
#define RELAY_PIN1 13
#define RELAY_PIN2 2
#define RELAY_PIN3 14
#define RELAY_PIN4 15
void setup() {
pinMode(RELAY_PIN1, OUTPUT); digitalWrite(RELAY_PIN1, LOW);
pinMode(RELAY_PIN2, OUTPUT); digitalWrite(RELAY_PIN2, LOW);
pinMode(RELAY_PIN3, OUTPUT); digitalWrite(RELAY_PIN3, LOW);
pinMode(RELAY_PIN4, OUTPUT); digitalWrite(RELAY_PIN4, LOW);
Serial.begin(SERIAL_BAUDRATE);
Serial.println("FauxMo demo sketch");
Serial.println("Ask Alexa to 'turn pixels on/off' or 'turn relay on/off'");
wifiSetup();
// 알렉사 디바이스 이름 등록
fauxmo.addDevice("TV");
fauxmo.addDevice("GregsNetflix");
fauxmo.addDevice("Sleep");
fauxmo.addDevice("Office");
fauxmo.onMessage(callback);
}
void callback(uint8_t device_id, const char * device_name, bool state) {
Serial.printf("[MAIN] %s state: %s\n", device_name, state ? "ON" : "OFF");
if (strcmp(device_name, "TV") == 0) {
digitalWrite(RELAY_PIN1, state ? HIGH : HIGH); // TV는 토글 방식이므로 둘 다 HIGH
}
if (strcmp(device_name, "GregsNetflix") == 0) {
digitalWrite(RELAY_PIN2, state ? HIGH : LOW);
}
if (strcmp(device_name, "Sleep") == 0) {
digitalWrite(RELAY_PIN3, state ? HIGH : LOW);
}
if (strcmp(device_name, "Office") == 0) {
digitalWrite(RELAY_PIN4, state ? HIGH : LOW);
}
}
void loop() {
fauxmo.handle();
delay(500);
// 펄스 방식이므로 잠시 후 LOW로 복구
digitalWrite(RELAY_PIN1, LOW);
digitalWrite(RELAY_PIN2, LOW);
digitalWrite(RELAY_PIN3, LOW);
digitalWrite(RELAY_PIN4, LOW);
}
IR-Alexa-Send.ino (아두이노 우노용)
NodeMCU에서 신호 수신 시 해당 IR 코드 전송
#include <IRremote.h>
IRsend irsend;
#define a 4 // TV
#define b 5 // GregsNetflix
#define c 6 // Sleep
#define d 7 // Office
void setup() {
Serial.begin(9600);
pinMode(a, INPUT);
pinMode(b, INPUT);
pinMode(c, INPUT);
pinMode(d, INPUT);
}
void loop() {
if (digitalRead(a) == HIGH) {
irsend.sendNEC(0x57E3E817, 32); // Power
Serial.println("TV");
delay(500);
}
if (digitalRead(b) == HIGH) {
// Netflix 진입 시퀀스 (예시: Enter → Up x3 → Right → Enter x2)
irsend.sendNEC(0x57E354AB, 32); delay(2000);
irsend.sendNEC(0x57E39867, 32); delay(1000);
irsend.sendNEC(0x57E39867, 32); delay(1000);
irsend.sendNEC(0x57E39867, 32); delay(1000);
irsend.sendNEC(0x57E3B44B, 32); delay(1000);
irsend.sendNEC(0x57E354AB, 32); delay(2000);
irsend.sendNEC(0x57E354AB, 32);
Serial.println("The Office");
delay(500);
}
if (digitalRead(c) == HIGH) {
// 슬립 타이머 설정 시퀀스
irsend.sendNEC(0x57E38679, 32); delay(1500);
irsend.sendNEC(0x57E3CC33, 32); delay(700);
irsend.sendNEC(0x57E3CC33, 32); delay(700);
irsend.sendNEC(0x57E3CC33, 32); delay(700);
irsend.sendNEC(0x57E3CC33, 32); delay(700);
irsend.sendNEC(0x57E3B44B, 32); delay(700);
irsend.sendNEC(0x57E3B44B, 32); delay(900);
irsend.sendNEC(0x57E38679, 32);
Serial.println("Sleep Timer");
delay(500);
}
if (digitalRead(d) == HIGH) {
irsend.sendNEC(0x57E34AB5, 32); // Netflix 바로가기
Serial.println("Greg's Netflix");
delay(500);
}
}
IR_REMOTE_read.ino (리모컨 코드 분석용)
아두이노에 업로드하여 리모컨 버튼별 HEX 코드 확인
// 2017.06.22
#include <IRremote.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 9, 2);
int receiverpin = 10;
IRrecv irrecv(receiverpin);
decode_results results;
void setup() {
lcd.begin(16, 2);
pinMode(receiverpin, INPUT);
Serial.begin(9600);
irrecv.enableIRIn();
}
void loop() {
if (irrecv.decode(&results)) {
Serial.println(results.value, HEX);
irrecv.resume();
lcd.clear();
lcd.print(results.value, HEX);
delay(150);
}
}
회로도
아두이노 - NodeMCU - IR 송신기 최종 연결도
참고: 위 코드의 IR 코드(0x57E3xxxx)는 예시입니다. 본인의 TV 리모컨으로 IR_REMOTE_read.ino를 실행하여 실제 코드를 확인 후 IR-Alexa-Send.ino에 적용하세요.