Has anyone here made a sleep tracker for measuring your quality of sleep at night?
I know there are various fitbit type things that claim to do this, but I figure it should be possible to do better. Some kind of DIY sleep lab would be interesting to try.
So, I have looked in to this. I even had a fitbit that i was hoping to use to determine if I fell asleep at night and turn off lights in my home automation system.
The down side I ran into is this. I had fitbit setup with ifttt since that was something it could interface with. The sleep detection worked. HOWEVER. It only actually posted info to IFTTT when you woke up, at that point, all sleep related data was submitted. So it didn't track it real time.
I have been looking in to how to integrate sleep in to my HA but also like you mentioned quality of sleep. The fitbit utilizes motion to determine "restless" sleep. Attaching a bunch of sensors to myself doesn't seem like it would yield comfortable natural sleep. So potentially stuff like a mesh of piezo sensors under a mattress topper would work. that would detect when the values change indicating turning, movement.
Temperature should be easy (fitbit probably does it, i had a cheap one so it did not).
If you want to get crazy (which if i had time i would go this route) you can get a fitness watch with a certain chip in it, and reprogram it.
That's what he did. This could be REALLY REALLY cool. You could code in your own parameters and what not, since it's bluetooth LE you could track it via phone or just remote sensors.
Once you have some basic "restless" night tracking you could do some experimenting (even with the fitbit).
- track your sleep for a week or 2 to get a baseline of how much time each night you sleep "restless"
- change thermostat temp up/down - track again and compare.
- monitor body temp and see if warmer/colder = restless. find sweet spot.
- integrate body temp monitor to HA system to control thermostat to keep you correct temp
If you make any progress, definitely let me know, i would be interested to see what you come up with!
@crankycoder The hard part of reprogramming the wrist watch isn't programming the MCU per se, but knowing what library to use to have it drive the sensor (or even knowing what sensor they're using). I think it probably isn't worth the effort. It would be easier to make your own from scratch, because then you could at least pick a sensor that's easy to interface with.
What I had been thinking of was a couple things:
Put scales under each of the four bed legs. That way you can measure shifting around, and you'd know whether the person is still or not. I'm not sure if that would be sensitive enough or not.
There are goggles you can put on that detect rapid eye movement. I tried a prototype 30 years ago, although at the time they were for purpose of lucid dreaming. I bet now it would be possible to do something better, or maybe by now there's even something you can buy to check for REM sleep.
I'm not sure what other ways there are to check for quality of sleep. I wouldn't want to wear an EEG, which is what some sleep labs use (or at least used to use). For one thing, you don't sleep very well with all that gear on.
I agree, I am wondering if just doing a small pcb, oled screen and some smd parts would be easier.
I don't want to wear extra stuff either. Definitely got me thinking though.
Did you see this?
I also remember seeing some Arduino code for a sleep tracker on Github.. although I can't find it now.
Woah. very cool. going to look in to those some more.
alowhum last edited by alowhum
I'm also building a sleep tracker alarm clock. This is what I'm working on:
- Use HB100 or similar doppler radar pointed at the bed. I have a normal radar in my current experiment, but I would also like to get the movement intensity as well, for even better detection. I don't want anything that has to be put in the bed, or that has to be worn. Too annoying. The data is sent to the controller.
- Use bright LED that the Arduino slowly fades up in intensity as the ideal wake up time approaches.
- If still not awake at the deadline time, play a sound. Either a normal buzzer that plays a tune, but preferably I want to use a little $2 device that allows for audio recording and playback, and that can be triggered via a pin. This way fun wake up messages can be played, which gives it a nice social aspect.
- An RTC keeps the time. I don't want users to have to set the time, so I'm exploring how to automate that (get it from MySensors most likely, but there ways of over engineering this..).
- Use a Serial LCD screen that has built in drawing functions to create graphs of the previous night. It also shows the time.
- Add in a MH-Z19B CO2 detector, and also show a graph for that. From experience I think a CO2 sensor is useful in the bedroom. This data is sent to the controller.
- Possible: use a PIR sensor to detect when people are standing up in the middle of the night (pointed to the regio above the bed, or the door), so that the system can be sure that this is an awake moment.
- Probably not: add in a CO sensor.
- Probably use a endless rotation knob with built in button to set the wake up time. Another option is a joystick (could be a fun design element).
- Pressing a button when you want to go to bed starts the system, and turns off the LCD. No light during sleep!
- When you are supposed to wake up the LED's but also the screen turns on, so you can see the clock and graph data.
- During the night, if the PIR is triggered, the screen could turn on shortly to show the time.
- Possibly: toggle if there is one or two people sleeping in the bed.
- Possibly: toggle if a child or adult is sleeping in the bed.
- The current design means that you have to turn on the alarm every night. The advantage is that you are less likely to record sex activities - that would be creepy.
- If two people sleep in the bed, the wake up functionality cannot be precise. But it can still work on a simpler level: wake both up when neither is in REM sleep - in other words, allow waking up procedure to start when there is significant movement.
https://code.google.com/archive/p/lolosalarmclock/ (2010, download the zip from Google Code). Youtube Video.
https://link.springer.com/chapter/10.1007%2F978-3-319-44215-0_36 (scientific, but hidden behind paywall )
https://www.instructables.com/id/Sleep-Cycle-Alarm-Clock-with-Motion-Sensor/ (very basic, alarm goes off after 3 detections of motion)
https://forum.mysensors.org/topic/9444/clock-with-temperature-humidity-and-co2-level-sensors/2 (MySensors alarm clock, no sleep cycle detection)
https://github.com/leoscholl/sense-alarm/blob/master/worker_src/c/accel.c (Pebble watch app that seems to use Sadeh algorithm)
What you could measure
What professionals measure:
"Professional sleep clinics use polysomnography,which involves taking multiple measurements including brain activity, eye movements, heart rate and rhythm, blood pressure, and the amount of oxygen in your blood." Source
I tried it last night, and my current RCWL 0516 detector detects very little movement. The most intense was 4 movements over the space of 5 minutes.Tonight I will try adding a PIR sensor and see if it detects a different pattern.
adamf663 last edited by
I had a sense sleep monitor by hello.is.
It used an accelerometer in a small disk that clipped onto a pillow. As is the case with all devices dependant on the cloud, it instantly transformed from a $130 sleep monitor to a worthless paperweight when the company went out of business.
jamzm last edited by
I don't see how you are going to develop a worthwhile device without wearable hardware. Sure, there are a few metrics you can monitor without, but this limits you to few options. I wear a C-PAP device. It monitors usage time, mask seal, events per hour, and humidifier, mask on/off and then gives you a score from 1 to 100. That's not much, and that's with a mask. When you go for a sleep study, the technicians place stick-on sensors on many locations on your body. The technology may have become more refined since i last had a sleep study, but i'm thinking that the sensors stuck to your body may be a necessity for this sort of thing. Here is a link to the Resmed site that my machine reports to. There's more info there. Good luck. https://www.resmed.com/us/en/index.html
Vincent Gijsen last edited by
THe NRF58122 can also be used with the NRF24l01 aircompatible protocol (instead of BLE), integrating even more into mysensors, as a notification device for example
- Use HB100 or similar doppler radar pointed at the bed.
I'm already shutting down wifi during night because I think we already eat too much waves (because of this +security, I don't want or can't rely on wifi), so I'm not sure if I would like to have doppler pointed to me during nights. Maybe I'm paranoid, maybe not
Well, scientifically speaking those high frequencies wouldn't penetrate your body.
More interestingly, I tried the PIR sensor last night, and to my surprise it gave more data than the radar sensor. It saw motion when the radar sensor didn't. So maybe the PIR is the way to go.
@jamzm It depends on what your goal is. While I can't speak for @NeverDie, my goal is not medical. And as my scientific sources in the post above point out, for simple things like figuring out the best time to wake you up, a simple movement indication is totally fine.
Basically the rule of the alarm clock should be:
- Wake up where there is at least some movement in bed, indicating the sleeper is not in the REM phase (when you basically become motionless).
Simple. And this is what one of the existing Arduino alarm clocks basically does.
With the Sadeh algorithm this can become a bit more precise, as you can also take the sleep cycle into account. The PIR sensor actually seemed to show periods of no movement 90 minutes apart. I didn't even expect that, since there were two people sleeping in the bed.
The Sadeh alghorithm is really simple too.
- If there are 15 continuous minutes in which there is very little to no movement, then this is designated as the REM phase.
- From then on you switch what you are looking for, and basically wait for a 5 minute period in which there is lots movement. That's the best time to start the wake up procedure.
@alowhum Interesting information. Do you know whether you actually feel better if you wake up according to that algorithm?
Yes, you do. This is the algorithm used in most of the armbands/apps.
The last sleep study I had was simple - they sent me home with a recording device attached to two finger sensors; one was for heart rate and oxygenation, one was supposed to detect REM sleep (both had lights aimed at the skin or fingernail, did not appear to be accelerometers). I was surprised that they could detect REM sleep in that manner, but it would be worth looking into.
I wonder if one could detect movement with a cheaper BLE wristband, like the Xiomi MiBand? Not sure if anybody has cracked the OTA protocol. (OTA meaning generic Over the Air, not FOTA = Firmware/Flash Over the Air). I used to have one (before some firmware update from Xiomi bricked it), and it had a very long battery life and was small).
Building one's own wearable device - homebuilt and yet sturgy seems likely to be bigger and clunky; but maybe others can build tiny wearables.
Doppler Radar - I don't think my turning over in my sleep would result in a lot of motion towards/away the sensor from if mounted on the ceiling or high on the wall.
Antenna Effects (RCWL-0506) - might work if mounted close enough. Perhaps multiple devices. Worth considering. (These are NOT radar despite advertising, but do detect local movement).
One thing which might also work is a camera near the ceiling, attached to some image processing (NOT to a recorder!). Upside - it might be able to guess about movements of two people. In our case, we'd need to filter out cats who come and go all night (smaller areas?).
Well, it sounds like Alowhum is getting good results with PIR sensors. Right now it's the summer though. I just wonder whether they will work as well in the winter if a lot of blankets get piled on?
alowhum last edited by alowhum
@zeph: that RCWL-0506 exactly the sensor I used, as mentioned in my posts. And yes, I know this isn't really officially radar, but they are colloquially called that amongst makers.
I also mentioned that, indeed, oxygen level and heart pulse are indicators the professionals use. I have those in my arsenal, as well as gyro sensors. However, in my case on of the parameters for the alarm clock is that it doesn't require the user to wear anything.
Why not? Well, because I am working on devices that should offer high levels of privacy protection I could not support any current commercial devices. They all use bluetooth, which sends out signals all day, making the user trackable through space. (and yes, bluetooth 5 supports mac address randomization, but it is rarely implemented. For example, the Samsung Galaxy phones do not support it, while iPhones predictably do.)
On the humorous side of things, you can apparently somehow (?) make an erection detector as a way of detecting REM sleep. There was actually a kickstarter to do exactly that. Funding was unsuccessful: https://www.kickstarter.com/projects/nptdreamer/npt-lucid-dreamer?ref=nav_search
but the science is sound: https://en.wikipedia.org/wiki/Nocturnal_penile_tumescence
Obviously, they should have made it work using bluetooth instead of using wires. Looks as though it was a simple closed circuit held together with magnets that would open during REM. Not clear whether it worked only once or whether the circuit would close again between REMs. Probably a simple strain gauge would work just as well.
nagelc last edited by
: ) Masters & Johnson had some creative sensor designs, but I hadn't really considered the possibility of MySensors applications.
Getting closer.. I received a much better 'radar' sensor (the directional one). The only downside is that it has a bright green LED that turns on whenever it detects motion.