Introduction: IR Thermometer for Sleep

About: Lazy Old Geek

So this Lazy Old Geek (L.O.G.) recently purchased an IR thermal module, MLX90614 from AliExpress.com. See pictures

This is the same type of sensor used in those forehead and ear thermometers shown in the third picture. They’re called non-contact because the actual sensor element doesn’t really contact the skin.

I wanted to try this to measure my skin temperature when I sleep. I think the general consensus is that your body temperature goes down when you’re sleeping, then goes up as you wake up.

Here’s an interesting article:

https://www.sleep.org/does-your-body-temperature-c...

“until it hits its lowest point a couple hours before you wake up in the morning. “

“Since temperature is an such important part of determining when we fall asleep, it’s interesting that during rapid eye movement (REM) sleep, your brain’s temperature-regulating cells switch off and let your body temperature be determined by how warm or cool your bedroom is.”

Here’s another:

https://www.tuck.com/thermoregulation/#:~:text=Wha...

“From your peak in body temperature in the early evening to the lowest point just before waking up, you experience a decrease in core body temperature of 2 degrees Fahrenheit.

The temperature of both the brain and the body fall during NREM sleep. The longer the NREM-sleep episode, the more the temperature falls. By contrast, brain temperature increases during REM sleep. The control of body and brain temperature is closely tied to sleep regulation.”

So I wanted to measure my body temperature throughout the night.

Step 1: Design IR Thermometer

My design is to use an MLX90614 IR temp sensor with a spacer so that the distance from the skin stays constant. So I wear a CPAP mask for sleep and will attach the IR sensor to it. (You could probably just use a headband). The ideal location is (apparently) the temporal artery but I am more interested in temperature change rather than actual temperature.

The IR sensor will store information at fixed intervals throughout the night (I started with 30 seconds, but am now using 5 minutes). The MLX90614 also measures the sensor's ambient temperature.

I will also use a DHT22 Temperature/Humidity sensor to monitor ambient room conditions. The data will be stored on a microSD card.

A DS3231 RTC (Real Time Clock) will keep track of the time.

DEVICE INFORMATION:

MLX90614 IR Temp Sensor

Voltage: 3V (There also is a 5V version)

Interface: I2C (SCL/SDA)

Arduino Library: Adafruit library

DS3231 RTC Real Time Clock

Voltage: 3.3-5.5V

Interface: I2C (SCL/SDA)

Features: battery back up

Arduino Library: https://github.com/PaulStoffregen/DS1307RTC

microSD adapter

Voltage: 3.3V (modified)

Interface: SPI (SCK/MISO/MOSI/CS)

Features: level converter IC

Arduino Library: SPI

DHT22

Voltage: 3.3-6V

Interface: digital one wire bus

Features:

Arduino Library: adafruit/DHT-sensor-library

3.3V Micro Pro Arduino

Voltage 3.3V

Features: ATmega32U4 microcontroller

MODIFICATION: DS3231

The AliExpress module I bought is supposed to be designed to use a rechargeable battery, LIR2032. The charging circuit does not work. I tried it out. After about a day, the battery was dead.

Well after some searching on the Internet, I found this article:

https://www.onetransistor.eu/2019/07/zs042-ds3231-...

I agree with this analysis but thought the LIR2032 would charge adequately but not excessively. I was wrong. My DS3231 although also marked as ZS-042 as in the article was slightly different then his but almost the same. So I unsoldered the diode seen in the picture and installed a CR2032 battery. Without the diode the module will not try to charge the battery. Now the DS3231 holds the correct time even with power disconnected and the battery should be good for many years.

MODIFICATION: microSD Adapter

So I bought this microSD Adapter from AliExpress.com. It’s designed to run with a 5V microcontroller and even includes a level shifter IC. For my application I am using 3.3V power so I shorted the input to the output of the voltage regulator. (The level shifter seems to work okay with 3.3V signals). I mark 3.3V conversions with yellow nail polish. Schematic is attached.

Step 2: Hardware

HARDWARE:

Right now I consider this more of a feasibility study so I designed the schematic and breadboarded the circuit per schematic. The second picture shows the major parts.

Step 3: IR and Mask

For the IR sensor,MLX90614, I built a 4 wire cable to connect it to the breadboard. I hot-glued a spacer to the IR sensor. The sensor is about 2mm from the edge of the spacer.

I attached an adhesive Velcro piece to the back of the IR sensor. On the side of my CPAP mask I attached a mating adhesive Velcro strip. Now the IR sensor is held in place with the Velcro. The CPAP mask holds it against my skin.

FYI: Since these pictures, I moved the sensor to the right side, since I generally lie on my left side and it was uncomfortable.

Location: The forehead thermometer, sometimes called temporal artery thermometer is supposed to be swept across the forehead:

https://www.researchgate.net/figure/Scanning-the-t...

The attached picture is from this webpage.

Now I’m guessing that my IR sensor is more at location 12 or 14 but for my purposes I don’t care about actually temperature. I’m mostly interested in temperature changes over time so location shouldn't be critical.

Step 4: Arduino Software

The sketch uses the DS3231 to tell time. The sketch has a start time (start recording), stop time and recording interval. It records the date, hour (decimal), the DHT22 temperature, RH, the MLX90614 ambient temperature and IR temperature to a CSV (comma separated value) file. (I use Microsoft Excel to read this file)

Daylight Saving time has been a problem for me. I ran across the following by JChristensen:

https://forum.arduino.cc/index.php?topic=96891.0

https://github.com/JChristensen/Timezone

To use this, you first have to set the RTC to UTC (Coordinated Universal Time), this is time in Greenwich, England. Well, I didn’t know how to do that but found this article:

https://www.justavapor.com/archives/2482

Rewrote it for Mountain time (attached) UTCtoRTC.ino

This sets DS3231 to UTC time 6 hours later than Mountain time

Then I incorporated the timezone into my Sketch. To be honest, I haven’t tested it out so just assuming that it works.

Software/Hardware Setup

Additional libraries needed:

https://github.com/PaulStoffregen/DS1307RTC

https://github.com/JChristensen/Timezone

https://github.com/adafruit/Adafruit-MLX90614-Libr...

https://github.com/adafruit/DHT-sensor-library

Install a CR2032 battery in the DS3231 RTC. Connect to the 3.3v Arduino Pro Micro.

Run UTC to RTC.ino. This sets the DS3231 to UTC (Greenwich Mean Time).

Format a microSD card. I use Windows, the format is FAT32. Insert it in the microSD card adapter.

Setup and connect the IR sensor.

Load sketch, Infrared.ino

After a night, you can remove the microSD card and plug it into a PC.

The Night.csv can be opened with Excel (there is a way to open it with Libre Office (free))

Step 5: Testing and Conclusion

I read the microSD card with MS Excel. In the spreadsheet, I make another column called Difference which is the IRTemp -96. This shows the variation in temperature around 96F. Then I create a chart using the Hour in decimal compared to the Difference. The chart shows the temperature change throughout the night (not actual temperatures).

For Aug18, I included the file and the chart with my comments.

Some suggest the typical night is when temperature drops off until a couple of hours before waking up when it starts to rise again. The chart seems to follow that pattern.

What I find more interesting is the times when it starts to climb that may actually be REM sleep. I have sleep data from my Withings sleep mat for the same night that says I was in REM sleep from 3:15 to 4:50am. This corresponds closely to the IR graph when it rose slightly. The Withing also shows REM from 1:30 to 2 which is not quite as wide as IR shows.

Caveat: This does not agree at all with my Fitbit or my Go2Sleep ring.

For Aug19, I included the chart with comments. This was an unusual night as I had my windows open but there was a wild fire about 10 miles away blowing in smoke and ash. When I went to sleep, I was on the warm side and didn't sleep very well.

CONCLUSION:

So my setup seems to do what I wanted it to do.

I'm especially happy to see a possible link between IR temp and REM sleep and plan to do some further testing.