Interrupt function, initiated by a push button, trigerring without button press

I am building an interface with my thermostat. To turn on the thermostat when the measured temperature is above a desired temperate in air-conditioning mode, and below a desired temperature when in heater mode. To change the desired temperature, a have two pushbuttons connected to pins 2 and 3 respectively. Each have a 10k pull-up resistor connected to them.

The problem is that the desired temperature appears to be changing on its own with a press of a button. It is not consistent when it changes on its own and Im not sure why its happening. Is there something to do with interrupts which I am not aware of?

Thanks,

#include <LiquidCrystal.h>
#include <dht.h>

dht DHT;

#define DHT11_PIN 8

//timing related variables
unsigned long currentMillis;
unsigned long timeReadDHT = 0;
unsigned long timechangeAC = 0;
unsigned long timeLCD = 0;
unsigned long timeBounce = 0;
unsigned long timeTemp = 0;
unsigned long holdDisplay = 0;
int timerChange = 500;
#define BOUNCE_DURATION 400
#define AntiCyclingHold 120000 //30000=30seconds 60000=1min 180000=3min 300000=5min
bool cycling_timer_flag = LOW;

volatile int desiredTemp = 24; //desired temperature
boolean AC_on = true; //AC or Heating On
int temp = 0; //temperature variabke
int humi = 0; //humidity variable

bool SystemOn = LOW; // check if the system should be sent a high signal to turn it on

// initialize the LCD library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 10, 9);


void setup() {
  //Set up pins
  
  pinMode(13, OUTPUT);
  pinMode(A1, INPUT_PULLUP);

  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);

  // set up the Serial Monitor
  Serial.begin(9600);

  // Print test message to the LCD.
  lcd.print("DHT test");
  Serial.println("DHT TEST Type,\tstatus");

  testDHT(); // testing DHT sensor

}


void loop() {
  bool hold_flag = LOW;
  currentMillis = millis();


  // read temp and humidity
  if ((currentMillis - timeReadDHT) > 2100)
  {
    DHT.read11(DHT11_PIN);
    temp = DHT.temperature;
    humi = DHT.humidity;
    timeReadDHT = millis();
  }

  int luxSEND = -0.066433 * analogRead(A0) + 81.467234; //lux reading

  int changeAC_send = digitalRead(A1);//read button for change between heating and AC

  changeAC_on (changeAC_send); //change between heating and AC

  if ((currentMillis - holdDisplay) >= timerChange) { //delay to display change from AC or Heating longer
    displayReadings(humi, temp, luxSEND, hold_flag); //display on LCD - humidity, temperature, lux, desired temperature
    holdDisplay = millis();
    timerChange = 0;
  }

  attachInterrupt(digitalPinToInterrupt(2), upButtonOn, FALLING);//Up in desired temp
  attachInterrupt(digitalPinToInterrupt(3), downButtonOn, FALLING);//Down in desired temp

if (cycling_timer_flag == HIGH){ //state machine for creating a delay to avoid quick cycling on and off of system
  timeTemp = currentMillis;
  cycling_timer_flag = LOW;
}

  if ((currentMillis - timeTemp) >= AntiCyclingHold) { //state machine for creating a delay to avoid quick cycling on and off of system
    hold_flag = LOW; // for reading out holding of the temp to the LCD
    if ((temp > desiredTemp) && (AC_on == true)) { //Power On to the SystemOn flag in AC structure
      SystemOn = HIGH;
      cycling_timer_flag = HIGH;
      Serial.println("Turned ON");
    }
    else if ((temp < desiredTemp) && (AC_on == false)) { //Power On to the SystemOn flag in Heat Structure
      SystemOn = HIGH;
      cycling_timer_flag = HIGH;
      Serial.println("Turned ON");
    }
    else {
      SystemOn = LOW; //Power Off
      cycling_timer_flag = HIGH;
      Serial.println("Turned OFF");
    }
  }
  else {
    hold_flag = HIGH;
  }


//Structure to keep system on or off depending on the SystemOn flag
  if (SystemOn == HIGH) { 
    digitalWrite(13, HIGH);
  }
  else if (SystemOn == LOW) {
    digitalWrite(13, LOW);
  }
}

//Function to display readings to LCD
void displayReadings (int h, int t, int lux, bool hold_flag_received) {

  if ((currentMillis - timeLCD) > 300) { //refresh every 1/3 second

    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("T:");
    lcd.print(t);
    lcd.print((char)223);
    lcd.print("C ");
    lcd.print("DesT:");
    lcd.print(desiredTemp);
    lcd.print((char)223);
    lcd.print("C");

    lcd.setCursor(0, 1);
    lcd.print("H:");
    lcd.print(h);
    lcd.print("% ");
    lcd.print("LUX:");
    lcd.print(lux);
    lcd.print(" ");
    if (hold_flag_received == HIGH){
    lcd.print("HOLD"); 
    }

    Serial.print(h, 1);
    Serial.print(",\t");
    Serial.print(t, 1);
    Serial.print(",\t");
    Serial.print(lux);
    Serial.println(",\t");

    timeLCD = millis();
  }

}

//Function to test if temp/humidity sensor is working - only called in setup()
void testDHT () {
  // READ DATA
  lcd.clear();
  Serial.print("DHT11, \t");
  int chk = DHT.read11(DHT11_PIN);
  switch (chk)
  {
    case DHTLIB_OK:
      Serial.println("OK,\t");
      break;

    case DHTLIB_ERROR_CHECKSUM:
      Serial.print("Checksum error,\t");
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("Can't get reading");
      lcd.setCursor(0, 1);
      lcd.print("from DHT");
      break;

    case DHTLIB_ERROR_TIMEOUT:
      Serial.print("Time out error,\t");
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("Can't get reading");
      lcd.setCursor(0, 1);
      lcd.print("from DHT");
      break;

    default:
      Serial.print("Unknown error,\t");
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("Can't get reading");
      lcd.setCursor(0, 1);
      lcd.print("from DHT");
      break;
  }
}

//Function to increase desired temperature on button press
void upButtonOn () {
  if ((currentMillis - timeBounce) > BOUNCE_DURATION) {
    Serial.println("Up Pressed");
    desiredTemp++;
    timeBounce = millis();
    
    timeTemp = (currentMillis - (AntiCyclingHold + 300));
    cycling_timer_flag = LOW;
  }
}

//Function to decrease desired temperature on button press
void downButtonOn () {
  if ((currentMillis - timeBounce) > BOUNCE_DURATION) {
    Serial.println("Down Pressed");
    desiredTemp--;
    timeBounce = millis();
    
    timeTemp = (currentMillis - (AntiCyclingHold + 300));
    cycling_timer_flag = LOW;
  }

}

//Function to switch from AC mode to Heating mode
void changeAC_on (int changeAC) {

  if (currentMillis - timechangeAC >= 300) {

    if ((changeAC == LOW) && (AC_on == true)) {
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("HEATING MODE");
      Serial.println("Heat On");
      AC_on = false;
      timechangeAC = millis();
      holdDisplay = currentMillis;
      timerChange = 1000;
    }

    else if ((changeAC == LOW) && (AC_on == false)) {
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("A/C MODE");
      Serial.println("A/C On");
      AC_on = true;
      timechangeAC = millis();
      holdDisplay = currentMillis;
      timerChange = 1000;

    }

    else {
      timechangeAC = millis();

    }
  }
}

dht.zip (2.65 KB)

Buttons with interrupts is over kill.
Just look for a change in state detection every 50 ms.

.

 attachInterrupt(digitalPinToInterrupt(2), upButtonOn, FALLING);//Up in desired temp
  attachInterrupt(digitalPinToInterrupt(3), downButtonOn, FALLING);//Down in desired temp

As larryd suggests, using interrupts with pressed buttons is unnecessary. It often leads newbies into trouble--like attaching them in loop() instead of setup().

 attachInterrupt(digitalPinToInterrupt(2), upButtonOn, FALLING);//Up in desired temp
  attachInterrupt(digitalPinToInterrupt(3), downButtonOn, FALLING);//Down in desired temp

Do these pins have pull-up resistors attached? Or are they pull-down? Or are they floating so that they are able to trigger an interrupt any ole time they pick up a little noise and feel like it?

Delta_G:

 attachInterrupt(digitalPinToInterrupt(2), upButtonOn, FALLING);//Up in desired temp

attachInterrupt(digitalPinToInterrupt(3), downButtonOn, FALLING);//Down in desired temp




Do these pins have pull-up resistors attached? Or are they pull-down? Or are they floating so that they are able to trigger an interrupt any ole time they pick up a little noise and feel like it?

Each have a 10k pull-up resistor connected to them.

Got schematic?