Introduction: Infrared Thermal Imaging Camera With MLX90640 and ESP32 for Less Than 70 USD
Hello!
7 years ago I made a simple infrared thermal imaging camera using the temperature-sensor Melexis
MLX90614 DCI and two servo motors.
Link: https://forum.mosfetkiller.de/viewtopic.php?f=6&t...
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
You can get the MLX90640 for example from sparkfun (sparkfun MLX90640), aliexpress (MLX90640 aliexpress) or mouser (mouser MLX90640).
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:
https://github.com/sparkfun/SparkFun_MLX90640_Ardu...
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:
https://randomnerdtutorials.com/installing-the-esp...
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:
https://github.com/MartyMacGyver/ESP32_Adafruit_IL...
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...
more physics projects: https://stoppi-homemade-physics.de/
Attachments

Participated in the
Remix Contest
19 Comments
Question 6 weeks ago
Super project! I have everything set up the way you have it and everything does run well with good output for about 30 seconds to a minute; then it freezes every time. I have to unplug the unit from the power supply and wait a minute or so, and plug it back in. Then it will work another half minute or so, does anybody have any ideas? Thank you.
2 months ago
Can you run multiples of these cameras on a single ESP32 by adding a TCA9548A IC2 multiplexer, I wanted to make a tire monitor.
7 months ago
Hello, I was working with mlx and esp32 wroom32d version which is a dual core version. Then I found out that everyone is using single core version. I had a question, why does single core version esp32s handle mlx whereas esp32d doesnt provided it has 2 cores?
1 year ago
Hii there, I am using 2.4"tft PARALLEL display. how to configure this project with a parallel input display. Can you help me out!
1 year ago
SPI-Bus from Display disturbs I2C. Whithout display sensor works fine, but if I connect display I have much errors in I2C
Question 2 years ago
Which is the minimum possible price at which I can take up this project? As I am still a student and cannot afford to spend much, could you please help me with the BOM? I want to attempt this for my project at college.
And could I use:
1. SparkFun 1.8" TFT LCD 160x128 display - https://www.tanotis.com/products/sparkfun-1-8-tft-...
Question 2 years ago
hi, can you please help me to slove the problem of the program of this. i tried this video thermal cameral MLX90640,Esp32, but while uploading the error occurs, the error is MLX90640_APP.h is not found.
2 years ago
Hi, thanks for upload this video, i tried this video thermal cameral MLX90640,Esp32, but while uploading the error occurs, the error is MLX90640_APP.h is not found, can you help me solve this problem
Question 3 years ago
Hi everyone,
First of all, thanks for sharing this nice project to build a thermal camera of low cost.
I have a NodeMCU Lua WiFi ESP8266 CP2102, a GY-MCU90640 with MLX90640BAA sensor and ILI9341 display. I would like to ask if any body has built a thermal camera with these parts and he/she can share his/her experience and any resource to make it.
I appreciate any help and guidelines, please.
Cheers
Question 3 years ago
I ended up buying a esp32s cam and am struggling cause I don't have a serial to usb connector. Due to corona the shipping has shut down but I would like to make this in a rush.
Would it not work if I directly connect a 4 wire Android wire with the esp32s cam board? It doesn't have a usb port and hence the make shift. Please see the image to see how I've connected.
Does anyone know how to connect the usb chord directly to a esp32s cam? Would it work? I got a serial time out error
Question 3 years ago
Hi there! Really neat project you have there.
I'm thinking about constructing one myself, but with another display... I'm planning to use the MLX90640BAB (smaller FOV, better for longer ranges).
I serached in the sensor's datasheet but I was not able to find: do you know the maximum range that this sensor is able to get a decent reading? I don't want anything particularly precise, just need to be able to see the presence/absence of heat forms and its general shape.
3 years ago
Something interesting about the MLX90614 and MLX90640 is that they do not seem to want to sit on the same I2C line. They are both individually great sensors but trying to use both in a project seems not to work.
Other than that, thanks for the instructable and your work, its been quite handy getting my project up and running.
3 years ago
Dear sir im facing this problem i had change all the code from above example when i connect my MLX90640 device to esp32 and open serial monitor i didnt see any pixel temp here please see the below pic
3 years ago
Hi!
I would like to do my own version of this, but as I tried this project the only thing I get for the readout is NanC and some absurdly large values.
I use:
MLX90640 55FOV module ( GY-MCU90640)
ESP-32S
I also have Ili9340 screen, but I haven't got that far, because I cannot get a sensible readout from the sensor.
As I have read from the forum posts in the video description link, You did have the same problem with NanC results?
Did you change the register values in the sensor beforehand to get it working? Or is the sensor as-is factory default?
Also As I have understood the SET - pads, or the PS pin needs to be connected in order to get I2C read out directly from the sensor, and not UART from the chip. In your video, I don't see have these been connected.
Thanks!
3 years ago
Great project! I was wondering if you've ever tried to display to an HTML page instead of an external display. Id like to upload an HTML file to the on board flash, and then use the ESP32 as a webserver to display the thermal sensor rendition ontop of a live webcam image viewed through the HTML site utilizing websocket protocol. Utilizing a cell phone or computer would reduce material costs and expand use???
Very green and only messed with Qbasic back in the day, just getting my feet wet with Arduino IDE. Not sure if my terminology is correct or if this is possible.
Question 3 years ago on Step 4
Thank you so much for sharing this. Great job!!
I tried to build this thermal camera with my son. I used the "ESP32 ESP-32S NodeMCU Development Board 2.4GHz WiFi+Bluetooth Dual Mode CP2102" and the Qwiic IR Array (MLX90640) (from Sparkfun). MLX90640 can be powered up. I used the code you share with us (Example_basicreading) and uploaded. However there's no reading can be found in series monitor. Do you have any recommendations or comments for us? thanks!
Answer 3 years ago
Hi! The code example_basicreading isn't complete. You'll have to add the line MLX90640_I2CWrite(0x33, 0x800D, 6401); in the setup-routine. Furthermore you need the line #include <Arduino.h> ; at the beginning of the file MLX90640_I2C_Driver.cpp!
Please take a look at the significant changes in the code Arduino_ESP32_MLX90640.ino compared with your example_basicreading.ino! Without those changes the second code didn't work for me as well... Good luck
Reply 3 years ago
Thanks a lot for your kind help. I added the line MLX90640_I2CWrite(0x33, 0x800D, 6401) in the setup and added #include <Arduino.h> at the file MLX90640_I2C_Driver.cpp. It still won't work after uploading. I'm not sure if I miss anything else.
Then I tried to upload Arduino_ESP32_MLX90640.ino. It says the spi.h file is not in the directory...
Reply 3 years ago
The spi.h file is part of the display-library. If you use a display you'll have to copy a spi-library (f.e. https://github.com/PaulStoffregen/SPI) into the directory .../Arduino/libraries/...
In your case I'd delete all the lines with /* ... */ concerning the display and just show the values from the MLX90640. If you get reasonable values then you can add the display-code...