Hi All,
I am trying to code IR temperature sensor to work with a Arduino uno through the I2C bus.
The code is working for the I2C bus and the display the temp readings from MLX90614 IR sensor.
I have 2 leds to display as outputs. One Red led to display that the IR sensor is working and another to light up when the temp is over the limit of 50 C.
I need help with the second led function. I have added the source below:
appreciate any help to solve the issue.
Regards,Gonzo
//Temperature Monitor
/******************************************************************************
MLX90614_Serial_Demo.ino
Serial output example for the MLX90614 Infrared Thermometer
This example reads from the MLX90614 and prints out ambient and object
temperatures every half-second or so. Open the serial monitor and set the
baud rate to 9600.
Hardware Hookup (if you’re not using the eval board):
MLX90614 ------------- Arduino
VDD ------------------ 3.3V
VSS ------------------ GND
SDA ------------------ SDA (A4 on older boards)
SCL ------------------ SCL (A5 on older boards)
An LED can be attached to pin 8 to monitor for any read errors.
Development environment specifics:
Arduino 1.6.9
SparkFun IR Thermometer Evaluation Board - MLX90614
Reads the temperature from the MLX90614 through the I2C bus and displays on the LCD
******************************************************************************/
#include <Wire.h> // I2C library, required for MLX90614
#include <SparkFunMLX90614.h> // SparkFunMLX90614 Arduino library
#include <LiquidCrystal.h> // Include the library to use a LCD display
int temp;
int tempMin = 40;
//int tempMax = 100;
LiquidCrystal lcd (7, 6, 5, 4, 3, 2);
IRTherm therm; // Create an IRTherm object to interact with throughout
const byte GreenLED_PIN = 12; //LED attached to pin 12 active when temp is working
const byte RedLED_PIN = 13; //LED attached to pin 13 active when temp is over 40 C
/* The function above declares which Arduino’s pins will be used for controlling the LCD */
void setup()
{
lcd.begin(16, 2); // It tells the Arduino that the display is a 16x2 type
//lcd.print(“Temp:”); // Send the text to the screen of the display.
therm.begin(); // Initialize thermal IR sensor
therm.setUnit(TEMP_C); // Set the library’s units to Centigrade
pinMode(GreenLED_PIN, OUTPUT); // LED pin as output and is ‘ON’ when IRtemp is working
pinMode(RedLED_PIN, OUTPUT); // LED is ‘ON’ when the temp is over 40 C
//setLED1(LOW); // LED OFF
}
void loop()
{
temp = therm.read();
if(temp > tempMin) { // if temp is higher than tempMax
digitalWrite(RedLED_PIN, HIGH); // turn on led
} else { // else turn of led
digitalWrite(RedLED_PIN, LOW);
}
//setLED1(HIGH); //LED on
// Call therm.read() to read object and ambient temperatures from the sensor.
if (therm.read()) // On success, read() will return 1, on fail 0.
{
lcd.setCursor(0, 0); // Moves the cursor of the display to the next line
lcd.print("Object: " + String(therm.object(), 2));
//lcd.print (TC);
lcd.print((char)223);// degree symbol
lcd.print(“C”); // Writes “C” to indicate that it is in Centigrade scale.
//lcd.clear();
lcd.setCursor(0, 1); // Moves the cursor of the display to the next line
lcd.print("Ambient: " + String(therm.ambient(), 2));
lcd.print((char)223);// degree symbol
lcd.print(“C”);
//lcd.clear();
}
setLED1(LOW);
delay(5000); // Waits for five second to read the sensor pin again
}
void setLED1(bool on)
{
if (on)
digitalWrite(GreenLED_PIN, LOW);
else
digitalWrite(GreenLED_PIN, HIGH);
}