Arduino AC cooler automation

Thread Starter

visionofast

Joined Oct 17, 2018
106
Hi,
this is a simple project based on IRRemotecontrol library to schedule a samsung AC cooler ON/OFF timing for multiple times.
as you know,AC coolers and many other devices are just able to ON or OFF one time by schedule.so, by the mentioned Ardiono library you can sniff the IR command sent by remote control of your device as a Raw data code, and send it by any scheduled time regularly.
in this case, the AC cooler is scheduled to be ON for 20mins and be OFF for 2.5hrs and the sequence is repeated for 4 times.
the receiver pin is P2 and transmitter pin for arduino UNO is is P3 of Timer2.

Code:
/*
* IRsend: IRRemoteControlDemo - demonstrates receiving/sending IR codes.
* Created by Cristiano Borges - STI - Fatesg
* August, 2017
*/

#include "IRRemoteControl.h"

IRRecv irRecv;
IRSend irSend;

const int IR_RECV_PIN = 2;

const int MAX_IR_BUFFER_LENGTH = 650;
unsigned int irBuffer[MAX_IR_BUFFER_LENGTH];
int currentIrBufferLength = 0;

const int FREQ_KHZ = 40;
unsigned int irSignaloff[]={44, 3956, 3228, 8984, 552, 1528, 548, 500, 540, 492, 524, 516, 524, 516, 524, 516, 524, 516, 524, 516, 524, 516, 524, 1552, 528, 516, 524, 512, 528, 1552, 548, 492, 528, 1552, 548, 1532, 548, 1532, 548, 1532, 548, 1532, 548, 1532, 548, 492, 528, 512, 524, 516, 524, 516, 524, 516, 524, 516, 524, 512, 528, 512, 528, 512, 528, 512, 528, 512, 528, 512, 528, 512, 528, 512, 528, 512, 524, 516, 524, 516, 524, 516, 524, 516, 524, 516, 524, 516, 524, 516, 524, 512, 528, 516, 524, 516, 524, 516, 524, 516, 524, 516, 524, 516, 524, 516, 524, 512, 528, 512, 528, 512, 528, 512, 528, 512, 528, 512, 528, 12128, 3156, 8992, 548, 1532, 528, 512, 528, 512, 528, 512, 528, 512, 528, 512, 528, 512, 528, 512, 528, 512, 524, 1556, 528, 512, 524, 516, 528, 512, 524, 516, 524, 516, 524, 516, 528, 1548, 532, 1548, 528, 1556, 524, 1552, 528, 1556, 524, 1556, 524, 1552, 528, 1556, 524, 1556, 524, 512, 528, 512, 528, 512, 528, 516, 524, 516, 524, 512, 552, 1528, 528, 1556, 524, 512, 528, 512, 528, 512, 552, 488, 552, 488, 552, 488, 552, 1528, 528, 1552, 528, 512, 528, 1552, 528, 512, 528, 1552, 528, 512, 528, 512, 552, 488, 552, 488, 552, 488, 552, 488, 548, 492, 548, 492, 548, 492, 548, 1532, 528, 1552, 528};
unsigned int irSignalon[]={60, 37136, 3204, 8988, 576, 1504, 544, 492, 576, 464, 576, 464, 576, 464, 576, 464, 576, 464, 576, 464, 576, 464, 576, 1504, 524, 516, 576, 464, 576, 464, 572, 1508, 572, 1508, 576, 1504, 576, 460, 576, 1508, 576, 1504, 572, 1504, 576, 1508, 576, 1504, 572, 1504, 576, 1504, 576, 1504, 576, 464, 576, 464, 576, 464, 576, 464, 576, 464, 576, 464, 576, 1504, 576, 1504, 576, 464, 576, 464, 576, 464, 576, 464, 576, 464, 576, 464, 576, 1504, 576, 1504, 576, 464, 576, 1504, 576, 464, 576, 1504, 576, 464, 576, 464, 576, 464, 576, 464, 576, 464, 576, 464, 576, 464, 576, 1504, 576, 1504, 576, 1504, 548, 1532, 548};
int sizeoff=sizeof(irSignaloff);
int sizeon=sizeof(irSignalon);
int chk=1;
void setup() {
//  Serial.begin(9600);
  pinMode(LED_BUILTIN, OUTPUT);
// irRecv.start(IR_RECV_PIN, irBuffer, MAX_IR_BUFFER_LENGTH, currentIrBufferLength);

}
void loop ()
{
while (chk==1) {
//  Serial.println(F("Press the remote control button now - only once"));
//  delay(5000);

// if (currentIrBufferLength > 0) {
//    irRecv.stop(IR_RECV_PIN);
  
//    digitalWrite(LED_BUILTIN, HIGH);
  
//   Serial.println();
//   Serial.print(F("Code: "));
  
  //  for (int i = 0; i < currentIrBufferLength; i++) {
  //    if (i > 0) {
  //      Serial.print(F(", "));
   //   }
  //    Serial.print(irBuffer[i]);
  //  }
  
  //  Serial.println();
  //  Serial.println(F("Sending the code..."));
   // delay(5000);
  
    irSend.sendRaw(irSignaloff, sizeoff, FREQ_KHZ, false);
  
  //  Serial.println(F("Code sent!"));
//   Serial.println();
     delay(5000);
    digitalWrite(LED_BUILTIN, LOW);
    for (int i;i<=4;i++)
    {
    irSend.sendRaw(irSignalon, sizeon, FREQ_KHZ, false);
    irSend.sendRaw(irSignalon, sizeon, FREQ_KHZ, false);
    delay(1000UL * 60 * 20);
irSend.sendRaw(irSignaloff, sizeoff, FREQ_KHZ, false);
irSend.sendRaw(irSignaloff, sizeoff, FREQ_KHZ, false);
delay(1000UL *60 * 60 * 2.5);
    }
    irSend.sendRaw(irSignaloff, sizeoff, FREQ_KHZ, false);
   // irRecv.start(IR_RECV_PIN, irBuffer, MAX_IR_BUFFER_LENGTH, currentIrBufferLength);
   //exit(0);
   break;
}
chk=0;
}
 
Top