MLX90614 IR Thermistor, interrupt button to make reference

I’m making a IR thermometer which using the digital MLX90614 and arduino ATmega328 based on this website bildr Is it hot? Arduino + MLX90614 IR Thermometer - bildr. I have the color reference which changes its color depend on the temperature. I’m using triple LED RGB.

I wonder if anyone could help me fig out how to connect a button which later will use attachinterrupt so when every I push the button it would take the current temperature as reference and display to the screen. The LCD i’m using right now is the normal 16x2. I will change to the better LCD like nokia 5530 for larger inputs.

Any help or suggesting would be very appreciated.

Thanks.

The code I’m using.

#include <i2cmaster.h>
#include <LiquidCrystal.h>


LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

const int redled = 3;
const int blueled = 5;
const int greenled = 6;
int redfade,greenfade,bluefade;

void setup()
{
    //Initialize the LCD
    lcd.begin(16, 2);
    
    pinMode(redled, OUTPUT);
    digitalWrite(redled, HIGH);
      
    pinMode(blueled, OUTPUT);
    digitalWrite(blueled, HIGH);
    
    pinMode(greenled, OUTPUT);
    digitalWrite(greenled, HIGH);
    
    i2c_init(); //Initialise the i2c bus
    PORTC = (1 << PORTC4) | (1 << PORTC5);//enable pullups
}

void loop(){
    int dev = 0x5A<<1;
    int data_low = 0;
    int data_high = 0;
    int pec = 0;
    
    i2c_start_wait(dev+I2C_WRITE);
    i2c_write(0x07);
    
    // read
    i2c_rep_start(dev+I2C_READ);
    data_low = i2c_readAck(); //Read 1 byte and then send ack
    data_high = i2c_readAck(); //Read 1 byte and then send ack
    pec = i2c_readNak();
    i2c_stop();
    
    //This converts high and low bytes together and processes temperature, MSB is a error bit and is ignored for temps
    double tempFactor = 0.02; // 0.02 degrees per LSB (measurement resolution of the MLX90614)
    double tempData = 0x0000; // zero out the data
    int frac; // data past the decimal point
    
    // This masks off the error bit of the high byte, then moves it left 8 bits and adds the low byte.
    tempData = (double)(((data_high & 0x007F) << 8) + data_low);
    tempData = (tempData * tempFactor)-0.01;
    
    float celcius = tempData - 273.15;
    float fahrenheit = (celcius*1.8) + 32;

    lcd.clear();
    
    lcd.print("Temp (C):  ");
    lcd.println(celcius);

    lcd.setCursor(0,1);
    
    lcd.print("Temp (F):  ");
    lcd.println(fahrenheit);
    
    digitalWrite(greenled, LOW);
    digitalWrite(redled, HIGH);
    digitalWrite(blueled, HIGH);
    
  
    
    if(fahrenheit > 85)
    {
      digitalWrite(blueled, HIGH);
      
      redfade=255-(fahrenheit*10);
      greenfade=255-(255-(fahrenheit*10));
      
      analogWrite(greenled,greenfade);
      analogWrite(redled, redfade);
    }
    
    if(fahrenheit < 70)
    {
      digitalWrite(redled, HIGH);
      
      bluefade=255-(fahrenheit*8);  
      greenfade = 255-(255-(fahrenheit*10));
      
      analogWrite(greenled, greenfade);
      analogWrite(blueled, bluefade);
    }
       if (fahrenheit > 70 && fahrenheit < 85){
      digitalWrite (greenled, LOW);
      digitalWrite (blueled, HIGH);
       digitalWrite (redled, HIGH);
 
       }
    delay(500); // wait a second before printing again
}

I wonder if anyone could help me fig out how to connect a button which later will use attachinterrupt so when every I push the button it would take the current temperature as reference and display to the screen.

Why do you think that you need to use an interrupt for this? How long does it take to get a temperature reading?

    if(fahrenheit > 85)
    {
    }
    if(fahrenheit < 70)
    {
    }
    if (fahrenheit > 70 && fahrenheit < 85)
    {
    }

Do nothing if the temperature is 70? Do nothing if the temperature is 85?

This structure needs some elses:

    if(fahrenheit > 85)
    {
    }
    else if(fahrenheit < 70)
    {
    }
    else
    {
    }

the line that you quote because I want the light keep turn green if it’s in that range because it would combine colors and turn yellow for somehow.

I need interrupt to get the current object’s temperature as reference to compare with other object. Sorry if that’s is abit confusing.

Right now I dont think the button working because the MLX90614 is dealing with I2C eeprom.

I wonder if anyone could show me how to code that pde by input that function that MLX90614 would take the first result in delay of 2 second (doesn't how long) as reference to compare with other objects' measurements. Thanks

If we are to have a conversation, it is important to answer all questions that are asked. How long does it take to get a temperature?

If the answer is on the order of seconds, then an interrupt handler might be necessary. If the answer is on the order of microseconds, polling the switch is sufficient.

Thanks PaulS

Sorry I was gonna answer you question, but for some reason after I find out that MLX90614 is interface with I2C EEprom, I just forgot. Yes, it's in microsecond. So you have any suggestion that I could do to take the reference temperature first then compare to other. It doesn't have to using button interrupt though. I'm kind of novice on this. Really appreciate your help . :)

You're suggesting pulling the switch. How would I do that? is it base on software or hardware?

You’re suggesting pulling the switch.

Not pulling. Polling. On every pass through loop, check to see if the switch is pressed:

if(digitalRead(switchPin) == HIGH)
{
  // Do whatever needs to be done
}

If using the internal pullup resistors with the switch, change HIGH to LOW.