Hola buenas,
En primero lugar queria agradecer a toda la comunidad por la ayuda y decir que es mi primer post, entonces, espero haberlo hecho todo bien.
Os planteo rápidamente mi situación:
Tengo varios aires acondicionados (AC) en diferentes cuartos y me gustaría controlarlos. He conseguido copiar los códigos con un receptor IR (KY-022) y enviarlos desde mi Arduino con la biblioteca IRremote mediante un emisor IR (KY-005). Hasta aquí todo perfecto. Consigo encender, apagar y cambiar la temperatura sin problemas.
El problema viene por que no me gustaría tener que comprar un Arduino para controlar cada uno de los AC, me gustaría tener un único Arduino y tener diferentes emisores de IR conectados en diferentes pines PWM de mi Arduino. Por ejemplo, el AC del salón conectado al PIN 3 de mi Arduino, el de la cocina al PIN 5 y el de mi habitación al PIN 6. Así, cuando yo le mande encender el del salón, encienda solo el del salón y no me envíe la señal para todos los demás.
Por defecto, en el programa para enviar los codigos, tienes que conectar el emisor al PIN 3 del Arduino. He estado enredando en el archivo boarddefs.h de la biblioteca IRremote y he encontrado las lineas de código que definen el PIN al que va a ser conectado, osea que podría cambiarlo para otro PIN diferente, pero no se si puedo crear mas PINES para poder conectar varios emisores.
¿Alguien sabe si es posible o voy a tener que comprar un arduino para cada AC?
Os dejo aquí el Sketch con el que copio los códigos por si alguien quiere utilizarlos. El receptor IR es un KY-022 conectado al PIN 2.
#define LEDPIN 11
//you may increase this value on Arduinos with greater than 2k SRAM
#define maxLen 800
volatile unsigned int irBuffer[maxLen]; //stores timings - volatile because changed by ISR
volatile unsigned int x = 0; //Pointer thru irBuffer - volatile because changed by ISR
void setup() {
Serial.begin(9600); //change BAUD rate as required
attachInterrupt(0, rxIR_Interrupt_Handler, CHANGE);//set up ISR for receiving IR signal
}
void loop() {
// put your main code here, to run repeatedly:
delay(1000); // pause 5 secs
if (x) { //if a signal is captured
digitalWrite(LEDPIN, HIGH);//visual indicator that signal received
Serial.println();
Serial.print(F("Raw: (")); //dump raw header format - for library
Serial.print((x - 1));
Serial.print(F(") "));
detachInterrupt(0);//stop interrupts & capture until finshed here
for (int i = 1; i < x; i++) { //now dump the times
if (!(i & 0x1)) Serial.print(F("-"));
Serial.print(irBuffer[i] - irBuffer[i - 1]);
Serial.print(F(", "));
}
x = 0;
Serial.println();
Serial.println();
digitalWrite(LEDPIN, LOW);//end of visual indicator, for this time
attachInterrupt(0, rxIR_Interrupt_Handler, CHANGE);//re-enable ISR for receiving IR signal
}
}
void rxIR_Interrupt_Handler() {
if (x > maxLen) return; //ignore if irBuffer is already full
irBuffer[x++] = micros(); //just continually record the time-stamp of signal transitions
}
Y dejo tambien el Sketch con el cual puedo enviar los codigos que capturó el Sktch anterior. El emisor utilizado es un KY-005 conectado al PIN 3.
/*
* IRremote: IRsendRawDemo - demonstrates sending IR codes with sendRaw
* An IR LED must be connected to Arduino PWM pin 3.
* Version 0.1 July, 2009
* Copyright 2009 Ken Shirriff
* http://arcfn.com
*
* IRsendRawDemo - added by AnalysIR (via www.AnalysIR.com), 24 August 2015
*/
#include <IRremote.h>
IRsend irsend;
int khz = 38; // 38kHz carrier frequency for the NEC protocol
unsigned int irSignal_on[] = {8488, 4220, 492, 564, 512, 1580, 512, 1580, 488, 580, 512, 1588, 484, 584, 516, 1592, 488, 576, 512, 1576, 512, 1556, 536, 1580, 516, 1584, 504, 564, 512, 1588, 516, 1596, 504, 556, 492, 564, 492, 564, 488, 572, 488, 576, 484, 580, 488, 584, 488, 584, 488, 576, 488, 568, 500, 552, 488, 548, 512, 576, 488, 576, 492, 580, 488, 588, 484, 576, 512, 1576, 488, 568, 508, 552, 488, 576, 488, 576, 516, 1592, 484, 588, 504, 560, 512, 1572, 516, 1580, 484, 572, 516, 1584, 488, 576, 488, 584, 488, 588, 484, 576, 488, 568, 504, 548, 488, 572, 488, 576, 488, 576, 492, 580, 488, 588, 488, 572, 488, 568, 484, 548, 508, 576, 484, 580, 484, 580, 488, 580, 492, 584, 488, 572, 488, 568, 488, 564, 516, 1580, 516, 1584, 504, 564, 488, 580, 488, 588, 488, 576, 500, 552, 484, 568, 488, 576, 492, 568, 488, 584, 484, 580, 488, 588, 488, 552, 508, 568, 488, 564, 516, 1580, 516, 1584, 488, 576, 492, 580, 488, 588, 484, 576, 512, 1576, 512, 1580, 512, 1580, 516, 1584, 508, 560, 508, 560, 488, 588, 488, 572, 488, 568, 512, 1580, 508, 1580, 492, 576, 512, 1588, 508, 564, 504, 568, 488, 552, 512, 564, 512, 1580, 504, 552, 516, 1584, 508, 556, 492, 580, 488, 588, 488, 576, 484, 568, 512, 1576, 512, 1584, 488, 576, 504, 536, 540, 1592, 512, 1596, 508, 540, 464};
unsigned int irSignal_off[] = {120, 16088, 8484, 4220, 488, 564, 516, 1556, 536, 1580, 488, 576, 512, 1592, 484, 584, 516, 1592, 488, 572, 516, 1548, 540, 1576, 516, 1580, 512, 1584, 504, 564, 516, 1588, 516, 1592, 508, 556, 508, 544, 488, 568, 488, 548, 512, 580, 484, 580, 488, 580, 488, 588, 488, 572, 488, 568, 488, 568, 484, 576, 488, 576, 484, 580, 488, 584, 484, 588, 488, 572, 516, 1576, 484, 568, 488, 576, 484, 580, 484, 580, 512, 1592, 488, 588, 488, 576, 484, 568, 484, 568, 488, 572, 488, 580, 484, 580, 488, 580, 516, 1596, 512, 1584, 488, 568, 484, 568, 488, 572, 488, 576, 488, 576, 488, 584, 488, 588, 484, 576, 488, 568, 484, 568, 488, 572, 488, 576, 488, 576, 492, 580, 488, 588, 488, 572, 488, 568, 484, 568, 516, 1580, 512, 1588, 484, 580, 488, 584, 488, 588, 484, 576, 488, 568, 484, 568, 488, 548, 512, 576, 488, 576, 488, 584, 488, 588, 484, 576, 488, 568, 484, 568, 516, 1580, 512, 1584, 488, 580, 488, 584, 488, 584, 488, 572, 516, 1576, 484, 568, 488, 576, 512, 1584, 512, 1592, 484, 584, 488, 588, 484, 576, 488, 568, 508, 1576, 516, 1580, 488, 580, 512, 1564, 512, 580, 488, 588, 488, 572, 488, 568, 516, 1576, 484, 572, 512, 1588, 484, 580, 488, 560, 512, 588, 484, 572, 492, 564, 512, 1580, 488, 572, 488, 576, 484, 580, 516, 1588, 516, 1592, 488, 564, 460, 4916, 112};
void setup()
{
Serial.begin(9600);
}
void loop() {
switch (Serial.read()) {
//SI APRIETO 1 ENCIEDE AC
case '1':{
irsend.sendRaw(irSignal_on, sizeof(irSignal_on) / sizeof(irSignal_on[0]), khz); //Note the approach used to automatically calculate the size of the array.
Serial.println("ON");
break;
}
//SI APRIETO 2 APAGA AC
case '2':{
irsend.sendRaw(irSignal_off, sizeof(irSignal_off) / sizeof(irSignal_off[0]), khz); //Note the approach used to automatically calculate the size of the array.
Serial.println("OFF");
break;
}
}
}