sábado, 28 de julio de 2012

Arduino IR Remote Control - Controlar 4 relays con un control remoto Infrerojo

Hoy les traigo un proyecto de como controlar un panel de 4 relays utilizando in control remoto infrarojo ( IR remote control ). se requiere tener la libreria del sensor infrerojo. Nota importante en esta libreria requiere una pequeña modificacion, solo cuando utilizas las verciones nuevas del programa de Arduino 1.0 y 1.0.1 en las anteriores no tendras problemas.

La modificacion consiste en remplazar #include <WProgram.h>
por #include <Arduino.h> en el archivo IRRemoteInt.h.

Si tienen algun problema me abisan, con gusto los ayudare.

 

Enlace: IR Reomote library


Conecciones electricas:
Pin 13 – canal 1
pin 12 – canal 2
pin 11 – canal 3
pin 10 – canal 4

pin 7 – señal del sensor infrarojo

image

Estoy utilizando el Control remoto modelo YK-001, lo pueden conseguir en ebay.com, en la imagen podrán ver los códigos de cada tecla, los necesitaran para su proyecto.

IR CONTROL YK-001 codes

Con el siguiente sketch de Arduino podrán localizar los códigos de otros controles, los códigos los podrán ver en el serial monitor, por si desean utilizar otro diferente:


//apcexpert.blogspot.com
// IR Remote Control Code Finder
#include <IRremote.h>
int RECV_PIN = 7; //define input pin on Arduino
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
}
void loop() {
if (irrecv.decode(&results)) {
  Serial.println(results.value );
  irrecv.resume(); // Receive the next value
}
}


IR Sensor

Para finalizar, el Sketch de Arduino con el cual podremos controlar los cuatro relay como se ve en la imagen superior;


// apcexpert.blogspot.com

#include <IRremote.h>

int RECV_PIN = 7;

int Relay1_PIN = 13;
int Relay2_PIN = 12;
int Relay3_PIN = 11;
int Relay4_PIN = 10;

IRrecv irrecv(RECV_PIN);
decode_results results;

void setup()
{
  pinMode(Relay1_PIN, OUTPUT);
  pinMode(Relay2_PIN, OUTPUT);
  pinMode(Relay3_PIN, OUTPUT);
  pinMode(Relay4_PIN, OUTPUT);
 
  pinMode(6, OUTPUT);
  irrecv.enableIRIn(); // Start the receiver
}

int on = 1;


void loop() {
  if (irrecv.decode(&results)) {
    if (results.value == 16724175) { // YK-001 button 1
       {
        on = !on;
        digitalWrite(Relay1_PIN, on ? HIGH : LOW);
      }
     }
{
    if (results.value == 16718055) { // YK-001 button 2
     
       {
        on = !on;
        digitalWrite(Relay2_PIN, on ? HIGH : LOW);
      }
      }   
  {
    if (results.value == 16743045) { // YK-001 button 3
     {
        on = !on;
        digitalWrite(Relay3_PIN, on ? HIGH : LOW);
      }
     }   
  {
    if (results.value == 16716015) { // YK-001 button
     {
        on = !on;
        digitalWrite(Relay4_PIN, on ? HIGH : LOW);
      }
     }     
    irrecv.resume(); // Receive the next value
  }
}}}}


Espero que no tengan problemas, pero de tenerlos pueden comunicarse y con gusto los ayudare en lo posible. Hasta la próxima.

No hay comentarios.: