LED with MLX90614 Temperature Sensor

B’'H

Good afternoon. I am trying to make an LED turn on if the temperature is above 99.4. However, the LED stays on the whole time, even if the temperature is under 99.4. Thank you

B__H_LASER_ARDUINO_THERMOMETER.ino (1.82 KB)

Please post your code as described in the forum guide. Most of us read the forum on phones & tablets and cannot open a .ino file. So please read the forum guide. I'll say it once more for emphasis, please read the forum guide.

Sorry. Here is my code:

#include <Wire.h>
#include <Adafruit_MLX90614.h>
#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);

Adafruit_MLX90614 mlx = Adafruit_MLX90614();

int sensorValue=0;
const int Laser_Pin=5;  //Laser Pin
int LED= 6;

void setup() {
  Serial.begin(9600);

  Serial.println("Adafruit MLX90614 test");  
  
  pinMode(Laser_Pin,OUTPUT);
    pinMode(LED,OUTPUT);
  mlx.begin();  
  


  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
    Serial.println(F("SSD1306 allocation failed"));
    for(;;);
  }
  delay(2000);
  display.clearDisplay();

  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(0, 0);
  // Display static text
 
  display.display(); 
  delay(100);





  
}

void loop() {
  digitalWrite(Laser_Pin, HIGH);
  sensorValue= mlx.readAmbientTempF();
  Serial.print("Ambient = "); Serial.print(mlx.readAmbientTempC()); 
  Serial.print("*C\tObject = "); Serial.print(mlx.readObjectTempC()); Serial.println("*C");
  Serial.print("Ambient = "); Serial.print(mlx.readAmbientTempF()); 
  Serial.print("*F\tObject = "); Serial.print(mlx.readObjectTempF()); Serial.println("*F");

    display.clearDisplay();
    display.setTextSize(2);  //Size 2 means each pixel is 12 width and 16 high
    display.setCursor(25, 10);
    display.print(mlx.readObjectTempC());
    display.setCursor(95, 10);
    display.print("C");
    display.setTextSize(2);
    display.setCursor(25, 36);
    display.print(mlx.readObjectTempF());
    display.setCursor(95, 36);
    display.print("F");
    display.display();
    
   if(sensorValue >99.40)
   {
   
    digitalWrite(LED,HIGH);
}
else{
  digitalWrite(LED, LOW);
}
   
    
  Serial.println();
  delay(500);
}

Thanks, +1 karma

 if(sensorValue >99.40)

sensorValue is an int, so it could be 99 or 100 but nothing in-between. For what values below 99.4 is the led on? Please post some output from serial monitor. Not as a picture, just copy text from the serial monitor & paste into your post between code tags.

The LED should be on for all values under 99.4. However, even after I changed sensorValue to a float, the LED remains on even under 99.4.

Ambient = 22.87*C	Object = 23.65*C
Ambient = 73.17*F	Object = 74.57*F

How is the led anode and cathode connected?

The Anode is connected to D5 and the cathode is connected to ground through a resistor.

jamiz:
The LED should be on for all values under 99.4

jamiz:
I am trying to make an LED turn on if the temperature is above 99.4.

Please clarify?

int LED= 6;

jamiz:
The Anode is connected to D5

What kind of Arduino is this? Not esp8266 I guess because D5 would be gpio 14.

Sorry. I meant that the LED should turn on if the temperature is above 99.4. This is an Arduino Uno. Thank you for the LED pin correction, I think that was the problem.

jamiz:
the LED pin correction, I think that was the problem.

Ah, yes pin 5 it set to OUTPUT and HIGH, so that would be it.

Thank you for your help! Sorry for the delayed thank you, it really helped me a lot before.
Sorry to bother again but the LED does not seem to turn on unless the value is stationary. I inferred that from the fact that when I move the wires connected to the MLX90614 temperature sensor, I get an incorrect and constant reading of 1037.56 Celcius and 1899.59 Fahrenheit and only then does the LED turn on. However, when I place a hot glass of water over the Temperature sensor, the temperature reads above 100 Fahrenheit and the LED does not turn on. Anyone who can help, it would be appreciated