Infrared Thermal Imaging Camera With MLX90640 and ESP32 for Less Than 70 USD

23,919

43

13

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:

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...

And last but not least I'd be very happy if you could vote for me in the Remix-contest:

https://www.instructables.com/contest/remix2019/

Thank's a lot...

Remix Contest

Participated in the
Remix Contest

3 People Made This Project!

Recommendations

  • Battery Powered Contest

    Battery Powered Contest
  • Plywood Challenge

    Plywood Challenge
  • Plastic Contest

    Plastic Contest

13 Discussions

0
Anu Marimuthu
Anu Marimuthu

Question 2 months 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.

mlx90640.PNG
0
Anu Marimuthu
Anu Marimuthu

2 months 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

mlx90640.PNG
0
bilyed
bilyed

Question 6 months 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

0
arvindsesh9
arvindsesh9

Question 8 months 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

IMG-20200325-WA0017.jpegIMG-20200325-WA0015.jpegIMG_20200325_092212.jpg
0
lftaddeo
lftaddeo

Question 8 months 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.

0
ahooper
ahooper

9 months 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.

1
Avishek9797
Avishek9797

11 months 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

serial problem.PNG
3
napiton
napiton

1 year 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!

0
Jd0g
Jd0g

1 year 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.

0
cooling coil77
cooling coil77

Question 1 year 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!

0
stoppi71
stoppi71

Answer 1 year 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

0
cooling coil77
cooling coil77

Reply 1 year 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...

Mlx90640.png
0
stoppi71
stoppi71

Reply 1 year 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...