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

4,411

25

4

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!

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

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

Share

    Recommendations

    • Indoor Lighting Contest

      Indoor Lighting Contest
    • Make It Fly Challenge

      Make It Fly Challenge
    • Growing Beyond Earth Maker Contest

      Growing Beyond Earth Maker Contest

    4 Discussions

    0
    None
    cooling coil77

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

    3 answers
    0
    None
    stoppi71cooling coil77

    Answer 1 day 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
    None
    cooling coil77stoppi71

    Reply 23 hours 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
    None
    stoppi71cooling coil77

    Reply 11 hours 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...