hello friend how are have this problem I need help I am creating a code which works but I have a little problem that I have divided my work into 3 parts
1-) by infrared control my air conditioner
2) remote control for the lights in my house (control infrared tv)
3) controlled via web interface (php and serial port) the lights and the air conditioner from anywhere by internet.
works fine the first time, but when I send the signal to the IR LED connected to the Arduino pin 3 to turn on my air control with the party in control of my tv stops working. I have to manually reset the arduino mind to run all over again
/*
-Codigo Control Home..
-Email: greber.roamir@gmail.com
-Pin 3 controla el led IR
-Pine Receptor vout 12
Gnd Gnd
Vcc +5v
*/
#include <IRremote.h>
int RECV_PIN = 12;
int PIN_11 = 11;
int PIN_10 = 10;
int PIN_9 = 9;
int PIN_8 = 8;
int PIN_7 = 7;
int PIN_6 = 6;
int PIN_5 = 5;
int PIN_4 = 4;
int PIN_3 = 3;
int PIN_2 = 2;
int BAUD_RATE = 9600;
IRsend irsend; // Se conecta el pin # 3 Led IR
IRrecv irrecv(RECV_PIN);
decode_results results;
///////////////////////////////////////////////////////////////////// Codigo de Control de Aire Acondicionado por Infrarojo
unsigned int powerOn[22] = {
850,800,1700,800,850,1650,850,800,900,750,900,800,1700,1600,1750,1600,1700,1650,850,};
unsigned int powerOff[22] = {
850,800,1700,800,850,1650,850,800,900,750,900,800,1700,1600,1750,1600,1700,1600,900,};
unsigned int temp1[22] = {
900,800,850,800,1700,1650,900,750,850,800,900,800,850,800,1700,800,850,1650,1700,1600,900,};
unsigned int temp2[22] = {
900,750,1750,750,900,1600,900,800,850,800,900,750,900,800,1700,800,850,1650,850,800,1700,};
void setup()
{
pinMode(11, OUTPUT);
pinMode(10, OUTPUT);
pinMode(9, OUTPUT);
pinMode(8, OUTPUT);
pinMode(7, OUTPUT);
pinMode(6, OUTPUT);
pinMode(5, OUTPUT);
pinMode(4, OUTPUT);
pinMode(2, OUTPUT);
Serial.begin(BAUD_RATE);
{
irrecv.enableIRIn(); // Inicio del Receptor
}
}
int on = 1;
void loop(){
cmd();
ctl();
}
/////////////////////////////////////////////////////////////////////
void cmd()
{
if (Serial.available() > 0) {
int command = Serial.read();
if (command == 'w') {
irsend.sendRaw(powerOn,22,38); // Para enviar señal IR al Presionar en consola serial "w" Power ON
Serial.println("LED ON");
}
else if (command == 'x') {
irsend.sendRaw(powerOff,22,38); // Para enviar señal IR al Presionar en consola serial "x" Power OFF
Serial.println("LED OFF");
}
else if (command == 'y') {
irsend.sendRaw(temp1,22,38); // Para enviar señal IR al Presionar en consola serial "y" Temp Up
Serial.println("LED ON");
}
else if (command == 'z') {
irsend.sendRaw(temp2,22,38); // Para enviar señal IR al Presionar en consola serial "z" Temp Down
Serial.println("LED OFF");
/////////////////////////////////////////////////////////////////////
}
else if (command == 'a') {
digitalWrite(2, HIGH);
Serial.println("LED ON");
}
if (command == 'b') {
digitalWrite(2, LOW);
Serial.println("LED OFF");
}
else if (command == 'c') {
digitalWrite(4, HIGH);
Serial.println("LED ON");
}
if (command == 'd') {
digitalWrite(4, LOW);
Serial.println("LED OFF");
}
else if (command == 'e') {
digitalWrite(5, HIGH);
Serial.println("LED ON");
}
if (command == 'f') {
digitalWrite(5, LOW);
Serial.println("LED OFF");
}
else if (command == 'g') {
digitalWrite(6, HIGH);
Serial.println("LED ON");
}
if (command == 'h') {
digitalWrite(6, LOW);
Serial.println("LED OFF");
}
else if (command == 'i') {
digitalWrite(7, HIGH);
Serial.println("LED ON");
}
if (command == 'j') {
digitalWrite(7, LOW);
Serial.println("LED OFF");
}
else if (command == 'k') {
digitalWrite(8, HIGH);
Serial.println("LED ON");
}
if (command == 'l') {
digitalWrite(8, LOW);
Serial.println("LED OFF");
}
else if (command == 'm') {
digitalWrite(9, HIGH);
Serial.println("LED ON");
}
if (command == 'n') {
digitalWrite(9, LOW);
Serial.println("LED OFF");
}
else if (command == '0') {
digitalWrite(10, HIGH);
Serial.println("LED ON");
}
if (command == 'p') {
digitalWrite(10, LOW);
Serial.println("LED OFF");
}
else if (command == 'q') {
digitalWrite(11, HIGH);
Serial.println("LED ON");
}
if (command == 'r') {
digitalWrite(11, LOW);
Serial.println("LED OFF");
}
}
}
void ctl() {
if(irrecv.decode(&results)) {
if (results.value == 33431775) { // Codigo IR Control Infrarojo Tecla # 1
{
on = !on;
digitalWrite(2, on ? HIGH : LOW);
}
}
{
if (results.value == 33464415) { // Codigo IR Control Infrarojo Tecla # 2
{
on = !on;
digitalWrite(4, on ? HIGH : LOW);
}
}
{
if (results.value == 33448095) { // Codigo IR Control Infrarojo Tecla # 3
{
on = !on;
digitalWrite(5, on ? HIGH : LOW);
}
}
{
if (results.value == 33480735) { // Codigo IR Control Infrarojo Tecla # 4
{
on = !on;
digitalWrite(6, on ? HIGH : LOW);
}
}
{
if (results.value == 33427695) { // Codigo IR Control Infrarojo Tecla # 5
{
on = !on;
digitalWrite(7, on ? HIGH : LOW);
}
}
{
if (results.value == 33460335) { // Codigo IR Control Infrarojo Tecla # 6
{
on = !on;
digitalWrite(8, on ? HIGH : LOW);
}
}
{
if (results.value == 33444015) { // Codigo IR Control Infrarojo Tecla # 6
{
on = !on;
digitalWrite(9, on ? HIGH : LOW);
}
}
irrecv.resume(); // Recibe Proximo valor
}
}
}
}
}
}
}
}