I've been intrigued by thermal cameras for some time and decided to experiment with the MLX90640 IR Camera from Melexis. Anxious to get started I soldered some 4-wire flat telephone cable between it and an Adafruit development board with a display handed out at a conference I attended. In the image below I'm measuring my cup of tea under the watchful eye of Bender to ensure it is at the proper temperature. Unfortunately, it took so long to set up the photo that the tea has cooled off to an unacceptable level.
And that teabag was left steeping in the cup too long. Enough about the tea, let's do some research on the sensor and turn it into a real project.
Background
My original intention was to use a Raspberry Pi Zero W as the brains. In addition to the MLX90640, there would also have a Pi camera which would allow the thermal image to be overlaid on top of a camera image. For the camera body, I considered Lego as well as 3D prints. But I procrastinated on ordering and only received the MLX90640 a few days ago. Knowing I wouldn't have time to write much software or do the mechanical design I settled on using an Adafruit "Edge Badge" handed out at a conference I attended. There is a nice write-up by Adafruit on using this sensor with a similar board. By luck, I also found a 3D model that met most of my needs for the camera body.
MLX90640 Features and Usage
The MLX90640 allows relatively high precision non-contact temperature measurement with a 32x24 pixel sensor. Uses include presence/movement detection, thermal comfort, temperature control, insulation efficiency, and determining if your hot beverage is at the right temperature.
Among the features are:
- 32x24 pixels IR array
- Easy to solder four lead TO39 package
- I 2 C compatible digital interface
- Programmable refresh rate 0.5Hz…64Hz
- 3.3V supply voltage
- Current consumption less than 23mA
- Two field of view options – 55°x35° and 110°x75°
- Target temperature from -40°C to 300°C
The datasheet reports an initial factory set accuracy for temperatures in the range of 0°C to 100°C to be ± 1.5°C in the center portion of the sensor. The sensor has the lowest noise at refresh rates of 1Hz and becomes noisier with higher refresh rates.
Melexis provides a well-written datasheet and C++ code for using the sensor. They also have several videos describing the product and its use.
The MLX90640 sells in small quantities for around $50. The circuit is simple and as noted above the sensor comes in a TO-39 package that would be easy to hand solder.
Credit: Melexis MLX90640 32x24 IR Array Datasheet
Newark doesn't stock the individual components but they do sell an Adafruit MLX9640MLX9640 breakout board for the reasonable price of $60 and that is what I am using. I got mine using winnings from a Project14 basket. The Adafruit board adds an LDO, power LED, and STEMMA headers to the circuit above.
Project Wiring
As seen in the schematic from Melexis, there isn't much to the wiring. In addition to the circuitry on the Adafruit breakout, the Edge Badge has circuitry for charging and controlling a LiPo battery. Since I didn't have a STEMMA cable I wired up a daughterboard on the back of the Edge Board for the power, ground, SDA, and SCL connections. It would be much easier to use a pre-built cable. Links to the Adafruit wiring diagram are given at the bottom of this post.
Code
The Circuit Python code used has only minimal changes from the Adafruit examples. Do note that the Adafruit code won't run as written however because it attempts to get the map_range function from the simpleio library. Apparently, this function was moved from simpleio to simplemath at some point. Adafruit hasn't yet updated its code or the documentation for simpleio. Links to the Adafruit code are given at the bottom of this post.
3D Model
The 3D model also originated from Adafruit and can be downloaded in various formats.
This is a very nice model and I picked up a couple of ideas from it for the future. I removed the stand-offs in the original design and mounted the sensor board to the camera directly. The posts on the camera mount were then extended which gave sufficient room for the daughterboard as well as proper placement of the sensor. Given more time there are several additional changes I'd consider:
- Faux lens body for the sensor with lens cap like the version linked at the bottom
- Larger posts with threaded screw inserts
- Separate side plates for aesthetic reasons
- Screw on top and bottom for easier removal
In a fit of whimsy, I elected to print it in non-traditional colors :-). Links to Adafruit design files are given at the bottom of this post.
Assembly
Assembly was straightforward. I cut off the flat telephone cable due to a lack of room and wired the daughterboard directly to the sensor breakout. The back plate didn't quite fit my Edge Badge so I took a file to it. I had some trouble printing the top plate and had to restart the print. The problem arose due to the need for a small support that could be removed with a small design change. As seen below the parts count is low.
The slides below show the microcontroller and sensor, view with the top removed, and the front and back of the camera.
{gallery} My Gallery Title |
---|
Board and MLX90640 IR Thermal Sensor |
REPLACE THIS TEXT WITH YOUR IMAGE Assembled Camera with Top Off |
Competed Camera from Back |
Completed Camera from Front |
Testing the Camera
OK, here is the first test. I can see my hand!
The camera reports that the warmest part of my hand is 36°C.
The two-minute video below demonstrates the camera detecting a person, measuring the temperature of ice water, boiling water, and a lightly loaded Raspberry Pi 3. As a bonus, it makes a determination on whether or not Bender is cold-hearted.
Realize that some of the tests weren't that well-conceived. For example, the camera could have been picking up the pan in the boiling water test which showed higher temperatures near the end of the clip.
Summary
The small 32x24 pixel matrix gives better results than I thought it would. The sensor generally gives useable results but was off by as much as 4°C or so in some cases. Realize that my test procedure was not very scientific but it is indicative.
I liked the overall case design but as noted above there are several aesthetic changes and some mechanical changes I would make if redoing the project. Thanks for reading and as always comments and suggestions are welcome.
Links
CircuitPython Code
3D Files - These files differ from what I made but fit a development board that is easier to obtain
Top Comments