Blynk Ir Connection - NEED HELP

Hi,

I am trying to switch on my A/C from blynk. When I tested it out without Blynk it worked good, so the Ir codes and Ir led are connected good. The problem is when I put Blynk on top of it, it is not wokring. Here I my code for sending Ir signal

#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
#include <IRremote.h>

char auth[] = "xxxxxxxx";
IRsend irsend;
int khz =38;
unsigned int irTemp17 [] = {3050,1550, 550,1050, 500,1050, 550,250, 550,300, 500,300, 550,1050, 500,300, 550,250, 550,1050, 500,1050, 550,250, 550,1050, 500,300, 550,250, 550,1050, 550,1000, 550,300, 500,1050, 550,1000, 550,300, 500,300, 550,1000, 550,300, 500,300, 550,1050, 500,300, 550,250, 550,300, 500,300, 550,250, 550,300, 500,300, 550,250, 550,300, 500,300, 550,300, 500,300, 550,300, 500,300, 550,250, 550,250, 550,300, 550,1000, 550,300, 500,300, 550,1000, 550,300, 550,250, 550,1000, 550,1050, 550,250, 550,250, 550,300, 550,250, 550,300, 500,300, 550,300, 500,1050, 500,1050, 550,1000, 550,300, 500,300, 550,300, 500,300, 550,1000, 550,300, 500,1050, 550,250, 550,300, 550,250, 550,300, 500,300, 550,250, 550,300, 550,250, 550,250, 550,300, 500,300, 550,300, 500,300, 550,300, 500,300, 550,250, 550,250, 550,300, 550,250, 550,300, 500,300, 550,250, 550,300, 500,300, 550,300, 500,300, 550,250, 550,250, 550,300, 550,250, 550,300, 500,300, 550,250, 550,300, 550,250, 550,250, 550,300, 550,1000, 550,1050, 500,1050, 550,1000, 550,300, 500,300, 550,1000, 550,300, 500};

void setup()
{
  Serial.begin(9600);
  Blynk.begin(auth);
}

BLYNK_WRITE(V12) {
if(param.asInt == HIGH) { 
irsend.sendRaw(irTemp17, sizeof(irTemp17) / sizeof(irTemp17[0]), khz);
}}

void loop()
{
  Blynk.run();
}

Anyone knows what is the problem. Thanks in Advanced…

That looks pretty much OK to me. I used IR with Blynk too to switch on/off my Amplifier and TV and it worked very well. I can’t really see what’s going wrong here. I’m thinking it is a timing issue. I think that @Pavel uses something similar to control his A/C, maybe he knows?

if(param.asInt == 1)

Hi. Thanks for the reply I tried that too instead of high I wrote 1 but it still didnt work

It’s param.asInt() now that you mention it :slight_smile:

HI, thanks for the help but I tried but it still isn,t not working. @Pavel maybe you know

Sorry, have a little time to review your code. Here is my AC controller with Particle Photon. Please also mind that I’m not the best coder in the world. I just make it work and forget )

#include "blynk/blynk.h"
#include "IRTransmitter.h"
#define IR_PIN D6
#define LED_PIN D7


#define BLYNK_PRINT Serial


char auth[] = "************************";
int userTemp = 16; //initial temp
bool acState;



// Raw data can be sniffed using an IR-receiver and e.g. https://github.com/z3t0/Arduino-IRremote/blob/master/examples/IRrecvDumpV2/IRrecvDumpV2.ino
unsigned int onoff[67] = {8950, 4400, 600, 500, 650, 450, 600, 500, 650, 1600, 600, 500, 600, 500, 600, 500, 600, 500, 600, 
                        1600, 650, 500, 600, 1600, 600, 500, 650, 1550, 650, 1600, 650, 1550, 650, 1600, 600, 1600, 600, 
                        500, 600, 500, 650, 500, 600, 1600, 650, 450, 600, 500, 600, 500, 600, 500, 650, 1600, 600, 1600,
                        600, 1650, 600, 500, 600, 1600, 600, 1650, 600, 1600, 600};  // ON OFF
                        
unsigned int up[67] = { 8900, 4450, 600, 500, 650, 450, 650, 450, 650, 1600, 600, 500, 600, 500, 600, 500, 600, 500, 650, 
                        1600, 600, 500, 600, 1600, 600, 500, 600, 1650, 600, 1600, 600, 1600, 650, 1600, 600, 500, 600, 
                        1600, 600, 1650, 600, 1600, 600, 500, 600, 500, 600, 500, 650, 450, 650, 1600, 600, 500, 600, 
                        500, 600, 500, 600, 1600, 650, 1600, 600, 1600, 600, 1600, 650}; // UP

unsigned int down[67] = {8900, 4400, 600, 500, 600, 500, 600, 500, 600, 1600, 650, 450, 650, 500, 600, 500, 600, 500, 600, 
                        1600, 650, 450, 650, 1600, 600, 500, 600, 1600, 650, 1600, 600, 1600, 600, 1600, 650, 1600, 600, 500, 
                        600, 1600, 600, 1650, 600, 500, 600, 500, 600, 500, 600, 500, 600, 500, 600, 1650, 600, 500, 600, 500, 
                        600, 1600, 600, 1650, 600, 1600, 600, 1600, 600}; //down

unsigned int slow[67] = { 9000, 4400, 600, 500, 600, 500, 600, 500, 600, 1600, 650, 
450, 650, 450, 650, 500, 600, 500, 600, 1600, 650, 450, 650, 1600, 600, 500, 600, 1600, 600, 1600, 650, 1600, 600, 1600, 650, 450, 650, 500, 600, 1600, 600, 500, 600, 500, 600, 500, 650, 450, 650, 450, 650, 1600, 600, 1600, 650, 450, 650, 1600, 600, 1600, 600, 1600, 650, 1600, 600, 1600, 600}; //slow

unsigned int fast[67] = { 8900, 4400, 600, 500, 600, 500, 650, 450, 650, 1600, 600, 500, 600, 500, 600, 
500, 600, 500, 650, 1600, 600, 500, 600, 1600, 600, 500, 650, 1600, 600, 1600, 600, 1600, 650, 1600, 600, 1600, 650, 450, 650, 450, 650, 500, 600, 500, 600, 500, 600, 500, 600, 500, 600, 500, 600, 1650, 600, 1600, 600, 1600, 650, 1600, 600, 1600, 600, 1600, 650, 1600, 600}; 

unsigned int cool[67] = {9000, 4350, 650, 500, 600, 500, 600, 500, 600, 1600, 650, 450, 650, 
450, 650, 500, 600, 500, 600, 1600, 600, 500, 650, 1550, 650, 500, 600, 1600, 600, 1600, 650, 1600, 600, 1600, 650, 1600, 600, 500, 600, 500, 600, 1600, 650, 450, 650, 450, 650, 500, 600, 500, 600, 500, 600, 1600, 600, 1650, 600, 500, 600, 1600, 600, 1600, 650, 1600, 600, 1600, 600};

unsigned int eco[67] = {8900, 4400, 600, 500, 600, 500, 600, 500, 650, 1550, 650, 
500, 600, 500, 600, 500, 600, 500, 600, 1600, 650, 450, 650, 1600, 600, 500, 600, 1600, 650, 1600, 600, 1600, 600, 1650, 600, 500, 600, 1600, 600, 500, 600, 500, 650, 450, 650, 450, 650, 500, 600, 500, 600, 1600, 650, 450, 650, 1600, 600, 1600, 600, 1600, 650, 1600, 600, 1600, 650, 1550, 650}; 

unsigned int fan[67] = {8900, 4400, 650, 500, 600, 500, 600, 500, 600, 
1600, 650, 450, 650, 450, 650, 500, 600, 500, 600, 1600, 600, 500, 600, 1650, 600, 500, 600, 1600, 600, 1600, 650, 1600, 600, 1600, 650, 1600, 600, 1600, 600, 1600, 650, 500, 600, 500, 600, 500, 600, 500, 600, 500, 600, 500, 600, 500, 650, 450, 650, 1600, 600, 1600, 600, 1600, 650, 1600, 600, 1600, 600};

unsigned int sleep[67] = {9000, 4400, 600, 500, 650, 450, 600, 
500, 650, 1550, 650, 500, 600, 500, 600, 500, 650, 450, 650, 1550, 650, 450, 650, 1600, 650, 450, 650, 1550, 650, 1600, 600, 1600, 650, 1550, 650, 500, 600, 500, 600, 500, 650, 450, 650, 450, 650, 450, 650, 450, 650, 450, 650, 1600, 650, 1550, 650, 1600, 600, 1600, 650, 1550, 650, 1600, 600, 1600, 650, 1550, 650}; 

unsigned int autofan[67] = {8900, 4450, 600, 500, 600, 500, 650, 450, 650, 
1550, 650, 450, 650, 500, 600, 500, 600, 500, 650, 1550, 650, 450, 650, 1600, 600, 500, 650, 1550, 650, 1600, 600, 1600, 650, 1550, 700, 1550, 650, 1550, 650, 1600, 600, 1600, 650, 450, 650, 450, 650, 450, 650, 450, 650, 500, 600, 500, 600, 500, 650, 450, 650, 1550, 650, 1600, 600, 1600, 650, 1550, 650}; 

unsigned int ONtimer[67] = {8900, 4400, 600, 500, 600, 500, 600, 
500, 600, 1650, 600, 500, 600, 500, 600, 500, 600, 500, 600, 1600, 650, 500, 600, 1600, 600, 500, 600, 1600, 650, 1600, 600, 1600, 650, 1600, 600, 500, 600, 1600, 600, 1650, 600, 500, 600, 500, 600, 500, 600, 500, 600, 500, 600, 1650, 600, 500, 600, 500, 600, 1600, 600, 1650, 600, 1600, 600, 1600, 600, 1650, 600};


IRTransmitter transmitter(IR_PIN, LED_PIN);

void setup()
{
    Serial.begin(9600);
    delay(5000); // Allow board to settle
    Blynk.begin(auth);
}

BLYNK_CONNECTED(){
  RGB.control(true);
  RGB.color(80, 227, 194);
  RGB.brightness(8);
}

void loop() {
    Blynk.run();
}

BLYNK_WRITE(V1) {
    if (param.asInt() == 1) { 
        transmitter.Transmit(onoff, sizeof(onoff) / sizeof(onoff[0]));
        acState = true;
        Blynk.virtualWrite(V17,"ON");
    }
    
    if (param.asInt() == 0) { 
        transmitter.Transmit(onoff, sizeof(onoff) / sizeof(onoff[0]));
        acState = false;
        Blynk.virtualWrite(V17,"OFF");
    }
}

BLYNK_WRITE(V2) {
    
    userTemp = param.asInt();
    int delta = userTemp-16; //22-16 = 6
    
    Blynk.virtualWrite(V6, userTemp);
    
    for (int i = 30; i >= 16; i--){                                 // Since I don't know if the temperature was changed manually,
       transmitter.Transmit(down, sizeof(down) / sizeof(down[0]));  // I always set it to min value (16ºC) and then increase it to a 
       delay(50);                                                   // user defined value
    }
    
    for (int k = 16; k <= userTemp-1; k++ ){
        transmitter.Transmit(up, sizeof(up) / sizeof(up[0]));
        delay(50);
    }
}

BLYNK_WRITE(V3) { // Temp Up
    if (param.asInt()) { 
        transmitter.Transmit(up, sizeof(up) / sizeof(up[0]));
        userTemp = userTemp+1;
        if (userTemp >= 32){
            userTemp = 32;
        }
        Blynk.virtualWrite(V2,userTemp);
        
    }
}

BLYNK_WRITE(V4) { // Temp Down
    if (param.asInt()) { 
        transmitter.Transmit(down, sizeof(down) / sizeof(down[0]));
        userTemp = userTemp-1;
        if (userTemp <= 16){
            userTemp = 16;
        }
        Blynk.virtualWrite(V2,userTemp);
    }
}

BLYNK_WRITE(V7) { // Mode
    if (param[0].asInt() == 1 ) { 
        transmitter.Transmit(cool, sizeof(cool) / sizeof(cool[0]));
    }
    
    if (param[0].asInt() == 2 ) { 
        transmitter.Transmit(eco, sizeof(eco) / sizeof(eco[0]));
    }
    
    if (param[0].asInt() == 3 ) { 
        transmitter.Transmit(fan, sizeof(fan) / sizeof(fan[0]));
    }
}

BLYNK_WRITE(V8) { // decrease fan speed
    if (param.asInt()) { 
        transmitter.Transmit(slow, sizeof(slow) / sizeof(slow[0]));
    }
}

BLYNK_WRITE(V9) { // increase fan speed
    if (param.asInt()) { 
        transmitter.Transmit(fast, sizeof(fast) / sizeof(fast[0]));
    }
}

BLYNK_WRITE(V13) { // Brightness
    RGB.brightness(param.asInt());
}

BLYNK_WRITE(V14) { // trigger cool down scene
    if (param.asInt()){
        Blynk.virtualWrite(V1,1);
        delay(100);
        coolDownScene();
    }
    
}

void coolDownScene(){

    transmitter.Transmit(onoff, sizeof(onoff) / sizeof(onoff[0])); // turning AC on
    delay(100);
    acState = true;
    Blynk.virtualWrite(V17,"ON");
    Blynk.virtualWrite(V14,0); // resetting the button for Alexa

    transmitter.Transmit(cool, sizeof(cool) / sizeof(cool[0])); // switching AC to COOL mode
    delay(100);
    
 
     for (int s = 0; s <= 3; s++){
         transmitter.Transmit(fast, sizeof(fast) / sizeof(fast[0])); //setting fan speed to max
         delay(50);
         //Blynk.virtualWrite(V17,s);
     }
    
    delay(100);
    
     for (int x = 32; x >= 16; x--){
         transmitter.Transmit(down, sizeof(down) / sizeof(down[0]));
         delay(50);
         //Blynk.virtualWrite(V17,x);
    }

    Blynk.virtualWrite(V17,"ON");
    delay(100);
    Blynk.virtualWrite(V2,16);
 
    //Blynk.virtualWrite(V2, 16); // setting the temp to 16ºC
}