Introduction: Infrared Thermal Imaging Camera With MLX90640 and ESP32 for Less Than 70 USD
7 years ago I made a simple infrared thermal imaging camera using the temperature-sensor Melexis
MLX90614 DCI and two servo motors.
It worked but it has the great disadvantage, that one picture takes several minutes to expose. Moreover the temperatures had to be sent to the computer, stored there and put together to a coloured picture.
Two months ago I found out that Melexis has a new infrared sensor with more than one pixel, the MLX90640 (https://www.melexis.com/en/documents/documentation/datasheets/datasheet-mlx90640). The MLX90640 consists of 768 pixel arranged in 24 rows and 32 columns.
If you buy just the sensor without PCB (Printed Circuit Board), you need two 2.2 kOhm pull-up-resistors for the SDA- and SCL-line. And don't supply the sensor with more than 3.3V, otherwise it'll be damaged!
Step 1: Parts You'll Need and the Total Costs
There are two different sensor-types, one with 110°x75° field of view (MLX90640BAA) and the other with 55°x35° fov (MLX90640BAB). There is no difference in pricing...
Then you'll need an ESP32. It can be bought in several stores or ebay for less than 6 USD.
To graph the temperatures you will need a display too. I chose a 320x240 ILI9341 display from aliexpress (ILI9341 display). It offers touchscreen and a SD-card-slot but for the thermal imaging camera you just need the 9 pins for the display and power supply.
At last you need some female-female dupont wires for the connections between the ESP, the display and the sensor (dupont wires)
Costs for this project:
- Melexis MLX90640 ............... 50-70 USD
- ESP32 .................................. 5 USD
- ILI9341 320x240 display ....... 8 USD
- dupont wire ........................... 1 USD
total minimum = 64 USD
Step 2: Necessary Libraries and Code for the First Test
Here you can find the arduino-code from sparkfun for the MLX90640:
I tried to run the code with an Arduino Due but I didn't succeed. In the web I found several threads from other users who had similar problems with an arduino-board. I didn't get temperatures but the values "not a number" (nan).
Therefore I switched to an ESP32-board. Installing the ESP32 with your Arduino-IDE is very simple. Here you can find a useful tutorial:
After a short time you'll be able to select among many ESP32-boards in the boards manager of the Arduino-IDE. For my board I choose "ESP32 Dev Module".
For the display you need two libraries from adafruit:
- the ILI9341 library: https://github.com/adafruit/Adafruit_ILI9341
- the GFX-library: https://github.com/adafruit/Adafruit-GFX-Library
To test the display with your ESP32 I can recommend this program:
There you'll find the necessary code for drawing lines, rectangles and so on but also to determine the right colour.
Then I tried to run the Sparkfun-MLX90640-code now with the ESP32. I was very frustrated to see wrong temperatures (nan) once again.
Fortunately I found out that someone's MLX90640-sensor worked with special values in the memory/register of the sensor. The value at the position 0x800D has to be 1901 (HEX) = 6401 (DEC). I inserted the line
MLX90640_I2CWrite(0x33, 0x800D, 6401);
in the setup-routine of the arduino-program. But with this modification I still got error messages while compiling the code. Another hint was very useful: You must add the line #include <Arduino.h> ; at the beginning of the file MLX90640_I2C_Driver.cpp!
Now you should get reasonable values from the MLX90640-sensor. Maybe some pixels are not working or show wrong temperatures. In this case you have to change the value of the pixel by hand. I chose a simple linear interpolation with the two neighbour-pixels. If f.e. the 1*32 + 21 st pixel is faulty the code will be:
mlx90640To[1*32 + 21] = 0.5 * (mlx90640To[1*32 + 20] + mlx90640To[1*32 + 22]);
But this only works when the faulty pixel isn't exactly located on one of the two sides of the picture...
Step 3: The Visualization of the Temperatures
To visualize the 768 temperatures I created a simple conversion of values between [0,180] to RGB-values. The temperatures of all pixels are being transformed to the interval [0,180] with the function 180 * (T_pixel - T_minimum) / (T_maximum - T_minimum). So you get similar colours like those you know from the company flir. Above you can see a test run with random temperatures...
Step 4: The Complete Circuit, Code and Results
After copying the program you'll have to connect the display with the ESP32 (look at the picture and code added). During the upload you first have to press the BOOT-putton on the ESP32. Afterwards you must press the EN-button. Then if everything worked fine you'll see the infrared thermal image on the display.
The whole camera will be powered by one Li-ion battery followed by a step-up-converter to provide +5V for the ESP32. Don't go much higher than 5V, otherwise the on board voltage-regulator will get too hot. At the moment I'm just waiting for the battery holder. Then this project will be finished...
Maybe you want to take a look at my other physics-projects: https://www.youtube.com/user/stopperl16/videos?vi...
And last but not least I'd be very happy if you could vote for me in the Remix-contest:
Thank's a lot...
Participated in the