In this article Brian uses a Melexis MLX90640 IR camera module coupled to an ESP32 controller. He streams the image data to a web browser running on a cell phone, tablet, or computer, eliminating the need for a dedicated color LCD. Together, this makes for a very low-price IR camera.
Forward-looking infrared (FLIR) cameras are quite common today. These cameras detect infrared energy, which is a measure of how much heat an object is emitting. FLIR sensors were developed in 1963 by Kirby Taylor, while working at Texas Instruments and were originally designed for military purposes. At the time, they would have been expensive and thus only practical for the military, which spends heavily for technology. In time, however, the cost of these sensors dropped enough to make them practical for commercial/consumer use.
Infrared light falls into two ranges: long-wave and medium-wave. Long-wave IR sensors can pick up body heat as well as heat produced by electronic components. They only work over a limited distance, which is generally fine for their intended purpose. These sensors are often referred to a “thermopile IR sensors.” Medium-wave IR sensors have other uses as well but generally need to be cooled to cryogenic temperatures.
Many years ago, I worked for General Electric Medical Systems. I serviced an IR camera system they sold, called the Spectrotherm. It was used for mammograms on female patients to detect breast cancer. If my memory serves me correctly, its IR sensor was made by the military contractor Hughes. As already mentioned, this sensor had to be maintained at minus 195˚C by being surrounded by a vacuum vessel (dewar) containing liquid nitrogen. This wasn’t as inconvenient as you might think, since hospitals use liquid nitrogen for many other purposes. The Spectrotherm’s IR sensor was not at all like the modern IR camera sensors as it produced only a single pixel. To get an image, the incoming IR energy making up the image had to be bounced off two moving mirrors. This allowed for the scanning of the incoming IR energy in both the vertical and horizontal planes. This is similar in principle to the fixed bar code scanners you see in the grocery store checkout line.
Modern IR camera sensors fall into three broad groups:
- Very low-resolution sensors such as the Panasonic AMG8833 Grid-EYE infrared sensor array, which only has a resolution of 8 × 8 pixels. These are only meant to vaguely detect the shape of an object by its heat signature, used, for example, on an assembly line.
- Modest-resolution sensors made by Melexis. The MLX90640 sensor has a resolution of 32 × 24 pixels and is easily interfaced via I2C. At a cost of about $35 USD, these sensors are a good choice for a DIY project. [1]
- High-resolution sensors made by Lepton. The term high-resolution is relative. In the IR camera field, the 160 × 120-pixel resolution of the Lepton 3.1R sensors is considered to be high-resolution. We’d hardly consider a cellphone camera to be high-resolution if it had those specifications. These Lepton sensors are more expensive, at about $142 USD, but are quite reasonable if you consider the per-pixel cost. Figure 1 shows a Lepton sensor.
I recently came across an IR sensor that is not a camera sensor per se but is somewhat more versatile than the single-pixel IR sensors used for things such as in-ear baby thermometers or the hand-held fever scanners rolled out during the COVID-19 pandemic. DF Robot sells the Gravity brand IR Positioning Camera (part number SEN0158). While not a camera in the traditional sense, this device can track the position of up to four discrete heat sources and place them on a 128 × 94-pixel grid. This sensor is optimized for positioning and does not measure the actual temperature of the detected heat sources. This sensor is shown in Figure 2 and is quite reasonably priced for such an application ($24 USD). It can be readily interfaced via I2C. I’ve ordered one and will give it a try soon.

While not used in this project, I came across this IR sensor that doesn’t measure temperature per se but tracks the position of up to four heat-emitting objects in a 128 × 94 grid.
I settled on the Melexis MLX90640 as a good comprise for this project. They are available from DigiKey.
The Melexis MLX90640 IR image sensor
The MLX90640 sensor array has another advantage beyond its reasonable price—it is housed in the same TO39 package that was used in the past for medium power transistors. It contains four leads and easily mounts on a protoboard having holes centered on a 0.1” grid. It comes in two versions:
- BAB option code with a field of view (FOV) of 55˚ × 35˚
- BAA option code with a wider 110˚ × 75˚ FOV
The BAB configuration is a bit lower priced and is the one I chose. Figure 3 shows the MLX90640 BAB sensor that I bought—the BAA option looks similar, except that its black collimator is shorter and has a wider aperture.

This is the Melexis MLX90640 sensor used in this project. It is easy to mount due to its four-lead TO39 package.
These sensors are factory calibrated. That is, the temperature readings provided are accurate out of the box. Also important is that the matching of all 768 individual sensors is done using coefficients stored in EEPROM tables within the device. Therefore, if you point the camera at something that is isothermal over its entire surface, you won’t see any significant hot spots or cold spots in the resulting image. I suspect that this factory calibration factors significantly in the cost of producing this unit.
These sensors are capable of a reasonably fast refresh rate. The rate can be programmed in the range of 0.5 to 64Hz. In my project, the limiting factor was how fast I could collect the pixel data, convert it into a 320 x 240 pixel image, and then stream it out using the ESP32’s web-server capability.
The MLX90640 operates on 3.3 volts, which is convenient since that is the supply voltage used by the ESP32. However, the MLX90640 requires a very low-noise (“clean”) 3.3V supply; the 3.3V power source supplied by the ESP32 board’s LDO regulator is not clean enough. More on this later. The MLX90640 itself draws about 20mA of current, so it is not a significant load on the LiPo battery I use.
There are 768 discrete IR sensors within the MLX90640. All of these sensors measure temperature (IR radiation) with respect to the temperature of the substrate upon which they are mounted. Therefore, an internal substrate temperature sensor (referred to as PTAT) is included in the chip. Figure 4 shows the internal elements of the device. It appears that each sensor has its own analog amplifier prior to being fed to the analog-to-digital controller (ADC), which I assume must be a single ADC with an input multiplexer. The ADC has a resolution of 18 bits, but this can be modified under program control.
The MLX90640 contains an EEPROM array to store many different factory-measured calibration coefficients. There are a few discrete coefficients such as the ones that store the device’s internal VDD value as well as the ambient temperature sensor (PTAT) calibration. However, most of the EEPROM space is taken up by coefficient arrays corresponding to parameters for each of the 768 sensors in the array.
The MLX90640 contains an accurate band-gap reference for the ADC, as well as a RAM storage array, which temporarily stores each of the pixel values until they can be read out serially, via I2C. While not shown in Figure 4, there is also a microcontroller unit (MCU) or digital signal processor (DSP) that handles all the data flow, which is clocked by a 34MHz RC clock.
To appreciate all the calculation that is needed when using the MLX90640, you must understand the relationship between the voltage output of the thermopile as a function of both the object temperature being measured, as well as the substrate temperature. I have previously tried using Thermometrics ZTP-1468SR IR sensors, which contain only a single thermopile IR sensor and which provide an analog output signal from the thermopile. These thermopiles also measure temperature relative to the device’s internal substrate temperature and thus also contain a substrate-mounted thermistor. These sensors produce low-millivolt level signals from the thermopile IR sensor and somewhat higher-level signals from the substrate thermistor. The simplified formula for the thermopile voltage is derived from Stefan-Boltzmann’s law and the Seebeck effect, as seen here in Equation 1:
VTP = A × (TO4 – TS4)
Where VTP is the thermopile voltage, TO is the object temperature, and TS is the sensor temperature. A is composed of the constants (RTH x N x S x ε x σ x F) where RTH = thermal resistance, N = number of thermocouples, S = Seebeck coefficient, ε = net emissivity, σ = Stefan’s constant, and F = field of view. Adding to the complexity of this equation, the substrate temperature is measured by a thermistor, so the Steinhart-Hart (or equivalent method) must be used to convert the thermistor resistance into substrate temperature.
With all the hassle of providing an amplifier to boost the low-level analog signal from the thermopile, filtering out the noise from the amplified signal, and then doing all the math, the results I obtained were not very good. In the end I used a MLX90614 (single-pixel) digital IR sensor, which provided much better results.
In the case of the MLX90640 device, the calculations needed are much more complicated. I don’t just mean that each pixel has its own set of calibration coefficients—there’s just a whole lot more calculation needed overall.
Although the MLX90640’s “friendly” package and convenient I2C interface were encouraging, I was concerned about the complex math needed to use this sensor. While a part of this was my concern about writing such a program, I also wondered how hard my host MCU would have to work to crunch the numbers. The amount of MCU SRAM memory needed was also a concern.
Melexis obviously anticipated this stumbling block, so they wrote a driver for this device, which they prominently display in their datasheet. This can be found on the Melexis GitHub site, a link for which is provided on the Circuit Cellar Article Materials and Resources webpage. It consists of an API written in C as well as a dedicated I2C driver for the device. This Github site also contains a PDF file titled “MLX90640 driver” which describes the various API functions, as well as describing the I2C driver itself.
This was a good first step, but an Arduino example sketch would be even more useful. Thankfully, I found such a sketch, written by SparkFun. They sell a small breakout board containing this sensor, as shown in Figure 5. Since the MLX90640 is easy to mount on a board, I didn’t pay extra to get this breakout board and instead purchased just the sensor itself from DigiKey.

SparkFun offers a breakout board for the MLX90640. Due to the ease of mounting the MLX90640, I didn’t bother to use one of these breakout boards.
Along with this Arduino sketch, SparkFun has also written a Processing app that runs on a PC, allowing you to visualize the images produced by this sensor. Figure 6 shows an example of the MLX90640’s image output (provided on the SparkFun GitHub site). As you can see, this is quite detailed, considering the MLX90640 sensor only contains 32 × 24 pixels. I believe that SparkFun uses some Gaussian smoothing routines to “up-sample” the MLX90640’s actual 32 × 24 resolution. I didn’t try this Processing app myself, as I didn’t have an easy way to get the MLX90640’s I2C signal into the PC (via USB).

This is a screen capture of an MLX90640 image, after being processed by a PC-based Processing program provided by SparkFun, in conjunction with their MLX90640 driver library, which is used in this project.
I should mention that although SparkFun has provided an Arduino MLX90640 sketch, due to the complex math mentioned earlier—as well as memory constraints—this sketch will not run on any of the earlier AVR-based Arduino boards, such as the Uno. To store all the necessary floating-point variables requires 20,000 bytes of SRAM. This SRAM requirement is easily met by any ESP32 device. The ESP32 also contains hardware floating-point support, so the complex calculations used by the MLX90640’s library were also deemed to be easily handled.
Displaying the IR Camera’s Output
I was interested in providing a display which would be comparable to that shown in Figure 6. I didn’t expect it to be quite as good as I knew that the ESP32 MCU would be hard-pressed to do any advanced Gaussian smoothing—while also streaming the image out to a cell phone’s web browser—at a reasonable frame rate.
I settled on an image size of 320 × 240 pixels, which is a common resolution for LCDs. This meant that I would be expanding the MLX90640’s 32 × 24 resolution by a factor of 10, in both the X and Y axes. I’ll go into the up-scaling algorithm that I used later.
The output of the MLX90640 is an I2C stream of 768 single-precision floating-point numbers per image frame. Each of these values expresses the temperature in degrees Celsius. Thus, a frame consists of 3072 bytes of temperature data plus a few more parameter bytes. The MLX90640 is only capable of I2C clock rates of up to 400k during its initialization phase (while it reads the EEPROM calibration parameters). However, after this initialization has finished, it can be switched to a higher I2C rate of up to 1MHz. Assuming it sends this data as a binary array, it could perform this transfer in about 3 milliseconds. Therefore, the I2C transfer time is an insignificant portion of the overall frame rate I was expecting to achieve.
To provide a display with adequate contrast, it makes sense to determine the minimum and maximum temperatures present in each frame and then scale this into the full contrast range of the display. Most FLIR cameras map the range of temperatures present to a range of colors—not as shades of gray. Humans equate blue with cold and red with hot, so it makes sense to map the coldest temperatures into the blue section of the color spectrum and the hottest temperatures into the red section of the spectrum. Increasing intermediate temperatures would be represented by orange, yellow, and green, respectively.
To do this, first convert the MLX90640’s temperature data into the HSV color format. This is a color representation scheme using three parameters: Hue, Saturation, and Value. Hue corresponds to the actual “color” itself, Saturation is the intensity/purity of that color, and Value is the overall brightness. The MLX90640’s temperature readings are mapped to values between 0 and 255 and are fed to the Hue variable. The Saturation and Value settings are fixed at 255 (the 8-bit maximum value).
However, most video displays, including those used in cellphones, expect their video signal to be in an RGB format (Red/Green/Blue). These are the colors emitted by the LEDs used in modern displays (and the phosphors found in CRT displays that were prevalent when this format was defined). Therefore, the HSV values must be converted into an RGB format.
Given the 18-bit ADC contained in the MLX90640, it seems like the optimum RGB format would be the RGB565 format. This is a 16-bit value, split up as follows:
- 5 bits for Blue
- 6 bits for Green
- 5 bits for Red
However, when I tried to send RGB565 encoded images to the web browsers that I use, it did not render them. While I’m not very knowledgeable on the HTML standards used by web browsers, I read that browsers will always render RGB images where each of the three colors are 8-bit values (24-bit RGB format), but don’t often handle other formats.
The size of a 320 × 240 RGB24 image is 230,400 bytes. While the ESP32 MCU family contains up to 512KB of SRAM, not all of this is available for your program variables, arrays, and so forth. 200KB of this is IRAM, which is where your Flash-based program code is moved when the program is executing. The rest of the memory is segmented into two segments: one for local variables and one for the heap. There is no contiguous memory segment large enough to fit this 320 × 240 RGB24 image. The ESP32-C3 module that I was hoping to use in the final project has even less RAM (400KB) [2].
Having worked with ESP32 camera boards, I know that they can collect and stream much higher resolution images than what we are dealing with here. However, the way that they accomplish this is by including a 4MB to 8MB PSRAM chip on the ESP32 camera board.
While I was breadboarding this project, I initially tried an Espressif ESP32S3 Devkit C-1 board, which contains an 8MB PSRAM chip [3]. I was able to fit the whole 320 × 240 RGB24 image into a PSRAM-based array. However, as I developed the code, I realized that I could process the MLX90640’s 768 temperature values one horizontal line at a time and then stream those 320 RGB24 values out to the cellphone. Doing it this way only required a 960-byte array, so any member of the ESP32 family would suffice. I wanted this project to fit into a tiny enclosure, so I chose a Seeed Studios XIAO ESP32-C3 module that I had on hand (Figure 7).

This shows the tiny XIAO ESP32-C3 module sold by Seeed Studio and used in the initial version of this project. The XIAO ESP32-S3 looks basically identical.
The ESP32 Camera boards stream their images using the JPEG format. Espressif has provided JPEG encoding/decoding in their camera API. I thought of using JPEG encoding especially since I was starting out with such a low resolution (32 × 24) and then upscaling it. This type of image would lend itself to very significant JPEG compression. Streaming out such small, compressed image files would certainly increase the frame rate I could achieve.
However, the Espressif JPEG encoding routine requires the whole image array to be present in memory. This basically means that you need an ESP32 board that contains PSRAM. While I completed this project using the XIAO ESP32-C3 module, I later discovered the XIAO ESP32-S3 board (containing 8MB PSRAM). While slightly more expensive, I ended up getting one of these modules and modifying my code to stream the image in JPEG rather than RGB888 format. More on this later.
Upscaling the MLX90640’s 32 × 24 resolution
As you can see from Figure 6, the MLX90640 image processed on a PC computer, you can extrapolate the MLX90640’s low resolution into a reasonable image if you are prepared to do a lot of math in the form of Gaussian smoothing (or something similar). I was afraid the ESP32 would not be able to handle a Gaussian smoothing task at a reasonable frame rate. Instead, I wrote my own less complex algorithm, which does the following:
- For a given horizontal line, it calculates a linear color gradient between each two adjacent pixels, thus generating 10 upscaled pixels.
- This upscaled horizontal line is streamed out as five consecutive (and equal) horizontal lines.
- The same upscaling is repeated, but this time taking the average value of each pixel in horizontal line (x) and horizontal line (x+1), then generating new gradients using these new averaged values.
- This upscaled horizontal line is streamed out as the next five consecutive lines.
- Repeat this 24 times to match the MLX90640’s vertical resolution.
This results in an image that has more apparent resolution in the horizontal plane than in the vertical one but is nevertheless quite presentable visually. The math involved in this upscaling is much less complex than that used by the SparkFun PC program (which generated the image shown in Figure 6). While I mentioned the need for one 960-byte array to handle one horizontal line of the image at a time, I actually used two such arrays to be able to upscale each horizontal line into two different ones, as shown in the bullet list above.
The Gradient and Temperature Range Display
Figure 8 is a screen capture of this IR camera. Along the bottom is the gradient bar, which shows the relationship between measured temperature and the hue of a pixel. The lowest temperature found in the image is rounded down to the nearest integer and displayed on the left. The highest temperature is rounded up and displayed on the right. The colors used between these two extremes are displayed in the gradient bar connecting these two values. I had to write my own routine to display numbers on this bit-mapped image, including generating an 8 x 16 font.
The ESP32 Web server
Ideally, it would be nice to write a cell phone app that would display the IR camera’s output on the screen. Writing an iPhone (iOS) app is not something that I have ever done and generally requires one to be signed up as an Apple developer and familiar with Apple’s Swift programming IDE. You also need a Mac PC to run this software. It’s somewhat less of a challenge to write a native Android app, but I’ve not tried that either.
Another possibility would be to use the Android GUI-O app. This app is basically a command interpreter program that gets its commands from a host MCU via Bluetooth or Wi-Fi and renders a dashboard on the cell phone, based upon the received commands. I have used it in past projects, and it does have the capability to display videos in RGB format.
For this project though, I decided to have a XIAO ESP32-C3 module act as a webserver and use the phone’s web browser to display the IR camera image. Initially, I configured the ESP32-C3 to log in to my router, in Station mode. I also added the DNS capability to my app, allowing me to merely use “ESP32-CAM/stream” as the URL.
— ADVERTISMENT—
—Advertise Here—
My office is at the opposite end of my house from where my router is located. At the breadboard stage of the project, when I was using an ESP32S3 DevKit-C1, the signal strength (RSSI) I was seeing was around -60dBm. This was a strong enough signal to stream the IR camera video at a decent rate. However, when I switched to the small XIAO ESP32-C3 module, even with its external patch antenna, the RSSI values dropped to -75dBm to -80dBm and the streaming became slow and somewhat erratic.
At this point, I decided to switch the ESP32 to the Access Point (AP) mode. For this project, the cell phone is right next to the IR camera, and the RSSI values are much better, thus allowing for much faster streaming. In my program, I define the name of the AP to be “ESP32IR,” so using the Settings menu on the phone, you select the Wi-Fi access point with that name.
When set for AP mode, the IP address of the ESP32 is fixed at 192.168.4.1, so that is the URL that you use in the web server. I configured the web server to respond to its home page by sending out the text message “ESP32 IR camera.” When you append “/stream” to the 192.168.4.1 URL, you get the actual image stream.
ESP32 has several different web server frameworks. Initially, the web server API was provided by library files specified in the webserver.h file. Later, Espressif introduced the ESPAsyncWebserver library. This version offers many advantages, enhancing the overall performance of the ESP32 as a web server. While I have very little knowledge of what goes on under the hood in either of these two web server variations, I do know that the Async version can handle many clients simultaneously and is not prone to delays from blocking routines—unlike the earlier version. However, these advantages are not applicable for this project.
Another consideration is what ESP32 family member is being used in the project. Although I originally used an ESP32S3 DevKitC-1 while breadboarding the project, I had planned on using a tiny XIAO ESP32-C3 in the final version, due to the small size of the enclosure I wanted to use. While the legacy ESP32 and the newer ESP32S3 MCUs each have two identical 240MHz Xtensa MCU cores, the ESP32C3 has only a single 160MHz Risc-V core.
As I understand it, when using the Arduino ESP32 board support package, all Wi-Fi-related routines are performed by one of the ESP32/ESP32S3 cores, and your code is performed by the other core. Since I am processing the MLX90640’s data and streaming out one horizontal line of the image at a time, the ESP32(S3) should be able to do these two tasks simultaneously—assuming the webserver functions are non-blocking. Both my image processing task and the web streaming involve a lot of MCU processing, so parallel execution would be beneficial. But the EPS32C3 contains only one Risc-V MCU, so this speed enhancement is not possible.
The operational flowchart of the project is shown in Figure 9. This is performed when the webserver receives the URL “192.168.4.1/stream.” After responding positively to the initial GET command from the cell phone, the webserver then sends out a standard Bitmap image header, containing the size and format of the image data. Then a single horizontal line of MLX90640 temperature is processed into two discrete horizontal image lines, each sent out 5 times. When all 240 vertical lines have been sent out, the webserver terminates the message with CR and NL characters.

This is a flowchart of the image collection/processing done by the project after the user enters the project’s webserver URL into their web browser. This flowchart only applies to the initial ESP32C3 version of the code.
Note that when you are flashing the program to the ESP32-C3 MCU, you must set the USB-CDC on Boot option to ON in the Tools menu. This enables the USB-Serial port which is used for debugging.
Circuitry
The hardware involved in this project was much easier to obtain than coming up with the necessary software. From the start, I was planning on using a small Hammond 1593QGY enclosure (4.3” long × 2.5” wide). I also wanted to power it with a small LiPo battery in the 200mAh capacity range. Therefore, I was looking for as small an ESP32 module as I could find and preferably one with a built-in LiPo charger.
I had XIAO ESP32-C3 modules by Seeed Studio on hand. As you can see from Figure 7, these are very small. They include a LiPo charger, USB-C port for flashing/charging, and a U.FL connector for an external antenna. There is no on-board antenna—not even one of those tiny ceramic chip antennas. The required patch antenna is supplied with this board.
Figure 10 shows a schematic of the project. The MLX90640 is connected to the ESP32-C3 via I2C, using 2.2kΩ pull-up resistors. I chose this low value as I am running the I2C bus at 800kHz (except during initialization when it must be limited to 400kHz). The MLX90640 wants a really clean 3.3V power supply—much cleaner than that available from the Xiao ESP32-C3 module’s LDO. Therefore, I added an MCP1700-3302 LDO to provide this clean 3.3V power. During development, I connected the XIAO module to my PC using the USB-C connecter—for flashing/debug purposes. During that time, the MCP1700-3302 was able to get its power from the ESP32-C3’s 5V pin. However, when powered by the LiPo battery, the 3.7V to 4.1V from the LiPo cell are NOT available from the same 5V pin. Therefore, I added diodes D1,D2 to provide power to the MCP1700-3302 in either scenario. These are Schottky diodes with only about 0.1V drop. Capacitors C1,C2 are needed at the output of the MCP1700-3302 for stability and to further filter out any residual noise.

This is the schematic diagram of the project. It remains the same regardless of whether the XIAO ESP32-C3 or XIAO ESP32-S3 version of the project is being used.
Connecting a LiPo battery to the XIAO ESP32-C3 is a bit of a hassle as the two tiny battery pins are on the underside of the board. I used a socket for the Xiao board, and it wasn’t too hard to route the battery cables to these terminals on the underside of the module.
The MLX90640 and its associated MCP1700-3302 LDO are mounted on a separate board that sits behind the front panel wall. Figure 11 is a photo of the unit just before the top cover is attached. The patch antenna supplied with the XIAO module is the black rectangle below the XIAO module.
Upgrades
After finishing the project, I discovered the Seeed Studio ESP32-S3 module. While this is a few dollars more than the ESP32-C3 module, it contains the faster ESP32S3 MCU plus an 8MB PSRAM. I decided to get one of these modules and try to improve the project’s frame rate by:
- Using the inherent speed advantage of the dual-core ESP32S3
- Replacing the amount of RGB888 image data streamed, per frame (245,760 bytes), by instead streaming a JPEG image (approximately 30KB to 40KB).
Using the ESP32S3/PSRAM, I now keep the complete image (upscaled to 320 × 256) in a PSRAM array. Espressif has written a JPEG encoding routine for use with the standard video cameras that are commonly used with a ESP32 MCU (plus PSRAM). However, that JPEG encoder routine is closely coupled with the camera driver, and not readily usable. After much searching, I discovered that Espressif’s JPEG library also includes a routine that can be passed a pointer to an RGB888 image array (usually in PSRAM) and which will return a pointer to the compressed JPEG array. This is exactly what is needed for this project. Listing 1 shows the entire callback routine that handles the image streaming function. The line starting with bool jpeg_converted = fmt2jpg() contains the fmt2jpg() routine that does the JPEG compression. The only other special code needed is that required to define the pOutput array, which resides in PSRAM. This is shown in Listing 2.
void handle_bmp_stream() { esp_err_t res = ESP_OK; char part_buf[64]; // added for jpeg routine size_t _jpg_buf_len = 0; uint8_t * _jpg_buf = NULL; String response = “HTTP/1.1 200 OK\r\n” “Content-Type: multipart/x-mixed-replace; boundary=frame\r\n\r\n”; server.client().write(response.c_str(), response.length()); while(true) { capture(); size_t hlen = snprintf(part_buf, 64, “--frame\r\nContent-Type: image/jpeg\r\nContent-Length: %u\r\n\r\n”, _jpg_buf_len); server.client().write(part_buf, hlen); bool jpeg_converted = fmt2jpg(pOutput, pofs, 320,256,PIXFORMAT_RGB888,40,&_jpg_buf, &_jpg_buf_len); server.client().write((const char*)_jpg_buf, _jpg_buf_len); server.client().write(“\r\n”, 2); free(_jpg_buf); // free the jpeg buffer if(!server.client().connected()){ break; } // Serial.println(millis()); // shows an update rate of 5 Hz }}
Listing 1This is the code for the webserver callback function invoked when the URL 192.168.4.1/stream is entered into the phone/tablet’s web browser. This Listing is for the ESP32-S3 version of the project, which sends the IR images as a JPEG file.
pOutput = (unsigned char *) ps_malloc (n_elements * sizeof (unsigned char)); if(psramInit()){ Serial.println(“\nPSRAM is correctly initialized”); }else{ Serial.println(“PSRAM not available”); }
Listing 2
This shows you how to define a large array in the PSRAM contained on the XIAO EPS32-S3 board.
Switching to the ESP32-S3/PSRAM and sending JPEG compressed images increased the frame rate from 1/second (using the ESP32-C3) to 5/second. In both cases, using a weighted average routine, in the time domain, to filter the image data so that it’s more steady/stable. However, with the faster ESP32-S3 version, I can do more filtering, resulting in a steadier image.
The XIAO ESP32-S3 module is pin-compatible with the XIAO ESP32-C3. However, while the physical pins I used for the I2C port don’t change from one version to the other, they are defined differently in each case:
- ESP32C3: SDA GPIO 6 SCL GPIO 7
- ESP32S3: SDA GPIO 5 SCL GPIO 6
This is handled in each version of the program by configuring the wire.begin() appropriately. Both versions are included on the Circuit Cellar Resources webpage. Also included is the SparkFun MLX90640 library [4].
I used the Arduino IDE version 2.3.6 to compile the programs. Note that I also used an older Espressif ESP32 board support package: version 2.0.17. I believe that the newer Espressif board support packages version 3.x.x may not be compatible with the libraries that I used. I run a separate PC computer, with version 3.3.0 of the ESP32 BSP loaded, for those instances when I am using the latest ESP32 MCUs, such as the ESP32C6, which require the 3.x.x BSP.
Iterations win the Day
While I am getting increasingly familiar with most aspects of the ESP32 family, I’ll admit that programming the webserver to stream the image generated by the MLX90640 thermal data was quite challenging. Looking at the finished code, it doesn’t look too involved, but it took a lot of iterations to get it all working. Although I did not require a PSRAM chip in the ESP32-C3 module’s version of the project, I did learn how to use it when programming the faster ESP32-S3 module’s version of the program.
I first used a Melexis MLX90640 a few years back in another project. At the time it was the best device in terms of performance vs. cost. From what I can find on the web, that is still the case today.
— ADVERTISMENT—
—Advertise Here—

DigiKey | https://www.digikey.com
Espressif | https://www.espressif.com
Hammond | https://www.hammfg.com
Melexis | https://www.melexis.com
Seeed Technology | www.seeedstudio.com
SparkFun | https://www.sparkfun.com
REFERENCES
[1] Melexis MLX90640 IR camera https://www.digikey.ca/en/products/detail/melexis-technologies-nv/MLX90640ESF-BAB-000-TU/8638464
[2] Seeed Studios XIAO ESP32-C3
Cost Effective RISC-V MCU with Wi-Fi, BLE – XIAO ESP32C3
[3] Seeed Studios XIAO ESP32-S3
High-Performance Dev Board with Wi-Fi and BLE – XIAO ESP32S3
[4] MLX90640 Driver Library https://github.com/melexis/mlx90640-library.git
PUBLISHED IN CIRCUIT CELLAR MAGAZINE • JANUARY 2026 #426 – Get a PDF of the issue
Sponsor this ArticleBrian Millier runs Computer Interface Consultants. He was an instrumentation engineer in the Department of Chemistry at Dalhousie University (Halifax, NS, Canada) for 29 years.




