Infrared Thermometer using Arduino. DIY

Programming, Tutorial, Coding, New Design, and/or any project for your Arduino and Raspberry Pi can post your topic /suggestion here.
User avatar
Mitch
Posts: 61
Joined: Mon Jan 30, 2017 4:58 am

Infrared Thermometer using Arduino. DIY

Fri Jul 26, 2019 6:23 am

I decided to build my own Temperature Gun using Arduino and an Infrared Temperature Sensor. This Thermal gun will be built using a non-contact temperature sensor called MLX90614; hence it can not only be used to measure component temperatures but can also be used for measuring body temperature, surface temperature, Heat ventilation and much more. Of course, these thermal guns are readily available in the market from renowned manufacturers like Fluke, Flir etc. But they are not light on your pockets and on top of that what is more fun than building your own gadgets.
Circuit-Diagram-for-IR-Thermometer-using-Arduino-and-Infrared-Temperature-Sensor.png
Materials Required
- Arduino Pro Mini
- MLX90614 Infrared Temperature Sensor
- OLED Display – SSD1306
- Laser Diode
- 9V Battery
- Push button
- Battery Clip
- Connecting wires

Programming for Arduino Temperature Sensor

The Program for Arduino should read the temperature value from the MLX90614 and display it on the OLED display. Lucky for us the program will be very simple since Adafruit has provided us a Library to easily read data from the MLX90614. Note: Please download the library for MLX90614.
MLX906142.jpg
MLX906142.jpg (71.87 KiB) Viewed 438 times
Arduino MLX90614 Library

The link will download the library as a ZIP folder. After download add it to the Arduino IDE following the command Sketch -> Include Library -> Add .ZIP Library and browse for the location of this ZIP file. Also make sure you have followed OLED interfacing with Arduino tutorial so that you have installed the required libraries for OLED display module as well. Once the libraries are added we can begin our program, the complete program for this project can be found at the bottom of this page. Here the same program will be explained in small snippets.

Like always we begin the program by adding the required library files. Here the Wire library (in-built) is used to communicate using I2C protocol and the SparkFun MLX90614 library is used to for communicating with the sensor. The SPI, GFX and SSD1306 libraries are used for communicating with 4-wire SPI protocol to the OLED display module.
#include <Wire.h>
#include <SparkFunMLX90614.h>
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
We then define the pins of the OLED display to which we have made the connection. Since the module works with SPI we have used the SPI pins of the Arduino. There are OLED displays that works with I2C protocol as well, but we can’t use them here since the I2C pins are already occupied by the thermometer sensor.
#define OLED_MOSI 9
#define OLED_CLK 10
#define OLED_DC 11
#define OLED_CS 12
#define OLED_RESET 13
Adafruit_SSD1306 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);
Inside the void setup() function, we initialize serial monitor for debugging and also the IR temperature sensor using the object therm that we created earlier. Here in India the most followed unit for temperature is Celsius (degree C) hence we have set the unit of the with TEMP_C you can also change this to TEMP_F if you need the values to be in Fahrenheit (F). Finally we initialize the OLED display and clear its display. Also the screen of OLED is rotated by 180 degree for easier mounting option in the casing.
void setup()
{
Serial.begin(9600);
therm.begin();
therm.setUnit(TEMP_C);

display.begin(SSD1306_SWITCHCAPVCC);
display.clearDisplay();
display.setRotation(2);
}
Inside the loop function, we read the value of temperature from the sensor and convert it into String to be displayed in the OLED display. We have also printed the value on the serial monitor for debugging purpose. We have also increment a variable called runner which is produce a small animation on the screen every time the value of the temperature sensor is updated successfully, this will help us know if the reading is stuck for some reason.
if (therm.read()) // On success, read() will return 1, on fail 0.
{
temperature = String(therm.object(), 2);
Serial.print("Object: ");
Serial.print(temperature); Serial.println("C");
display.clearDisplay();
runner++;
delay(5);
}
Testing Arduino Thermal Gun

Once the Arduino code is ready we can upload it to our hardware using an external TTL programmer or FTDI board since the pro mini does not have one on-board. Then simply press the push button to trigger the thermal gun and you will notice the laser beam falling on the object and the temperature of the object being displayed on the OLED screen as shown below. Here I have used it to measure the temperature of a component as pointed by the laser beam.

The complete working of the thermal sensor sensor can be found below. Hope you enjoyed the project and learnt something useful in building it, if you have questions leave them in the comment section below or use our forums for more technical questions.

CODE:

Code: Select all

/***********************************
Arduino Contactless thermometer 
MLX90614 I2C connection
OLED 4-wire SPI connection 
Dated: 7-6-2019
Code by: Aswint Raj
**********************************/

#include <Wire.h> 
#include <SparkFunMLX90614.h> 

#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

// If using software SPI (the default case):
#define OLED_MOSI   9
#define OLED_CLK   10
#define OLED_DC    11
#define OLED_CS    12
#define OLED_RESET 13
Adafruit_SSD1306 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);

IRTherm therm;

void setup() 
{
  Serial.begin(9600); 
  therm.begin(); 
  therm.setUnit(TEMP_C); 

   display.begin(SSD1306_SWITCHCAPVCC);
   display.clearDisplay();
   display.setRotation(2);
  
}

String temperature; 
char runner;

void loop() 
{
  if (therm.read()) // On success, read() will return 1, on fail 0.
  {
    temperature = String(therm.object(), 2);
    Serial.print("Object: ");
    Serial.print(temperature); Serial.println("C");
    display.clearDisplay();
    runner++;
    delay(5);
  }

  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(display.width()/4,display.height()/12);
  
  if (therm.object()>=100)
  display.setCursor(display.width()/4,display.height()/12);
  
  display.println(temperature);

  display.drawLine(display.width()/runner,display.height() - display.height()/2.5, display.width()/runner+1, display.height() - display.height()/2.5, WHITE);

  display.setCursor(0,display.height()-display.height()/4);
  display.setTextSize(1);
  display.println("   Arduino Thermlgun");
  display.setCursor(display.width()- display.width()/4,display.height()/12);
  display.println("deg C");
  display.display();

  if (runner>20)
  runner=0;
}
MLX90614_1.jpg
MLX90614_1.jpg (85.76 KiB) Viewed 438 times


Return to “ARDUINO AND RASPBERRY PI”

Links

In total there are 5 users online :: 1 registered, 0 hidden and 4 guests
Registered users: Bing [Bot]
Most users ever online was 90 on Sat Nov 16, 2019 5:56 pm
Total posts 536
Total topics 414
Total members 73
Our newest member Kelly
No birthdays today