Clonando Infravermelho de Controle Remoto

Neste projeto estou montando alguns testes para clonar algumas funções dos controles remotos da sala da minha casa.

Meu primeiro teste foi realizando o algoritmo deste site.

Montei o seguinte esquema elétrico.

O código para receber o sinal.

No console do IDE ele vai imprimir o conteúdo da função do próximo algoritmo.

/*
  Raw IR decoder sketch!
  Code is public domain, check out www.ladyada.net and adafruit.com for more tutorials!
*/
#define IRpin_PIN PIND
#define IRpin 2

// => The maximum pulse we'll listen for - 65 milliseconds is a long time
#define MAXPULSE 65000

// => What our timing resolution should be, larger is better
// => as its more 'precise' - but too large and you wont get accurate timing
#define RESOLUTION 20

// => We will store up to 100 pulse pairs (this is -a lot-)
uint16_t pulses[100][2]; // => Pair is high and low pulse
uint8_t currentpulse = 0; // => Index for pulses we're storing

void setup(void) {
  Serial.begin(9600);
  Serial.println("Ready to decode IR!");
}

void loop(void) {
  uint16_t highpulse, lowpulse; // Temporary storage timing
  highpulse = lowpulse = 0; // Start out with no pulse length
  while (IRpin_PIN & _BV(IRpin)) {
    highpulse++; // => count off another few microseconds
    delayMicroseconds(RESOLUTION);
    // => If the pulse is too long, we 'timed out' - either nothing was received or
    // => the code is finished, so print what we've grabbed so far, and then reset
    if ((highpulse >= MAXPULSE) && (currentpulse != 0)) {
      printpulses();
      currentpulse = 0;
      return;
    }
  }
  // => We didn't time out so lets stash the reading
  pulses[currentpulse][0] = highpulse;
  // => Same as above
  while (! (IRpin_PIN & _BV(IRpin))) {
    lowpulse++; // => Pin is still LOW
    delayMicroseconds(RESOLUTION);
    if ((lowpulse >= MAXPULSE) && (currentpulse != 0)) {
      printpulses();
      currentpulse = 0;
      return;
    }
  }
  pulses[currentpulse][1] = lowpulse;
  // => We read one high-low pulse successfully, continue!
  currentpulse++;
}

void printpulses(void) {
  Serial.println("\n\r\n\r Received: \n\r OFF \t ON");
  for (uint8_t i = 0; i < currentpulse; i++) { // => Generate.
    Serial.print("delayMicroseconds(");
    Serial.print(pulses[i][0] * RESOLUTION, DEC);
    Serial.print(");\n");
    Serial.print("pulseIR(");
    Serial.print(pulses[i][1] * RESOLUTION, DEC);
    Serial.print(");\n");
  }
}

Este é o código para enviar o sinal.

Copie a parte do “delayMicroseconds” e “pulseIR” do console do algoritmo anterior e passe para este abaixo.

Carregue em seu Arduino, aponte o LED para seu aparelho e verifique se esta funcionando corretamente. O Sinal é enviado de forma constinua, então seria como se ficar apertando o botão constantemente do aparelho.

// This sketch will send out a Nikon D50 trigger signal (probably works with most Nikons)
// See the full tutorial at http://www.ladyada.net/learn/sensors/ir.html
// this code is public domain, please enjoy!

int IRledPin =  3; // => LED connected to digital port
const int button = 4;
int state_button = 0;

void setup()   {
  pinMode(IRledPin, OUTPUT); // => Initialize the IR digital pin as an output:
  pinMode(button, INPUT);
  Serial.begin(9600);
}

void loop(){
  state_button = digitalRead(button);
  if (true || state_button == HIGH) {
    Serial.println("Sending IR signal");
    SendVolumeUpCode();
    changeToChromecast();
  }
  delay(500);
}

// This procedure sends a 38KHz pulse to the IRledPin
// for a certain # of microseconds. We'll use this whenever we need to send codes
void pulseIR(long microsecs) {
  // we'll count down from the number of microseconds we are told to wait
  cli();  // => this turns off any background interrupts
  while (microsecs > 0) {
    // 38 kHz is about 13 microseconds high and 13 microseconds low
    digitalWrite(IRledPin, HIGH);  // => this takes about 3 microseconds to happen
    delayMicroseconds(10);         // => hang out for 10 microseconds
    digitalWrite(IRledPin, LOW);   // => this also takes about 3 microseconds
    delayMicroseconds(10);         // => hang out for 10 microseconds
    microsecs -= 26; // => so 26 microseconds altogether
  }
  sei(); // => this turns them back on
}

void SendVolumeUpCode() {
  delayMicroseconds(59268);
  pulseIR(4680);
  delayMicroseconds(4660);
  pulseIR(580);
  delayMicroseconds(1720);
  pulseIR(580);
  delayMicroseconds(1740);
  pulseIR(580);
  delayMicroseconds(1740);
  pulseIR(560);
  delayMicroseconds(560);
  pulseIR(600);
  delayMicroseconds(580);
  pulseIR(580);
  delayMicroseconds(580);
  pulseIR(580);
  delayMicroseconds(540);
  pulseIR(600);
  delayMicroseconds(580);
  pulseIR(580);
  delayMicroseconds(1740);
  pulseIR(580);
  delayMicroseconds(1740);
  pulseIR(560);
  delayMicroseconds(1720);
  pulseIR(600);
  delayMicroseconds(580);
  pulseIR(580);
  delayMicroseconds(580);
  pulseIR(560);
  delayMicroseconds(580);
  pulseIR(580);
  delayMicroseconds(560);
  pulseIR(600);
  delayMicroseconds(580);
  pulseIR(560);
  delayMicroseconds(1720);
  pulseIR(600);
  delayMicroseconds(1740);
  pulseIR(580);
  delayMicroseconds(1740);
  pulseIR(580);
  delayMicroseconds(560);
  pulseIR(580);
  delayMicroseconds(560);
  pulseIR(600);
  delayMicroseconds(580);
  pulseIR(580);
  delayMicroseconds(540);
  pulseIR(600);
  delayMicroseconds(580);
  pulseIR(580);
  delayMicroseconds(580);
  pulseIR(580);
  delayMicroseconds(580);
  pulseIR(580);
  delayMicroseconds(580);
  pulseIR(560);
  delayMicroseconds(1740);
  pulseIR(580);
  delayMicroseconds(1720);
  pulseIR(600);
  delayMicroseconds(1740);
  pulseIR(560);
  delayMicroseconds(1740);
  pulseIR(580);
  delayMicroseconds(1740);
  pulseIR(580);
  delayMicroseconds(48400);
  pulseIR(4680);
  delayMicroseconds(4660);
  pulseIR(580);
  delayMicroseconds(1720);
  pulseIR(580);
  delayMicroseconds(1760);
  pulseIR(560);
  delayMicroseconds(1740);
  pulseIR(580);
  delayMicroseconds(580);
  pulseIR(580);
  delayMicroseconds(580);
  pulseIR(560);
  delayMicroseconds(580);
  pulseIR(580);
  delayMicroseconds(580);
  pulseIR(580);
  delayMicroseconds(580);
  pulseIR(580);
  delayMicroseconds(1740);
  pulseIR(560);
  delayMicroseconds(1740);
  pulseIR(580);
  delayMicroseconds(1740);
  pulseIR(580);
  delayMicroseconds(580);
  pulseIR(560);
  delayMicroseconds(580);
  pulseIR(580);
  delayMicroseconds(580);
  pulseIR(580);
  delayMicroseconds(560);
  pulseIR(600);
  delayMicroseconds(580);
  pulseIR(560);
  delayMicroseconds(1740);
  pulseIR(580);
  delayMicroseconds(1740);
  pulseIR(580);
  delayMicroseconds(1740);
  pulseIR(560);
  delayMicroseconds(580);
  pulseIR(580);
  delayMicroseconds(560);
  pulseIR(600);
  delayMicroseconds(580);
  pulseIR(580);
  delayMicroseconds(580);
  pulseIR(560);
  delayMicroseconds(560);
  pulseIR(600);
  delayMicroseconds(580);
  pulseIR(580);
  delayMicroseconds(580);
  pulseIR(560);
  delayMicroseconds(600);
  pulseIR(560);
  delayMicroseconds(1740);
  pulseIR(580);
  delayMicroseconds(1740);
  pulseIR(580);
  delayMicroseconds(1740);
  pulseIR(580);
  delayMicroseconds(1720);
  pulseIR(580);
  delayMicroseconds(1740);
  pulseIR(580);
}

Nos meus testes, consegue fazer funcionar para somente alguns comandos. Em outros simplesmente ele não funcionou de acordo, mas já foi um aprendizado sobre o funcionar do LED e do receptor.

Novo teste usando Bibliotecas.

— Ainda sendo implementado.

Qualquer dúvida ou dicas, entre em contato: leandrolt@gmail.com

Leave a Reply

Your email address will not be published. Required fields are marked *