Snooze Control

This Raspberry Pi-powered device uses ML to track when a baby is sleeping to help parents set a healthy, consistent schedule.

Nick Bild
1 year agoMachine Learning & AI
Monitoring a baby's sleep schedule (📷: Caleb Olson)

In today's fast-paced world, it is not uncommon for parents and their babies to have an irregular sleep schedule. While it may seem like a minor inconvenience, the truth is that an irregular sleep schedule can have significant negative impacts on a baby's health and development, as well as the well-being of their parents.

Recent studies have shown that an irregular sleep schedule can disrupt a baby’s natural circadian rhythms, which can lead to sleep disturbances, mood swings, and feeding difficulties. It can also increase the risk of Sudden Infant Death Syndrome (SIDS), as well as impair cognitive development and social skills.

When the baby is not sleeping on a regular schedule, neither are the parents. They can experience a host of negative impacts from a loss of sleep, including fatigue, irritability, and difficulty concentrating. This can impact their work, personal relationships, and overall quality of life.

So, what does a healthy baby sleep schedule look like? According to the American Academy of Pediatrics, newborns should sleep for a total of 14-17 hours a day, with most of that sleep taking place at night. As babies grow and develop, they need less sleep, but they still require a consistent sleep schedule to maintain healthy sleep habits.

It is challenging to maintain a consistent schedule, however, because that sleep is broken up into short stretches of about 30 minutes to a few hours. So, to know when to leave the baby to try and fall back asleep, and when to go pick them up requires that the parents know when the baby is in fact sleeping. Keeping track of this data manually can be a real pain, so a number of commercial devices are on the market to automate the process.

But these devices can be expensive, with high up-front costs for the hardware, and often pricey subscription services to go with them. And anyway, do you really want sensors capturing images and other sensitive information from your nursery and sending it to the cloud? Engineer and hardware hacker Caleb Olson did not, nor did he want to fork over the cash for a commercial device. But he did want to make his wife happy, so he got to work designing his own baby sleep tracker.

The device is centered around a Raspberry Pi 4 single-board computer that provides the horsepower for the project. This was paired with a camera that supports the Real Time Streaming Protocol to wirelessly transmit images of the baby to the Raspberry Pi. To determine when the baby is sleeping MediaPipe, an open source framework for building machine learning-powered computer vision pipelines, was leveraged.

MediaPipe was used to look for certain features, like eyes and the mouth, and to determine if they are open or closed. Based on a simple heuristic, the state of each tracked feature was used to determine whether or not the baby was awake. For example, if the eyes are closed and no movement is detected, the baby is considered to be asleep. Each time the baby falls asleep, the system logs that event to a CSV file.

To make it easy to understand the logged data, Olson developed a companion web application. It answers questions about when the baby woke up, how long the baby slept for, when is the baby expected to take his next nap, and more. A very slick chart consisting of concentric circles, one for each day, that shows periods of sleep and wakefulness, was also included. As these circles stack up, it makes it easy to see if the patterns are regular, or all over the map.

The data can be leveraged in other ways, as well. Olson created a smart nightlight, for example, that is automatically turned on when the baby wakes and it is feeding time. It gives off a dim red glow so as to minimize the effects of the sleep disruption.

And for parents that hate their baby, Olson also demonstrated how one can create a robotic demon owl that will “enrich their waking experience” by loudly shrieking and spinning its head around rapidly the moment that junior wakes up. This add-on is not recommended as part of a healthy sleep routine, to put it mildly.

The full source code is available on GitHub and has been open sourced, so if you have a little one, go grab it and build your own low-cost sleep tracker for a happier, healthier home (assuming you do not build the demon owl, that is).

Nick Bild
R&D, creativity, and building the next big thing you never knew you wanted are my specialties.
Latest articles
Sponsored articles
Related articles
Latest articles
Read more
Related articles