IR remote signals

Hi,
i want to control the AC of my university for a project. I’m using an arduino uno wifi.
My code works great without blynk. When i use blynk i can see via a camera that my leds blink but the AC doesn’t respond. Any thoughts?

#include <BlynkSimpleWifiLink.h>
#include <IRLibSendBase.h>    //We need the base code
#include <IRLib_HashRaw.h>    //Only use raw sender
#include <TimeLib.h>
#include <Time.h>
#include <TimeAlarms.h>
IRsendRaw irsend;

char auth[] = "xxxx...";

.
char ssid[] = "cs-wireless";
char pass[] = "";


const int sensorPin = A3;
float temperature;
const float baselineTemp = 10.0;
const float baselineTemp2 = 15.0;
const long interval = 60000;
unsigned long previousMillis = 0;
unsigned long time;
unsigned long previousTime = 0;

const PROGMEM unsigned int rawOnAuto24[200] = {4309, 4480, 491, 1600, 512, 555, 512, 1600, 512, 1621, 512, 533, 512, 555, 512, 1600, 533, 555, 533, 533, 512, 1643, 512, 533, 512, 576, 512, 1600, 512, 1643, 512, 533, 533, 1621, 512, 555, 512, 555, 512, 533, 512, 1643, 512, 1621, 512, 1643, 533, 1621, 512, 1621, 512, 1621, 512, 1600, 512, 1643, 512, 555, 512, 555, 512, 533, 512, 555, 512, 533, 512, 555, 512, 1600, 512, 576, 512, 533, 512, 1643, 512, 533, 512, 555, 512, 533, 512, 1643, 512, 533, 512, 1621, 512, 1600, 512, 576, 512, 1600, 512, 1621, 512, 1621, 512, 5205, 4288, 4480, 512, 1621, 512, 555, 512, 1600, 512, 1621, 512, 533, 512, 555, 533, 1600, 512, 555, 512, 533, 512, 1621, 533, 533, 512, 555, 512, 1600, 512, 1621, 533, 533, 512, 1643, 533, 512, 555, 512, 512, 533, 533, 1621, 533, 1621, 533, 1600, 512, 1643, 533, 1600, 512, 1643, 533, 1621, 533, 1600, 533, 555, 533, 533, 533, 533, 533, 555, 533, 512, 512, 555, 533, 1579, 533, 555, 512, 512, 533, 1621, 533, 512, 533, 555, 533, 533, 512, 1600, 533, 512, 533, 1621, 533, 1579, 533, 533, 533, 1579, 533, 1621, 533, 1621, 533};
const PROGMEM unsigned int rawOnAuto25[200] = {4352, 4395, 576, 1536, 576, 512, 576, 1536, 576, 1579, 576, 491, 555, 512, 576, 1557, 576, 512, 576, 469, 576, 1579, 576, 469, 555, 512, 555, 1557, 555, 1600, 555, 512, 576, 1557, 555, 491, 555, 512, 555, 491, 555, 1600, 555, 1557, 555, 1600, 555, 1600, 555, 1579, 555, 1600, 555, 1557, 555, 1600, 555, 491, 555, 512, 555, 491, 555, 512, 555, 491, 555, 1600, 555, 1579, 555, 533, 555, 491, 555, 1600, 555, 512, 533, 533, 555, 491, 555, 533, 555, 512, 555, 1600, 555, 1579, 555, 533, 555, 1579, 555, 1600, 555, 1579, 555, 5184, 4352, 4416, 555, 1579, 555, 533, 555, 1579, 555, 1600, 555, 491, 555, 533, 555, 1579, 555, 533, 533, 512, 555, 1600, 555, 491, 555, 533, 555, 1579, 555, 1600, 555, 512, 555, 1600, 555, 491, 576, 491, 555, 512, 533, 1600, 555, 1600, 555, 1579, 555, 1600, 555, 1579, 533, 1600, 555, 1600, 533, 1579, 533, 533, 533, 512, 533, 512, 533, 533, 533, 512, 533, 1600, 533, 1600, 533, 512, 555, 512, 533, 1600, 533, 512, 533, 533, 533, 512, 533, 533, 533, 512, 533, 1600, 533, 1579, 555, 533, 533, 1579, 533, 1621, 533, 1600, 533};
const PROGMEM unsigned int rawOff[200] = {4245, 4501, 512, 1621, 512, 576, 512, 1621, 491, 1643, 512, 555, 512, 576, 512, 1621, 512, 576, 512, 533, 491, 1621, 533, 533, 512, 555, 491, 1621, 512, 1621, 512, 555, 512, 1643, 491, 555, 512, 1643, 512, 1621, 512, 1621, 512, 1621, 512, 555, 491, 1643, 512, 1600, 512, 1621, 512, 555, 512, 555, 512, 533, 512, 555, 512, 1600, 512, 576, 512, 533, 512, 1643, 512, 1600, 512, 1621, 512, 533, 512, 555, 512, 533, 512, 555, 512, 533, 512, 555, 533, 533, 512, 555, 512, 1621, 512, 1643, 512, 1600, 512, 1621, 512, 1600, 512, 5205, 4309, 4459, 512, 1621, 512, 555, 512, 1621, 512, 1621, 512, 533, 512, 555, 512, 1621, 512, 576, 512, 533, 533, 1621, 512, 555, 512, 555, 512, 1600, 512, 1621, 512, 533, 512, 1643, 512, 533, 533, 1600, 512, 1643, 512, 1621, 512, 1643, 512, 533, 512, 1643, 512, 1621, 512, 1643, 512, 576, 512, 533, 512, 533, 512, 576, 512, 1621, 512, 555, 512, 533, 512, 1621, 512, 1621, 512, 1600, 512, 576, 491, 555, 512, 533, 512, 555, 512, 533, 512, 576, 512, 512, 533, 555, 512, 1600, 512, 1643, 512, 1621, 512, 1643, 491, 1643, 512, 1398078};

BlynkTimer timer;

void myTimerEvent()
{
  Blynk.virtualWrite(V5, temperature);
}

void setup()
{
  // Debug console
  Serial.begin(9600);

  Blynk.begin(auth, ssid, pass);

  timer.setInterval(15000L, myTimerEvent);
}


BLYNK_WRITE(V1) {
  int rawOnAuto24 = param.asInt();
  if (rawOnAuto24 == 1) {
    irsend.send(rawOnAuto24, 200, 36);
    Serial.println("Anoikse to klimatistiko!!");
  }
  else {
    irsend.send(rawOff, 200, 36);
    Serial.println("Ekleise to klimatistiko!!");
  }
}

BLYNK_WRITE(V2) {
  unsigned long currentMillis = millis();
  int rawOnAuto24 = param.asInt();
  if (temperature > baselineTemp) {
    if ((unsigned long)(currentMillis - previousMillis) >= interval) {
      previousMillis = currentMillis; //apo8hkeuei thn teleutaia fora pou stal8hke shma
      irsend.send(rawOnAuto24, 200, 36);
      Serial.println("mphke 1");
    }
  }
  if (temperature < baselineTemp2) {
    irsend.send(rawOff, 200, 36);
    Serial.println("mphke 2");
  }
}

void loop()
{
  unsigned long currentMillis = millis();
  int sensorVal = analogRead(sensorPin);
  Serial.print("Sensor Value: ");
  Serial.print(sensorVal);
  float voltage = sensorVal * 5.0 / 1024.0;
  //voltage /= 1024.0;
  Serial.print(", Volts: ");
  Serial.print(voltage);
  temperature = (voltage - 0.5) * 10.0;
  Serial.print(", Temperature: ");
  Serial.println(temperature);
  Blynk.run();
  timer.run(); // Initiates BlynkTimer
}

Bad loop(), 2 lines max until you become experienced with Blynk. See how it’s really done with the PUSH DATA example.

what leds, where?

i also see some strange things in your code, what i’m not sure what is supposed to do:

the (unsigned long) what it supposed to do? i do not think that is correct…

in main loop you re-declare the variable currentMillis, but not using anywhere

you want to measure temperature, but i do not see any temperaure sensor library included. instead i see you’re calculating the temp based on an analog pin. what sensor are you using?

Thank you for your reply. I would like to add a button with which the AC will open if a certain temperature is reached. For this purpose i have made a button and my question is: Is the procedure of this button automatically running over and over again when called? Or do i have to put it in a loop?

@xenia the following function will permanently check for a button press:

BLYNK_WRITE(Vx){   // button widget on virtual pin number x
 // put your on /off logic in here
}

This is a standalone function, not setup, not loop. Check PUSH_DATA example for general Blynk syntax and the excellent docs.

My leds are on an arduino uno wifi. I send an IR signal. For your second observation, this is used to avoid rollover of the millis() procedure. For your third observation you are right for the variable, thank you. I use a TMP36 sensor which doens’t need any libraries, i think. Thank you for your reply.

I think you didn’t understand my question. I want to have a button which after it is pressed, it will get into an automatic mode where the temperature is checked constantly. If the temperature has reached a certain number, the AC will turn on without pressing the button again.

i know that (currentMillis - previousMillis) >= interval is for rollover protection, but i meant this part:

if ((unsigned long)(currentMillis - previousMillis) >= interval)

is that (unsigned long) a typo or what it does in the if statement?

so, you want a switch, with 2 postion? auto mode and off, or what is the second mode?

Ok that’s a button in switch mode and some temperature control logic (TCL). TCL is done at timed intervals like the PUSH_DATA example.

ONE of the reasons why your code isn’t working is what you’re doing here…

BLYNK_WRITE(V1) {
  int rawOnAuto24 = param.asInt();
  if (rawOnAuto24 == 1) {
    irsend.send(rawOnAuto24, 200, 36);
    Serial.println("Anoikse to klimatistiko!!");
  }
  else {
    irsend.send(rawOff, 200, 36);
    Serial.println("Ekleise to klimatistiko!!");
  }
}

You’ve already declared rawOnAuto24 as an unsigned integer at the top of your code. This makes it a global variable that’s accessible from anywhere within your code. You’ve used it to store the code that will turn your aircon on and set it to 24 degrees.

You’re re-declaring it here then assigning the result of the Blynk Write to this variable, then checking if it’s equal to 1. If it is, you’re then using this value of 1 to send to your IR LED in the next line of code.

So, instead of sending the string of commands that will turn your aircon device on and set it to 24 degrees, you’re sending “1” instead.

Pete.

1 Like

nice catch, @PeteKnight :wink:
probably this is the reason that he sees the led is flashing, but nothing happens on the aircon side. but how on earth can someone see an IR led flashing???

Through a smartphone camera.

how ???

Just open the camera app and point it at the LED.

He says he can see it via a camera. If I hold my TV remote in front of my iPhone I can the IR LED flash when I press a button.

Pete.

wow, i didn’t know this. just tested, it really works (even on android, nah)! …smarter every day, he? :blush:

2 Likes

I knew that too but after i read this https://www.baldengineer.com/arduino-how-do-you-reset-millis.html i decided to do it like that. I want a button on/off and a button for auto mode. And i am a girl :smile:

1 Like

I will try it when i will go to the university. Thank you for your reply.

ok, now i see. sorry!

i’m reading the article, the part with the (currentMillis - previousMillis) >= interval i understand, but i still do not understand what the (unsigned long) does before the (currentMillis - previousMillis) >= interval ?

it re-declares the currentMillis variable when rollover, or what? i never saw such a use case…

Apologies @xenia.
I should have realised from your username that you’re female, but in my sexist mind I tend to assume that most of the nerds that hang-out here are male :wink:

Pete.

1 Like