quinta-feira, 10 de maio de 2018

Arduino Acendendo e Apagando Led com Controle Remoto

Acendendo e Apagando 3 Leds Com Controle Remoto da TV - Infra Vermelho

Indico que assistam a vídeo aula do link abaixo:

Arduino, Utilizando Controle Infra Vermelho

Circuito Montado Conforme Vídeo Aula do Link A Cima:






Código :



/*
 * IRremote: IRrecvDemo - demonstrates receiving IR codes with IRrecv
 * An IR detector/demodulator must be connected to the input RECV_PIN.
 * Version 0.1 July, 2009
 * Copyright 2009 Ken Shirriff
 * http://arcfn.com
 */

#include <IRremote.h>

#define tecla1 0xE0E020DF
#define tecla2 0xE0E0A05F
#define tecla3 0xE0E0609F
#define tecla4 0xE0E010EF
#define tecla5 0xE0E0906F
#define tecla6 0xE0E050AF

#define led1 7
#define led2 6
#define led3 5

int RECV_PIN = 11;

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
}

void loop() {
  if (irrecv.decode(&results)) {
    Serial.println(results.value, HEX);
    switch(results.value)
    {
      case tecla1: digitalWrite(led1, HIGH); break; //tecla 1 liga led 1
      case tecla2: digitalWrite(led2, HIGH); break; //tecla 2 liga led 2
      case tecla3: digitalWrite(led3, HIGH); break; //tecla 3 liga led 3
      case tecla4: digitalWrite(led1, LOW); break;  //tecla 4 apaga led 1
      case tecla5: digitalWrite(led2, LOW); break;  //tecla 5 apaga led 2
      case tecla6: digitalWrite(led3, LOW); break;  //tecla 6 apaga led 3
      }
   
    irrecv.resume(); // Receive the next value
  }
  delay(100);
}

TESTE DO CIRCUITO 







Lendo Controle Remorto (IR) Infra Vermelho Arduino Nano


Sugiro que assintam o Vídeo Abaixo

Arduino - Lendo o Controle Remoto (IR) da sua TV

Link Para Baixar Biblioteca Arduino - IRremote-master.zip

http://bit.ly/1Wm1cec

Circuito Montado Conforme o Vídeo sugerido a cima.






Código Para Carregar No Arduino


/*
 * IRremote: IRrecvDump - dump details of IR codes with IRrecv
 * An IR detector/demodulator must be connected to the input RECV_PIN.
 * Version 0.1 July, 2009
 * Copyright 2009 Ken Shirriff
 * http://arcfn.com
 * JVC and Panasonic protocol added by Kristian Lauszus (Thanks to zenwheel and other people at the original blog post)
 * LG added by Darryl Smith (based on the JVC protocol)
 */

#include <IRremote.h>

int RECV_PIN = 11;

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
}

// Dumps out the decode_results structure.
// Call this after IRrecv::decode()
// void * to work around compiler issue
//void dump(void *v) {
//  decode_results *results = (decode_results *)v
void dump(decode_results *results) {
  int count = results->rawlen;
  if (results->decode_type == UNKNOWN) {
    Serial.print("Unknown encoding: ");
  }
  else if (results->decode_type == NEC) {
    Serial.print("Decoded NEC: ");
  }
  else if (results->decode_type == SONY) {
    Serial.print("Decoded SONY: ");
  }
  else if (results->decode_type == RC5) {
    Serial.print("Decoded RC5: ");
  }
  else if (results->decode_type == RC6) {
    Serial.print("Decoded RC6: ");
  }
  else if (results->decode_type == PANASONIC) {
    Serial.print("Decoded PANASONIC - Address: ");
    Serial.print(results->address,HEX);
    Serial.print(" Value: ");
  }
  else if (results->decode_type == LG) {
     Serial.print("Decoded LG: ");
  }
  else if (results->decode_type == JVC) {
     Serial.print("Decoded JVC: ");

  }
  else if (results->decode_type == AIWA_RC_T501) {
    Serial.print("Decoded AIWA RC T501: ");
  }
  else if (results->decode_type == WHYNTER) {
     Serial.print("Decoded Whynter: ");
  }
  Serial.print(results->value, HEX);
  Serial.print(" (");
  Serial.print(results->bits, DEC);
  Serial.println(" bits)");
  Serial.print("Raw (");
  Serial.print(count, DEC);
  Serial.print("): ");

  for (int i = 0; i < count; i++) {
    if ((i % 2) == 1) {
      Serial.print(results->rawbuf[i]*USECPERTICK, DEC);
    }
    else {
      Serial.print(-(int)results->rawbuf[i]*USECPERTICK, DEC);
    }
    Serial.print(" ");
  }
  Serial.println("");
}


void loop() {
  if (irrecv.decode(&results)) {
    Serial.println(results.value, HEX);
    dump(&results);
    irrecv.resume(); // Receive the next value
  }
}


Foto Capturando os Códigos em Exadecimal do Controle Remoto Samsung






Anotando O Código Capturado para Uso Posterior.

Tecla 1 do Controle Remoto Samsung
E0E020DF (32 bits)

Tecla 2 do Controle Remoto Samsung
E0E0A05F (32 bits)


Tecla 3 do Controle Remoto Samsung
E0E0609F (32 bits)

Observação: Os códigos acima estão relacionados ao controle que utilizo como referência.