Revitalize Controles Remotos Antigos: Crie Dispositivos Inteligentes DIY com Arduino
Componentes e Materiais
| Componente | Quantidade | Observações |
|---|---|---|
| Arduino Nano R3 | 1 | |
| LED 5 mm Vermelho | 3 | Um para LED de status, demais para identificar saídas ativas |
| LED 5 mm Verde | 1 | Cor não crítica, apenas para identificação |
| LED 5 mm Amarelo | 1 | Cor não crítica, apenas para identificação |
| LED Azul | 2 | Cor não crítica, apenas para identificação |
| Protoboard grande (sem solda) | 1 | |
| Fios jumper (genéricos) | 1 conjunto | |
| Chave liga-desliga (SPST) | 1 | Qualquer chave SPST funciona |
| Fonte para protoboard 5V/3.3V (SparkFun) | 1 | Opcional se tiver outra fonte 5V ou usar USB do PC |
| Receptor IR (genérico, ex: KY-022 37.9 kHz) | 1 |
Sobre o Projeto
Este projeto permite reutilizar controles remotos antigos de VCRs, TVs, DVD players, etc. Você pode usá-los para ligar dispositivos como lâmpadas, aquecedores, etc., através de relés, transistores de potência ou qualquer coisa que um sinal de 5V controle. Aqui demonstramos com 6 LEDs.

O sistema lê 6 códigos IR de qualquer controle e os "memoriza". Gosto de usar as teclas 1-6, mas quaisquer seis funcionam. Qualquer outra tecla com código desconhecido atua como reset, desligando todas as saídas. Os códigos são gravados como inteiros longos na EEPROM do Arduino (4 bytes cada). UNO e Nano têm 1024 bytes de EEPROM, espaço de sobra. A memória persiste após resets e desligamentos.

O desafio foi luz ambiente ou sinais fracos. Solução: dobrei o "LED" receptor a ~45° e coloquei uma caixa de papelão/fita com uma extremidade aberta sobre ele. Captura códigos consistentemente a 5-8 metros. Sem falhas em 5+ dias de testes.


Programação (Modo Learn)
Vire a chave para "Learn". O LED vermelho de modo acende, indicando prontidão. O LED 1 pisca; pressione uma tecla no controle. Ao reconhecer o código, o LED de modo pisca rápido (parece vibrar) e avança para o próximo LED. Repete para os 6. Depois, o LED de modo pisca lento (1 seg) indicando para voltar ao modo Run.
Erro comum: esquecer de mudar o dedo para o próximo dígito, programando duas saídas com o mesmo código. Na inicialização, duplicatas são detectadas e os LEDs "ofensores" piscam sugerindo reprogramação (não força, pois pode ser intencional).
Status, erros etc. são indicados pela taxa de pisca do LED vermelho. Tudo também vai para o Monitor Serial, mais fácil que decorar padrões de pisca.
Adendo: Testes com Relés
Testei com 5 relés em paralelo com LEDs 1-5; todos comutam lâmpada 120 VAC. Faltou relé para o 6º, mas deve funcionar. Cuidado com tensão de rede: choque perigoso ou fatal! Usei CD4011 (quad NAND) para inverter sinais das 4 primeiras saídas (fecham em 0V vs 5V). O 5º relé trabalha com +5V, sem inversão.



Código
/* Alterna 6 LEDs usando controle IR para ilustrar reuso de controles
Paul M Dunphy VE1DX - Março 2020 */
#include <IRremote.h>
#include <EEPROM.h>
long unsigned int intIRCode;
long unsigned int savedIRCodes[6];
long unsigned int dupeCheck[6];
const int Recv_Pin = 2;
const int PinOne = 12, PinTwo = 11, PinThree = 10, PinFour = 9, PinFive = 8, PinSix = 7;
const int switchPin = 4, statusPin = 5;
const unsigned long int repeatKeyPress = 0xFFFFFFFF;
boolean learnMode, first_iteration;
int togglestate1=0, togglestate2=0, togglestate3=0, togglestate4=0, togglestate5=0, togglestate6=0;
int current_remote_code;
int remote_code_1, remote_code_2, remote_code_3, remote_code_4, remote_code_5, remote_code_6;
IRrecv irrecv(Recv_Pin);
decode_results results;
void EEPROMWritelong(int address, long value) {
byte four = (value & 0xFF);
byte three = ((value >> 8) & 0xFF);
byte two = ((value >> 16) & 0xFF);
byte one = ((value >> 24) & 0xFF);
EEPROM.write(address, four);
EEPROM.write(address + 1, three);
EEPROM.write(address + 2, two);
EEPROM.write(address + 3, one);
}
long EEPROMReadlong(long address) {
long four = EEPROM.read(address);
long three = EEPROM.read(address + 1);
long two = EEPROM.read(address + 2);
long one = EEPROM.read(address + 3);
return ((four << 0) & 0xFF) + ((three << 8) & 0xFFFF) + ((two << 16) & 0xFFFFFF) + ((one << 24) & repeatKeyPress);
}
int Flip_LED(int led, int toggle_state) {
if(toggle_state==0) { digitalWrite(led, HIGH); toggle_state=1; }
else { digitalWrite(led, LOW); toggle_state=0; }
return toggle_state;
}
void Reset() {
digitalWrite(PinOne, LOW); digitalWrite(PinTwo, LOW); digitalWrite(PinThree, LOW);
digitalWrite(PinFour, LOW); digitalWrite(PinFive, LOW); digitalWrite(PinSix, LOW);
togglestate1=togglestate2=togglestate3=togglestate4=togglestate5=togglestate6=0;
}
void guessType() {
Serial.print("Remote appears to be a ");
switch (results.decode_type){
case NEC: Serial.println("NEC"); break;
case SONY: Serial.println("SONY"); break;
case RC5: Serial.println("RC5"); break;
case RC6: Serial.println("RC6"); break;
case DISH: Serial.println("DISH"); break;
case SHARP: Serial.println("SHARP"); break;
case JVC: Serial.println("JVC"); break;
case SANYO: Serial.println("SANYO"); break;
case MITSUBISHI: Serial.println("MITSUBISHI"); break;
case SAMSUNG: Serial.println("SAMSUNG"); break;
case LG: Serial.println("LG"); break;
case WHYNTER: Serial.println("WHYNTER"); break;
case AIWA_RC_T501: Serial.println("AIWA_RC_T501"); break;
case PANASONIC: Serial.println("PANASONIC"); break;
case DENON: Serial.println("DENON"); break;
default: case UNKNOWN: Serial.println("UNKNOWN"); break;
}
}
int learnCodeRead(int pinCode) {
if (irrecv.decode(&results)) pinCode = results.value;
return pinCode;
}
void Confirm() {
for(int i=0; i<=20; i++) { digitalWrite(statusPin, HIGH); delay(50); digitalWrite(statusPin, LOW); delay(50); }
digitalWrite(statusPin, HIGH);
}
void learn_Mode() {
boolean goodCode; int i, j, location; int pins[6] = {12,11,10,9,8,7};
if (first_iteration) { Serial.println(); Serial.println("Entering learn mode"); Serial.println(); }
intIRCode = 0; location = 0; goodCode = true; j = 0;
while ((goodCode=true) and (j<=5)) {
for(i=0; i<=25; i++) {
digitalWrite(pins[j], HIGH); delay(200);
intIRCode = learnCodeRead(intIRCode);
digitalWrite(pins[j], LOW); delay(200);
intIRCode = learnCodeRead(intIRCode);
goodCode = ((intIRCode != repeatKeyPress) and (intIRCode != 0));
if (goodCode) { i=30; }
irrecv.resume();
}
goodCode = (intIRCode != repeatKeyPress and intIRCode != 0);
if (goodCode) {
if (j==0) guessType();
Serial.print("Writing to EEPROM Location "); Serial.print(location);
Serial.print(" IR code = "); Serial.println(intIRCode, HEX);
EEPROMWritelong(location, intIRCode);
location += 4; j++; Confirm(); intIRCode = 0; irrecv.resume();
}
}
Serial.println(); Serial.println("Put Arduino back in run mode.");
while (digitalRead(switchPin) == HIGH) { digitalWrite(statusPin, HIGH); delay(1000); digitalWrite(statusPin, LOW); delay(1000); }
Serial.println(); Serial.println("Returning to run mode.");
delay(50); Serial.flush(); delay(50); asm volatile (" jmp 0");
}
void run_Mode() {
if (first_iteration) Serial.println("Entering run mode");
if (irrecv.decode(&results)) {
if (results.value != repeatKeyPress) {
current_remote_code = results.value;
Serial.print("Key press detected, IR code = "); Serial.println(current_remote_code, HEX);
if (current_remote_code == remote_code_1) togglestate1 = Flip_LED(PinOne, togglestate1);
else if (current_remote_code == remote_code_2) togglestate2 = Flip_LED(PinTwo, togglestate2);
else if (current_remote_code == remote_code_3) togglestate3 = Flip_LED(PinThree, togglestate3);
else if (current_remote_code == remote_code_4) togglestate4 = Flip_LED(PinFour, togglestate4);
else if (current_remote_code == remote_code_5) togglestate5 = Flip_LED(PinFive, togglestate5);
else if (current_remote_code == remote_code_6) togglestate6 = Flip_LED(PinSix, togglestate6);
else Reset();
}
delay(500); irrecv.resume();
}
}
void setup() {
first_iteration = true;
Serial.begin(9600);
irrecv.enableIRIn();
// Verifica EEPROM nova (0xFFFFFFFF) e define códigos Sony padrão se necessário
boolean defaultToSony = false;
long unsigned int IRCode = 0; int location = 0;
for(int i=0; i<=5; i++) { IRCode = EEPROMReadlong(location); if (IRCode==repeatKeyPress) defaultToSony = true; location += 4; }
if (defaultToSony) {
Serial.println("HEX FFFFFFFF found in EEPROM. Setting codes for Sony RM-YD104.");
EEPROMWritelong(0, 0x10); delay(50);
EEPROMWritelong(4, 0x810); delay(50);
EEPROMWritelong(8, 0x410); delay(50);
EEPROMWritelong(12, 0xC10); delay(50);
EEPROMWritelong(16, 0x210); delay(50);
EEPROMWritelong(20, 0xA10); delay(50);
}
pinMode(PinOne, OUTPUT); pinMode(PinTwo, OUTPUT); pinMode(PinThree, OUTPUT);
pinMode(PinFour, OUTPUT); pinMode(PinFive, OUTPUT); pinMode(PinSix, OUTPUT);
Reset();
pinMode(statusPin, OUTPUT); pinMode(switchPin, INPUT);
// Lê códigos salvos
Serial.println(); Serial.println("Reading stored IR remote codes . . . ");
location = 0;
for(int j=0; j<=5; j++) {
savedIRCodes[j] = EEPROMReadlong(location);
Serial.print("Reading from EEPROM Location "); Serial.print(location);
Serial.print(" IR code = "); Serial.println(savedIRCodes[j], HEX);
location += 4; dupeCheck[j] = savedIRCodes[j];
}
// Verifica duplicatas consecutivas
for (int i = 0; i < 5; i++) {
for (int j = i + 1; j < 6; j++) {
if (dupeCheck[i] == dupeCheck[j]) {
Serial.println("Duplicate codes found. Suggest re-running learn mode");
for(int k=0; k<=5; k++) {
digitalWrite(12+i, HIGH); digitalWrite(12+j, HIGH); delay(1000);
digitalWrite(12+i, LOW); digitalWrite(12+j, LOW); delay(1000);
}
}
}
}
remote_code_1 = savedIRCodes[0]; remote_code_2 = savedIRCodes[1];
remote_code_3 = savedIRCodes[2]; remote_code_4 = savedIRCodes[3];
remote_code_5 = savedIRCodes[4]; remote_code_6 = savedIRCodes[5];
delay(1000); Serial.println("Stored codes read."); Serial.println();
}
void loop() {
learnMode = (digitalRead(switchPin) == HIGH);
if (learnMode) {
first_iteration = true; Reset(); digitalWrite(statusPin, HIGH);
learn_Mode(); Reset(); first_iteration = false;
} else {
digitalWrite(statusPin, LOW); run_Mode(); first_iteration = false;
}
}
Esquemático

Processo de manufatura
- Diodos Emissores de Luz: Da Incepção a Vida Útil de 100 Anos
- Monitoramento Remoto do Tempo com Raspberry Pi 3 e PubNub
- Construa um Controle Remoto Universal Profissional para Raspberry Pi com LIRC
- Sistema Remoto de Monitoramento de Frequência Cardíaca com Alertas AWS IoT
- Projeto Arduino: Melodia Coffin Dance – Construa e Toque a Música Viral
- Transforme Seu Celular Antigo em um Interruptor Remoto Inteligente
- Pintura de Luz com LED Único: Construa Imagens Dinâmicas com Sistema Motorizado DIY
- Display de Luz com 8 LEDs Ativado por Som
- Os 5 Critérios-Chave para Selecionar uma Plataforma de Controle
- Descarte Seguro e Eficiente de Maquinaria Industrial Obsoleta