IR remote control

I want when it passes 30 degrees Celsius to perform the command once.
When it goes down to 25 degrees Celsius to do the same.
As I have done it executes the command continuously.

if (rtc.getTemp() - 18.7 >= 30) {
digitalWrite(relay, LOW);
irsend.sendRaw(power, 67, 32);
digitalWrite(relay, HIGH);
delay(500);
}

if (rtc.getTemp() - 18.7 <= 25) {
digitalWrite(relay, LOW);
irsend.sendRaw(power, 67, 32);
digitalWrite(relay, HIGH);
delay(500);
}

Is this an informative post?

arduino_new:
Is this an informative post?

Sorry. Did I make a mistake? I have a problem and I asked to help anyone who knows.

The code you posted does not exhibit any obvious problems to me. Perhaps the problem is in the code you didn't post.

I guess that you have "reset" your system else where when the value is not within your boundaries.

Please post your whole code in code tags so it looks like this:

//your code here

P/S: do not take a picture of your code, it seems stupid.

execution once when the value is the same.... :confused:

#include <LiquidCrystal.h>
#include <DS3231.h>
#include <Wire.h>
#include <VirtualWire.h>
#include <PinChangeInterruptHandler.h>
#include <IRremote.h>
#include <Keypad.h>


DS3231  rtc(SDA, SCL); //real time clock connect
#define DS3231_I2C_ADDRESS 104
byte seconds, minutes, hours, day, date, month, year;
#define NODE_ID          0
#define RELAY_ON 0
#define RELAY_OFF 1

unsigned int power[] = {8930, 4462, 574, 554, 570, 530, 598, 1654,
                        574, 526, 598, 526, 574, 554, 574, 526,
                        598, 526, 574, 1654, 598, 1654, 574, 530,
                        594, 1658, 574, 1654, 574, 1650, 602, 1654,
                        574, 1654, 574, 554, 570, 530, 598, 1654,
                        574, 526, 598, 526, 574, 554, 570, 530,
                        598, 526, 574, 1654, 598, 1654, 574, 526,
                        598, 1658, 570, 1658, 570, 1654, 602, 1654,
                        574, 1654, 574, 1000
                       };

IRsend irsend;

int val ;
int x = 0;
int y = 0;
int z = 0;
int BZ = 12;
int relay = 45;
int LEDKEYPAD = 10;
int menu = 0;
int p = 0;
int A = 0;
int hourupg;
int minupg;
int yearupg;
int monthupg;
int dayupg;
int secupg;
int i = 0;
int b = 0;
int pausa = 1;
byte tMSB, tLSB; // temperature bytes here
float temp3231;   // not used
LiquidCrystal lcd(4, 5, 6, 7, 8, 11);
int irf ;

const int OnHour = 20;
const int OnMin = 20;
const int OffHour = 20;
const int OffMin = 50;

char tecla;

const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
//define the cymbols on the buttons of the keypads
char hexaKeys[ROWS][COLS] = {
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'*', '0', '#', 'D'}
};
byte rowPins [ROWS] = {53, 51, 49, 47};
byte colPins [COLS] = {22, 24, 26, 28};
//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
Time  t;




void setup()
{
  lcd.begin(20, 4);
  lcd.clear();
  rtc.begin();  //begin real time clock

  t = rtc.getTime();

  pinMode (9, OUTPUT);  //output used in library
  pinMode (BZ, OUTPUT);  //output used in library
  pinMode (LEDKEYPAD, OUTPUT);  //output used in library
  pinMode (relay, OUTPUT);  //output used in library
  digitalWrite(relay, RELAY_OFF);


}

void loop() {
  t = rtc.getTime();

  char customKey = customKeypad.getKey();


    


  if  (rtc.getTemp() - 18.7  >= 30) {
    digitalWrite(relay, LOW);
    irsend.sendRaw(power, 67, 32);
    digitalWrite(relay, HIGH);
    delay(500);

  }

  if (rtc.getTemp() - 18.7  <= 25) {
    digitalWrite(relay, LOW);
    irsend.sendRaw(power, 67, 32);
    digitalWrite(relay, HIGH);
    delay(500);


  }




  z = 0;
  y = 0;
  tecla = customKeypad.getKey();
  MSNinicio();

  if (tecla) // Check for a valid key.
  {
    switch (tecla)
    {

      case 'A':
        Beep();
        digitalWrite(relay, LOW);
        irsend.sendRaw(power, 67, 32);
        digitalWrite(relay, HIGH);
        delay(10);

        lcd.clear();
        lcd.setCursor (3, 0);
        lcd.print("Air Condition");
        lcd.setCursor (7, 2);
        lcd.print("Open");
        lcd.setCursor (7, 3);
        lcd.print("Close");
        delay(1000);

        lcd.clear();

        break;

    }
  }
}






void ora() {
  while (y < 1)
  {
    tecla = customKeypad.getKey(); //CHOOSE SENSOR
    if (tecla == '1') {
      Beep();
      menu = menu + 1;
      if (menu == 2) {
        p = 1;
      }
      if (menu == 1) {
        p = 0;
      }
    }
    if (menu == 0)
    {
      // Print a message to the LCD.
      lcd.setCursor(0, 0);
      lcd.print("1: RYTHMISI ORAS");
      lcd.setCursor (0, 3);
      lcd.print("D: EXIT");
    }
    if (menu == 1)
    {
      DisplaySetHour();    // set hour
    }
    if (menu == 2)
    {
      DisplaySetMinute();  // set minute
    }
    if (menu == 3)
    {
      DisplaySetDay();      // set day
    }
    if (menu == 4)
    {
      DisplaySetMonth();   // set Month
    }
    if (menu == 5)
    {
      DisplaySetYear();    // set year

      //check error if  min,hour,day,month,year  = 0  print error
      if (minupg <= 0 && hourupg <= 0 && dayupg <= 0 && monthupg <= 0 && yearupg <= 0)
      {
        menu = 0;
        lcd.clear();
        lcd.setCursor(0, 0);
        lcd.print("   ERROR   ");
      }
    }
    if (menu == 6)
    {
      StoreAgg();      //setup time date to DS3231
      delay(500);
      menu = 0;  // return to main menu
      for (i = 0; i < 1; i++) {
        MSNinicio();
        lcd.setCursor (0, 1);
        delay(200);
        lcd.print(i);
      }
      y = 1;
      z = 1;
    }

    if (tecla == 'D') {
      Beep();
      for (i = 0; i < 1; i++) {
        MSNinicio();
        lcd.setCursor (0, 1);
        delay(200);
        lcd.print(i);
        lcd.clear();

      }
      y = 1;
      z = 1;
    }
  }
}



void MSNinicio() {
  lcd.setCursor(0, 0);
  lcd.print("Fv Park  Georgas");

  lcd.setCursor(0, 2);
  lcd.print(rtc.getDateStr());   // Print date to LCD


  lcd.setCursor(0, 3);
  lcd.print(rtc.getTimeStr());



  lcd.setCursor(15, 3);
  lcd.print(rtc.getTemp() - 18.7);




}


void Beep()
{
  digitalWrite(BZ, HIGH);
  digitalWrite(LEDKEYPAD, HIGH);
  delay(50);
  digitalWrite(BZ, LOW);
  digitalWrite(LEDKEYPAD, LOW);
  delay(50);
  digitalWrite(LEDKEYPAD, HIGH);
  delay(50);
  digitalWrite(LEDKEYPAD, LOW);
  delay(50);
  digitalWrite(LEDKEYPAD, HIGH);
  delay(50);
  digitalWrite(LEDKEYPAD, LOW);
  delay(50);
  digitalWrite(LEDKEYPAD, HIGH);
  delay(50);
  digitalWrite(LEDKEYPAD, LOW);
  delay(50);
  digitalWrite(LEDKEYPAD, HIGH);
  delay(50);
  digitalWrite(LEDKEYPAD, LOW);
}


//end of loop

I see when rtc.getTemp() - 18.7 is outside of [25, 30] it does the same one thing. What should happen when the value is inside the range?

Maybe define two flag variables gotHot and gotCold.

bool gotHot = false;
bool gotCold = false;

Then you can check if they are set before performing the code.

   if  (rtc.getTemp() - 18.7  >= 30) {

    // just turning hot?
    if ( !gotHot )
    {
      digitalWrite(relay, LOW);
      irsend.sendRaw(power, 67, 32);
      digitalWrite(relay, HIGH);
      delay(500);
    } // if
    gotHot = true;  // temp is in hot zone
  } else {
    gotHot = false;  // temp not in hot zone
  }

  if (rtc.getTemp() - 18.7  <= 25) {

    // just turning cold?
    if (!gotCold )
    {
      digitalWrite(relay, LOW);
      irsend.sendRaw(power, 67, 32);
      digitalWrite(relay, HIGH);
      delay(500);
    } // if
    gotCold = true;   // temp is in cold zone
  } else {
    gotCold = false;  // temp is not in cold zone
  }
}

Thanks very much ... It works just fine now ... !!!! :slight_smile:
May i ask something last ? If the temperature goes up to 27 Celsius and then goes under 25 Celsious then he execute the command ..
Is there possible do not execute the command that is for the 25 Celsious if he doesn't execute firtst the one that is for the 30 Celsious???

If I understand your question you never want the "cold" action taken unless the "hot" action has been taken.

In that case you could add a variable that is only set to true when the hot action is taken and only do the cold action when that variable is true and the temp is in the cold zone.

Variables:

bool gotHot = false;
bool doCold = false;  // true => ready to do cold action

In loop():

  if  (rtc.getTemp() - 18.7  >= 30) {

    // just turning hot?
    if ( !gotHot )
    {
      digitalWrite(relay, LOW);
      irsend.sendRaw(power, 67, 32);
      digitalWrite(relay, HIGH);
      delay(500);
      doCold = true;  // ready for cold action
    } // if
    gotHot = true;  // temp is in hot zone
  } else {
    gotHot = false;  // temp not in hot zone
  }

  if ( doCold && (rtc.getTemp() - 18.7  <= 25) ) {

    // don't repead cold action
    doCold = false;

    digitalWrite(relay, LOW);
    irsend.sendRaw(power, 67, 32);
    digitalWrite(relay, HIGH);

    delay(500);
  } // if

I have the same problem and i dint find the solution ... This is only for the temperture of 25 Celsious right ??
Is there a way to make it for the two tempertures????

anko1981an:
I have the same problem and i dint find the solution ... This is only for the temperture of 25 Celsious right ??
Is there a way to make it for the two tempertures????

Do not hijack other people's threads. It can become very confusing and the solution for the one problem might not necessarily be the solution for the other problem.

sterretje:
Do not hijack other people's threads. It can become very confusing and the solution for the one problem might not necessarily be the solution for the other problem.

I am sorry for asking in this post but i have the same problem too.
The code is working correctly and i have try it but it works only for the 25 Celsious.
In 30 celsious makes repeats without make it first in 25 Celsious.
I write here because i didnt want to open the same post and confuse the readers ... I am so sorry ....