Sleep is a tricky thing to get right. Sometimes I wake up with headaches and sore muscles, sometimes I wake up with a stuffy nose, sometimes with dry skin, and yet other times I wake up feeling great.
Why can't I feel great every morning? As an engineer, I decided to get to the bottom of this using both data and science.
Building a Device to Gather Data
Research has shown that indoor air quality plays a significant role in sleep quality. With this in mind, my first step was to measure the air quality in my bedroom.
I began by wiring a FeatherS2 microcontroller with just about every air sensor I could find: pressure sensors, temperature sensors, humidity sensors, electrochemical sensors, ozone sensors, infrared CO2 sensors, and particulate matter and dust sensors.
I even included a Geiger counter on the off-chance a truck transporting radioactive materials drove by my house.
Fortunately, each sensor I compiled used the I2C communication protocol, so wiring them up was relatively simple, as was housing them in a 3D-printed enclosure. My air quality monitor was complete. Building it required a few hours of my time and roughly $120.
My completed DIY air quality monitor
Once I Gathered the Data, How Would I Log and Analyze it?
Next, I had to determine how I would log and analyze the monitor's data.
Enter the Freedom Robotics stream tab — the premiere tool we all know and love for its ability to record, replay, and stream robot sensor data!
Although designed for robots, I knew it would provide the perfect user interface and experience for recording and reviewing arbitrary sensors collected from Internet of Things (IoT) devices like my air quality monitor. To support future work like this, we built the MicroLink, a library to publish data from microcontrollers that run on CircuitPython or MicroPython.
Indoor Carbon Dioxide Levels
The air quality monitor paid for itself after a single night of collecting data. As high CO2 levels are known to adversely affect sleep quality, I was surprised to find my bedroom measuring over 1200 ppm — easily crossing the 1000 ppm threshold, which is known to induce drowsiness, headaches, and other symptoms detrimental to a good night's sleep.
My solution? Crack my bedroom window open at night and watch the CO2 levels plummet. But how wide should I open it each night to keep the levels optimal without sacrificing heat? A few days of experimenting gave me my answer.
I also learned how quickly CO2 levels drop when I open my windows during the workday. Here, at 14:42, you can see the levels drop from over 900 ppm to just under 700 ppm within about 8 minutes. Each time I did this, I felt refreshed, alert, and productive.
Do Humidifiers Even Work? If They Do, Are They Reliable?
Another problem I sought to solve was waking up thirsty with dry skin. Further, my bedroom plants were not faring well and were prone to dry out rather quickly.
I had recently bought a humidifier to address my dryness woes, but was it working? Two sensors in my air quality monitor proved that it was.
The periodic behavior detailed in the readout below is due to the humidifier regularly turning off according to its set point, and shortly after 10 a.m., running out of water. When these instances occurred, humidity levels started to drop back to their natural dry levels.
I also discovered that the humidity levels in my room reported by the humidifier were nowhere near what my air quality monitor was reporting.
When the humidifier reported 57 percent, actual levels were between 35-40 percent. One might think this was due to miscalibrated sensors, but the discrepancy was actually caused by the humidifier sitting in a pool of its own fog.
Humidity levels near the humidifier will always be higher than elsewhere in the room. As such, one cannot possibly get an accurate measure of the room's humidity when near it. This is a fairly standard concept that is accounted for when temperature control systems are designed for laboratory equipment, but not when it comes to consumer products. With this in mind, the variance made sense.
Never trust readings from consumer air purifiers and humidifiers. Always make independent measurements using your air quality monitor from an area of the room away from the consumer device and adjust your set points accordingly. In this case, it’s evident that my set point of 60 percent resulted in an actual room humidity level of around 38 percent.
Keeping My Air in Check with "Smart Alerts"
Instead of regularly checking my air quality monitor graphs throughout the workday, wouldn't it be great if the system could notify me automatically when a significant shift in air quality occurs?
With Freedom Robotics, you can do just that by setting up smart alerts. As a result of the platform's multiple integration options, I now automatically receive an alert via Slack instructing me to open the window whenever CO2 levels are high.
How To Build Your Own Air Quality Monitor
You can build your own air quality monitoring system! Check out this repository for 3D print files and a list of parts you need for assembly. You can also choose to purchase only a subset of the sensors I used and adjust the configuration accordingly.
Exploring Microcontrollers Using Freedom Robotics
Have another microcontroller/IoT project you'd like to connect to the Freedom platform for monitoring or debugging? As long as your microcontroller supports CircuitPython or MicroPython and has Wi-Fi capabilities, you're good to go!
To get started, check out the MicroLink documentation, which includes a simple "hello world" example that publishes an integer count to Freedom Robotics. It's easy to configure in a manner that will allow you to publish data from any of the sensors or variables in your MicroPython code.
Freedom Robotics provides the essential building blocks for robotics projects with "out of the box" features that ensure you can create robotic solutions capable of overcoming any challenge. Platform agnostic and compatible with any robot, it installs in just seconds and helps robotics companies bring their products to market 10x faster with half the resources.