この記事は、電子工作初心者の私が必要に駆られて自作したリモコン代替装置の制作記録です。
初心者でもがんばればプログラムコピペでなんとかこれぐらい作れるということが伝われば幸いです。
私は物持ちがとてもいい。我が家のテレビはHisense製のHS32K220というモデルで、購入は2015年6月なのでかれこれ6年近く休みなく働いてくれている。そんな働き者のテレビくんだが、少し前から不調が現れ始めた。不調といっても本体は何ら問題なく、リモコンの方の調子が悪い。時々、早送りボタンを押したのに戻るボタンの動作になったり、30秒スキップのボタンが番組表になったり、4chのボタンに至っては反応すらしない。しかし一番困るのは、電源ボタンが全く利かなくなってしまったこと。朝起きてテレビを点けるのも、夜寝る前に消すのも、わざわざテレビまで歩いていって、背面のボタンを押さないといけないのだ。このままだと、いずれこのリモコンは他のボタンも利かなくなり、テレビ本体は壊れていなくても使用がままならなくなってしまう…
そんな事態を避けるために、今回Arduinoを用いてリモコンの保険(代わり)になるものを作ることにした。
欲しい機能として、
①リモコンで行う一通りの操作の再現、
②操作はPC・スマホからできること
の2つを条件とした。
使用したのは以下の6点。
- ESP32-DevKitC ESP-WROOM-32開発ボード
- 赤外線LED
- ブレッドボード
- 抵抗
- マイクロUSBケーブル
- USB電源
ESP32-DevKitCはWi-fiを内蔵しているので、部品を追加せずに家のWi-fiに接続できる。プログラム次第でPCやスマホから制御できるのでこれを使用した。
赤外線LEDは10個100円ちょいとかで買った(と思う。リモコン作ろうとだいぶ前に思い立って買ったものの、放置してたので…)。
設計図
書くまでもないほど単純ですが、ESP32-DevKitCに抵抗と赤外線LEDを接続しています。
プログラム
Wi-fi経由でLチカを行うプログラムと、初心者向けの学習リモコンのプログラムを組み合わせて使用しました。
これでWi-fi経由でESP32-DevKitCにアクセスすると、下図のようなリモコンを模したテキストページが表示され、リンクになっている文字をクリックするとリモコンの信号が赤外線LEDから発信されます。
ちなみにリモコンのコードの特定、こちらに結構手こずりました。
初心者向けの学習リモコンの電子工作では、たいてい赤外線リモコン受信モジュールで手持ちのリモコンから受光し、その信号の生の値を赤外線LEDから発信するというのが多いです。
問題は、赤外線リモコン受信モジュールが私の手元になかったこと(前にあったやつを無くしました…)。有名なメーカーのものなら信号コード一覧などがネットのどこかに転がっているかと思ったのですが、Hisenseのものはなかなか見つからず。
テレビの型番で検索したところ、海外のサイトにて、同型番ではないもののHisenseのテレビリモコンのコード一覧のようなものをなんとか見つけたので、使用してみると見事に動きました。
ESP32-DevKitCをリモコン化するプログラム
#include <WiFi.h>
#include <IRsend.h>
IRsend irsend(4);
const char* ssid = "XXXXXXXX";
const char* password = "XXXXXXXX";
WiFiServer server(80);
void setup()
{
Serial.begin(115200);
pinMode(4, OUTPUT); // set the LED pin mode
delay(10);
// We start by connecting to a WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected.");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
server.begin();
irsend.begin();
}
int value = 0;
void loop(){
WiFiClient client = server.available(); // listen for incoming clients
if (client) { // if you get a client,
Serial.println("New Client."); // print a message out the serial port
String currentLine = ""; // make a String to hold incoming data from the client
while (client.connected()) { // loop while the client's connected
if (client.available()) { // if there's bytes to read from the client,
char c = client.read(); // read a byte, then
Serial.write(c); // print it out the serial monitor
if (c == '\n') { // if the byte is a newline character
// if the current line is blank, you got two newline characters in a row.
// that's the end of the client HTTP request, so send a response:
if (currentLine.length() == 0) {
// HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
// and a content-type so the client knows what's coming, then a blank line:
client.println("HTTP/1.1 200 OK");
client.println("Content-type:text/html");
client.println();
// the content of the HTTP response follows the header:
client.print("<a href=\"/PWR\">Power</a> <br>"); // 1,電源
client.print("<a href=\"/VUP\">Vol Up</a><br>"); // 2,音量UP
client.print("<a href=\"/VDN\">Vol Down</a><br>"); // 3,音量DOWN
client.print("<a href=\"/CUP\">Channel +</a><br>"); // 4,channel +
client.print("<a href=\"/CDN\">Channel -</a><br>"); // 5,channel -
client.print("<a href=\"/EPG\">[EPG]</a><br>"); // 6,EPG
client.print("<a href=\"/BCK\">BACK</a><br>"); // 7,BACK
client.print("<a href=\"/MUT\">MUTE</a><br>"); // 8,MUTE
client.print("<a href=\"/AUP\">___[ UP ]____</a><br>"); // 9,UP
client.print("<a href=\"/ALE\">[LEFT]</a><a href=\"/ARI\">[RIGHT]</a><br>"); // 9.5,LR
client.print("<a href=\"/ADN\">___[DOWN]__</a><br>"); // 10,DOWN
client.print("<a href=\"/ENT\">[OK]</a><br>"); // 11,OK
client.print("<a href=\"/SET\">[Settings]</a><br>"); // 12,Settings
client.print("<a href=\"/INF\">[INFO]</a><br>"); // 13,INFO
client.print("<a href=\"/BLU\">[__]</a>"); // 14,BLUE
client.print("<a href=\"/RED\">[__]</a>"); // 15,RED
client.print("<a href=\"/GRN\">[__]</a>"); // 16,GREEN
client.print("<a href=\"/YLW\">[__]</a><br>"); // 17,YELLOW
client.print("<a href=\"/LST\">[time shift]</a><br>"); // 18,time shift
client.print("<a href=\"/SUB\">[Data]</a><br>"); // 19,subtitles
client.print("<a href=\"/001\">[_1_]</a>");
client.print("<a href=\"/002\">[_2_]</a>");
client.print("<a href=\"/003\">[_3_]</a><br>");
client.print("<a href=\"/004\">[_4_]</a>");
client.print("<a href=\"/005\">[_5_]</a>");
client.print("<a href=\"/006\">[_6_]</a><br>");
client.print("<a href=\"/007\">[_7_]</a>");
client.print("<a href=\"/008\">[_8_]</a>");
client.print("<a href=\"/009\">[_9_]</a><br>");
client.print("<a href=\"/000\">[_0_]</a><br>");
client.print("<a href=\"/HDD\">[HDD]</a><br>"); // 30,HDD
client.print("<a href=\"/PLY\">[>]</a><br>"); // 31,play
client.print("<a href=\"/PSE\">[II]</a><br>"); // 32,pause
client.print("<a href=\"/STP\">[[]]</a><br>"); // 33,stop
client.print("<a href=\"/RWI\">[<<]</a><br>"); // 34,rewind
client.print("<a href=\"/SUB\">[SUB]</a><br>"); // 35,SUB
client.print("<a href=\"/XX2\">[XX2]</a><br>");
// The HTTP response ends with another blank line:
client.println();
// break out of the while loop:
break;
} else { // if you got a newline, then clear currentLine:
currentLine = "";
}
} else if (c != '\r') { // if you got anything else but a carriage return character,
currentLine += c; // add it to the end of the currentLine
}
if (currentLine.endsWith("GET /PWR")) {
Serial.println("【Power】");
irsend.sendNEC(0xFDB04F, 32);
delay(10);
irsend.sendNEC(0xFDB04F, 32); // 1,電源
}
if (currentLine.endsWith("GET /VUP")) {
Serial.println("【Vol UP】");
irsend.sendNEC(0xFD22DD, 32); // 2,音量UP
}
if (currentLine.endsWith("GET /VDN")) {
Serial.println("【Vol Down】");
irsend.sendNEC(0xFDC23D, 32); // 3,音量DOWN
}
if (currentLine.endsWith("GET /CUP")) {
Serial.println("【channel +】");
irsend.sendNEC(0xFD52AD, 32); // 4,channel +
}
if (currentLine.endsWith("GET /CDN")) {
Serial.println("【channel -】");
irsend.sendNEC(0xFDD22D, 32); // 5,channel -
}
if (currentLine.endsWith("GET /EPG")) {
Serial.println("【EPG】");
irsend.sendNEC(0xFDB847, 32); // 6,EPG
}
if (currentLine.endsWith("GET /BCK")) {
Serial.println("【BACK】");
irsend.sendNEC(0xFD12ED, 32); // 7,BACK
}
if (currentLine.endsWith("GET /MUT")) {
Serial.println("【MUTE】");
irsend.sendNEC(0xFD708F, 32); // 8,MUTE
}
if (currentLine.endsWith("GET /AUP")) {
Serial.println("【UP】");
irsend.sendNEC(0xFD6897, 32); // 9,UP
}
if (currentLine.endsWith("GET /ALE")) {
Serial.println("【LEFT】");
irsend.sendNEC(0xFD9867, 32); // 9.5,LR
}
if (currentLine.endsWith("GET /ARI")) {
Serial.println("【RIGHT】");
irsend.sendNEC(0xFD18E7, 32); // 9.5,LR
}
if (currentLine.endsWith("GET /ADN")) {
Serial.println("【DOWN】");
irsend.sendNEC(0xFDE817, 32); // 10,DOWN
}
if (currentLine.endsWith("GET /ENT")) {
Serial.println("【OK】");
irsend.sendNEC(0xFDA857, 32); // 11,OK
}
if (currentLine.endsWith("GET /SET")) {
Serial.println("【SETTINGS】");
irsend.sendNEC(0xFD28D7, 32); // 12,SETTINGS
}
if (currentLine.endsWith("GET /INF")) {
Serial.println("【INFO】");
irsend.sendNEC(0xFD30CF, 32); // 13,INFO
}
if (currentLine.endsWith("GET /BLU")) {
Serial.println("【BLUE】");
irsend.sendNEC(0xFDAA55, 32); // 14,BLUE
}
if (currentLine.endsWith("GET /RED")) {
Serial.println("【RED】");
irsend.sendNEC(0xFD4AB5, 32); // 15,RED
}
if (currentLine.endsWith("GET /GRN")) {
Serial.println("【GREEN】");
irsend.sendNEC(0xFDCA35, 32); // 16,GREEN
}
if (currentLine.endsWith("GET /YLW")) {
Serial.println("【YELLOW】");
irsend.sendNEC(0xFD2AD5, 32); // 17,YELLOW
}
if (currentLine.endsWith("GET /LST")) {
Serial.println("【time shift】");
irsend.sendNEC(0xFD8A75, 32); // 18,time shift
}
if (currentLine.endsWith("GET /SUB")) {
Serial.println("【Data】");
irsend.sendNEC(0xFDF807, 32); // 19,Data
}
if (currentLine.endsWith("GET /000")) {
Serial.println("【0】");
irsend.sendNEC(0xFD00FF, 32); // 20,0
}
if (currentLine.endsWith("GET /001")) {
Serial.println("【1】");
irsend.sendNEC(0xFD807F, 32); // 21,1
}
if (currentLine.endsWith("GET /002")) {
Serial.println("【2】");
irsend.sendNEC(0xFD40BF, 32); // 22,2
}
if (currentLine.endsWith("GET /003")) {
Serial.println("【3】");
irsend.sendNEC(0xFDC03F, 32); // 23,3
}
if (currentLine.endsWith("GET /004")) {
Serial.println("【4】");
irsend.sendNEC(0xFD20DF, 32); // 24,4
}
if (currentLine.endsWith("GET /005")) {
Serial.println("【5】");
irsend.sendNEC(0xFDA05F, 32); // 25,5
}
if (currentLine.endsWith("GET /006")) {
Serial.println("【6】");
irsend.sendNEC(0xFD609F, 32); // 26,6
}
if (currentLine.endsWith("GET /007")) {
Serial.println("【7】");
irsend.sendNEC(0xFDE01F, 32); // 27,7
}
if (currentLine.endsWith("GET /008")) {
Serial.println("【8】");
irsend.sendNEC(0xFD10EF, 32); // 28,8
}
if (currentLine.endsWith("GET /009")) {
Serial.println("【9】");
irsend.sendNEC(0xFD906F, 32); // 29,9
}
if (currentLine.endsWith("GET /HDD")) {
Serial.println("【HDD】");
irsend.sendNEC(0xFDBA45, 32); // 30,HDD
}
if (currentLine.endsWith("GET /PLY")) {
Serial.println("【PLAY】");
irsend.sendNEC(0xFD15EA, 32); // 31,PLAY
}
if (currentLine.endsWith("GET /PSE")) {
Serial.println("【PAUSE】");
irsend.sendNEC(0xFD956A, 32); // 32,PAUSE
}
if (currentLine.endsWith("GET /STP")) {
Serial.println("【STOP】");
irsend.sendNEC(0xFD5AA5, 32); // 33,STOP
}
if (currentLine.endsWith("GET /RWI")) {
Serial.println("【REWIND】");
irsend.sendNEC(0xFD1AE5, 32); // 34,REWIND
}
if (currentLine.endsWith("GET /SUB")) {
Serial.println("【SUB】");
irsend.sendNEC(0xFD8877, 32); // 35,SUB
}
if (currentLine.endsWith("GET /XX2")) {
Serial.println("【XX2】");
irsend.sendNEC(0xFD11EE, 32); // XX2
}
}
}
// close the connection:
client.stop();
Serial.println("Client Disconnected.");
}
}
作ってみた感想
初心者の自分でも一日がんばって、電子部品と、プログラムと、たくさんの先人たちのWebサイトをにらめっこすれば、なんとか求めるものを形にすることができました。とりあえずわからなくてもやってみる、試行錯誤の気持ちが大切だと思います。そのうちこの記事も、誰かがリモコンを作るときの参考になればいいな。
-
shoshoh
さんが
2021/02/28
に
編集
をしました。
(メッセージ: 初版)
ログインしてコメントを投稿する