Rationale

Thermal imaging is a very useful tool for applications as diverse as home renovations (e.g for checking home insulation or for monitoring wear and tear on power tools) automotive repair and maintenance, or electronics. Being able to see, at a glance, the relative temperatures of different objects can make a range of design and diagnostic tasks much faster.

While the price of imaging sensors in the visible-light spectrum has plummeted in recent decades, long-wave infrared imaging remains a relatively expensive niche market. Commercial off-the-shelf (COTS) solutions exist, but are relatively expensive. Prices for a ready-to-use thermal camera begin at around USD500 and only go up from there. This places them out of reach of the casual hobbyist, student, or DIYer.

Due to the COVID19 pandemic in 2020-21, all thermal imaging tools and components have become scarce. A quick search of online electronics suppliers (Digikey, element14) shows that ~80% of all thermal imaging equipment is unavailable as of June 2021. As of June 2021, there is also an ongoing chip shortage which has affected availability of many of the supporting electronics components, from microcontrollers (MCUs) to passives like capacitors: https://amp.theguardian.com/technology/2021/may/14/global-shortage-of-computer-chips-could-last-two-years-says-ibm-boss

Presented here is a homemade device that can use the MLX90640 thermal sensor from Melexis. This sensor is available from Digikey, who can also supply a selection of breakout boards from Adafruit and Sparkfun.

This project builds on previous work published by Adafruit* for use with their MLX90640 breakout. The design presented here should be compatible with a wider range of 32-bit Arduino development boards and sensor packages. This should help the reader avoid some of the aforementioned supply chain issues. * https://learn.adafruit.com/mlx90640-thermal-image-recording

The design presented here has been assembled for under USD150, a significant saving compared to a COTS option. It also has the advantage that it can be customised to your needs, or to suit local availability of components.

Disclaimer

During the COVID19 pandemic, some parties have attempted to use thermal imaging as a diagnostic tool to identify people infected with COVID19, in a similar way as thermal imaging was used to identify SARS-positive patients during that earlier epidemic. Thermal imaging is NOT effective for COVID19, for a range of reasons.

It may be tempting to use a tool like this to try and help out with the pandemic response, or to get funding for your work, or just to try and get more attention or views for your project online. Please don’t do this.

Design

The Melexis MLX90640 sensor is an array of 32 x24 thermopiles that are sensitive to thermal radiation. This is usually radiation in the wavelengths of 8-14µm (but I couldn't find the specifics in the datasheet - let me know if you find this info for the MLX90640!) This is a lower resolution than a commercial thermal camera, but good enough for hobbyist work. It communicates with the MCU via the I2C bus. Melexis have excellent documentation for both the sensor and its communication protocol. Sparkfun has published some suggestions for simulating higher resolution with software interpolation but this design uses the native resolution of the sensor. https://learn.sparkfun.com/tutorials/qwiic-ir-array-mlx90640-hookup-guide

The carrier PCB is the heart of the physical design. This PCB was designed to suit any of 4 different breakout boards for the MLX90640 sensor, and could also support the bare sensor (with no breakout) with minor rework. The PCB also supports modules for DC-DC conversion (for battery power) and for an LCD screen + SD card adapter. The PCB is designed to accept microcontrollers (MCUs) in the Adafruit “ItsyBitsy” family, and tested with the ItsyBitsy M4.

The modular approach significantly reduced development time, because I didn’t have to “reinvent the wheel” for DC-DC conversion, signal level shifting etc. It reduces the amount of small surface-mount soldering required by the builder. It also makes the entire bill of materials (BoM) more flexible to accommodate what components are available in your country or what parts are can still be found during the chip shortage. Even if you can’t find every exact part that I used, hopefully you can work with what you do have, and the PCB will still be useful. If there is enough demand, I might make the whole thing available as a kit.

Hardware Development

This section assumes familiarity with the Arduino environment and basic electronics assembly.

As an initial proof of concept, I connected the MLX90640 breakout to the MCU and screen, with a small breadboard to share the power rails. For this stage of the development, all power was derived from the USB cable used to connect the MCU to the PC used for programming. This worked with no visible problems, which is a very good sign. A breadboard, with its long connecting wires and minimal ground plane, is much more susceptible to electrical “noise” and electromagnetic interference (EMI) than a well-made PCB. Therefore if the circuit works when implemented on a breadboard, we can be quite confident that the PCB will work!

The PCB was designed with Kicad. I used version 5.1.10. Kicad is a free, open-source circuit design package. It’s available for Linux, Windows and Mac. Because it is free and open, it will never lock you out of your designs, or require a cloud login or internet access to work. I highly recommend Kicad.

The PCB was designed to physically fit into a plastic case. More on this case in the “Enclosure” section. Before sending the PCB design for fabrication, I printed it on paper so I could check that it fitted in the case as designed.

Microcontroller

I have used the “ItsyBitsy M4” from Adafruit for this PCB. It is cheaper than the “PyBadge” development board specified in Adafruit’s guide at* and I already had one in stock. Adafruit has recently released a new board* in the Itsy Bitsy form factor, but based around the new Raspberry Pi 2040 MCU. At the time of writing, this new board does not support Arduino, so it is not presently compatible with this project.

IR sensor

The MLX90640 sensor comes in two configurations, with different fields of view (FoV). The wide-angle version has an FoV of 110°, and the narrow-angle version is 55°. All my testing has been done with the 55° version. It has a bigger lens (IR lenses have to be made of exotic materials) and for electronics work, it allows you to get closer in to the area of interest. If I need a wider field of view, I can pan the camera from side to side, or just take a few steps backwards :-)

I used the breakout board from Sparkfun. After more than a year of the MLX90640 being unavailable anywhere due to COVID19, the Sparkfun breakout was the first opportunity to get my hands on this sensor! For some strange reason, the Sparkfun breakout has the sensor mounted on the PCB at an angle, so that all the images are rotated by about 30 degrees. You could probably fix it in software, but I have found it easier to just mount the breakout board "rotated" relative to the rest of the circuit and enclosure. The equivalent breakout from Adafruit does not have this problem, and I encourage you to use the Adafruit board if it is available.

Both the Sparkfun breakout and the Adafruit breakout are pretty simple, so you could probably use the bare sensor instead, if that is easier to source. Version 0.1 of the PCB doesn’t have provision for a bare sensor, so you would have to figure out for yourself how to mount the sensor, and add pullup resistors for the I2C bus. A future revision of the PCB will provide pads for the sensor and necessary resistors.

Power

There are many options for power supplies for small handheld devices like this. Increasingly in the DIY world we are seeing use of lithium ion “pouch” cells or cylindrical cells like the 18650. These offer high energy density and range of sizes and shapes to suit your design. I have avoided using these for the following reasons:

Cons of lithium cells:

Pros of AA batteries

So, now that we have decided to use AA cells, this helps us finalise a few other design choices. First, I was able to find an enclosure at my local Jaycar store that has a built-in compartment for 2 AA cells, which also saves a lot of physical design work. More on this later.

We pass the power from the batteries through a pushbutton switch. This simply cuts the power when the switch is off, so there is zero current drawn from the batteries when the camera is off. I am not a fan of “standby” switches that don’t actually turn a device 100% off – I have had too many bad experiences with equipment that has lain unused in a drawer, only to be completely dead next time it is required.

DC-DC conversion

A non-rechargeable AA cell is nominally 1.5V, so two of them should give us 3V. Every module (thermal sensor, MCU and screen) in this design should happily run on 3V from two AA alkaline cells. If you are never planning to use rechargeable batteries, you can probably omit the DC-DC conversion module and just run 3V straight from the battery compartment to the PCB (I haven’t tried this yet! So make sure you read all the datasheets and understand what you’re doing)

A rechargeable AA cell has a nominal voltage of 1.25V when fully charged. So two of these cells in series will only deliver 2.5V. While this might be enough to run all the modules, it is definitely outside their spec, so they may be unreliable, especially as the batteries get depleted.

This design uses a cheap DC-DC “boost converter” which up-regulates the battery voltage to 5V. These converters are commonly used in those cheap phone chargers that take a couple of AA cells and have a USB port to charge a phone. The one used in the phone is an XC4512 that cost AUD3.95 from Jaycar at https://www.jaycar.com.au/arduino-compatible-5v-dc-to-dc-converter-module/p/XC4512 . I think the Jaycar unit uses the BL8530 boost-converter chip, but anything that you can cannibalise from a USB battery bank will probably be fine.

For optimum battery life, it would actually be better to use a DC-DC converter with a 3.3V output, and run the whole system from 3.3V. The only reason I didn’t do this was because I couldn’t find a 3.3V module locally! To run the unit from a 3.3V module, you will need to cut the 5V PCB track to the MCU, and run an insulated wire from your 3.3V DC-DC converter to the 3.3V pad on the MCU. A future revision of the PCB will provide jumper pads for this.

The MCU is supplied with 5V. We use its on-board regulator to provide 3.3V for the Sparkfun thermal sensor. The Adafruit thermal sensor accepts either 5V or 3.3V. The PCB allows you to choose whether you run the Adafruit sensor from 3.3V or 5V. If you use the Adafruit sensor, you will need to bridge ONE of the jumpers JP1 or JP2 to provide power.

Screen

The Adafruit screen module also accepts 5V OR 3.3V. Version 0.1 of the PCB is deisgned to use 5V for the screen. If you use 3.3V, you will need to cut the 5V track to the screen and use an insulated wire to deliver 3.3V to the power pad. A future revision of the PCB will provide jumper pads for this. The screen uses the ST7735 chipset to control it. Adafruit have done the hard work for us here with their Adafruit_GFX library. More on that in the “Software” section. The screen has a resolution of 160 x 128 pixels. This matches the 4:3 aspect ratio of the thermal sensor, so the output of the sensor can easily be scaled to fill the screen without distortion of the image.

Battery monitoring

We also pass the battery voltage through a voltage divider comprising R8 and R9 to an analog input pin on the MCU. Right after power-on, we read the ADC, then convert this reading into an estimate of battery voltage. Both numbers are then displayed on the screen. In a future software update I'd like to do this a bit more elegantly, so that we can have a "live" display of battery status while we are using the thermal camera.

Hardware switches

There are 3 momentary pushbutton switches on the PCB. These are connected to the MCU and are intended to select between functions when the camera is in use. As of August 2021, they have not been implemented in software yet. These pushbuttons require use of the internal pullup resistors in the MCU.

Audio

Pinouts for a piezo beeper are also provided to give audible feedback if required.

Capacitors

Capacitors C1 – C6 are all provided for “decoupling,” to stabilise the power rails and help protect each module from glitches or noise in the power rails. I didn’t use any capacitors in the breadboard prototype and it worked just fine! So, while you could probably get away without using these capacitors at all (all of the breakout boards have capacitors on-board), it is good practice to have them in the design.

Resistors

Resistors R1, R2, and R3 act as pulldowns for the pushbutton swiches. Their resistance of 330Ω was chosen so that if the MCU’s pins are misconfigured and set “high” in software, grounding these pins won’t damage the MCU witch excessive current. Resistors R5, R6 and R7 are on the SPI bus to the screen and are specified as 0Ω, so you can use 0Ω resistors, short lengths of wire, or just a bridge of solder for these resistors. Some SPI implementations are prone to “ringing” on the data lines which can lead to unreliable communications between the screen and the MCU. If this is the case, you may find that increasing the resistance here can help. If you do find that the screen or the SD card seems unreliable, try replacing the 0Ω resistors with resistors of about 100Ω.

LED

Finally, there is an LED attached to pin 13 of the MCU. Most Arduino boards have an LED built-in on this pin. As of June 2021, this LED isn’t actually used, but I have found that it is very useful in MCU development work to have an LED attached. When nothing else works, you can always go back to basics and make sure you can blink the LED! In future, we might also use it for visual feedback to the user, e.g a low-battery indicator, or confirmation of button presses.

Enclosure

The case is the “HB5610” from Jaycar*. In dimensions, it's very close to the “H65AA” or "H67AA" series of enclosures made by Serpac, or the "1593" enclosures made by Hammond. Jaycar don't specify the manufacturer, nor do they tell you the internal dimensions of the case, spacings between mounting points etc. External dimensions are 135mm x 70mm x 24mm. It’s a bit frustrating, but I used calipers to measure everything as best I could, and designed the PCB to fit neatly into the case and screw securely into the mounting points provided. I was pretty conservative with the dimensions of the PCB, which had the benefit that the PCB fit into the case with no cutting, filing or hacking required :-)

* https://www.jaycar.com.au/black-hand-held-electronic-enclosure/p/HB5610

Software Development

*As of August 2021, the software is still under active development. It’s pretty messy but “works.” I’m happy to share it on request and will put it online when I have tidied it up a bit more! I am not the world’s greatest coder, and am grateful that I can stand on the shoulders of giants for this project. A big thank you to Adafruit for all the libraries and examples that I have relied on – this kind of support is one reason I recommend Adafruit’s products so highly.

Libraries

We use the MLX90640 library from Adafruit. This seems to be an Arduino implementation of the C library provided by Melexis.

The screen is driven by the Adafruit_GFX library. This super-useful library has all sorts of clever graphical functions built-in, so you don’t need to go down the rabbit hole of writing your own graphics drivers. Adafruit also provide great documentation on how to use the library, in their how-to guide at https://learn.adafruit.com/adafruit-gfx-graphics-library?view=all .

We also use the SPI library to handle communications with the screen and the SD card on the screen module.

The goal for this design is to have equivalent features to the design presented by Adafruit at https://learn.adafruit.com/mlx90640-thermal-image-recording but also to be compatible with a wider range of MCUs and not dependent on such a large number of libraries. Then I want to add some extra features like:

Please feel free to add your own suggestions or contributions!