Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. General Discussion
  3. Has anyone here made a sleep tracker for measuring your quality of sleep at night?

Has anyone here made a sleep tracker for measuring your quality of sleep at night?

Scheduled Pinned Locked Moved General Discussion
21 Posts 9 Posters 3.3k Views 6 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • NeverDieN Offline
    NeverDieN Offline
    NeverDie
    Hero Member
    wrote on last edited by NeverDie
    #1

    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.

    1 Reply Last reply
    0
    • CrankyCoderC Offline
      CrankyCoderC Offline
      CrankyCoder
      wrote on last edited by
      #2

      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.

      https://www.youtube.com/watch?v=SBHyQ1OSM-4

      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!

      Home Automation Tinkerer
      www.CrankyCoder.net

      Controller: HomeAssistant in Kubernetes
      Gateway: MQTTClientGateway
      MySensors: 2.3

      NeverDieN 1 Reply Last reply
      3
      • CrankyCoderC CrankyCoder

        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.

        https://www.youtube.com/watch?v=SBHyQ1OSM-4

        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!

        NeverDieN Offline
        NeverDieN Offline
        NeverDie
        Hero Member
        wrote on last edited by NeverDie
        #3

        @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:

        1. 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.

        2. 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.

        1 Reply Last reply
        1
        • CrankyCoderC Offline
          CrankyCoderC Offline
          CrankyCoder
          wrote on last edited by
          #4

          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.

          Home Automation Tinkerer
          www.CrankyCoder.net

          Controller: HomeAssistant in Kubernetes
          Gateway: MQTTClientGateway
          MySensors: 2.3

          1 Reply Last reply
          0
          • alowhumA Offline
            alowhumA Offline
            alowhum
            Plugin Developer
            wrote on last edited by
            #5

            Did you see this?
            https://forum.mysensors.org/topic/9305/mysensors-smart-watch

            I also remember seeing some Arduino code for a sleep tracker on Github.. although I can't find it now.

            1 Reply Last reply
            1
            • CrankyCoderC Offline
              CrankyCoderC Offline
              CrankyCoder
              wrote on last edited by
              #6

              Woah. very cool. going to look in to those some more.

              Home Automation Tinkerer
              www.CrankyCoder.net

              Controller: HomeAssistant in Kubernetes
              Gateway: MQTTClientGateway
              MySensors: 2.3

              1 Reply Last reply
              0
              • alowhumA Offline
                alowhumA Offline
                alowhum
                Plugin Developer
                wrote on last edited by alowhum
                #7

                I'm also building a sleep tracker alarm clock. This is what I'm working on:

                Software:

                • Use Sadeh algorithm.
                  Example. Simple explanation. Here's some hardcore science.

                Hardware:

                • 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.

                Interface

                • 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.

                Issues

                • 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.

                Interesting sources

                Commercial devices comparison
                http://sleep.cs.brown.edu/comparison/
                https://blog.adafruit.com/2016/05/31/smarter-sleep/
                https://onlinelibrary.wiley.com/doi/full/10.1111/j.1365-2869.2008.00706.x

                Maker creations
                https://code.google.com/archive/p/lolosalarmclock/ (2010, download the zip from Google Code). Youtube Video.
                http://flyingpudding.com/projects/sleep_tracker/
                https://www.instructables.com/id/WeggUp-A-sleeping-cycle-and-light-alarm-clocke/
                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
                track heart-rate
                breathing
                body temperature
                sound
                ambient light
                EEG (brainwaves)
                (source)

                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

                scalzS 1 Reply Last reply
                1
                • alowhumA Offline
                  alowhumA Offline
                  alowhum
                  Plugin Developer
                  wrote on last edited by
                  #8

                  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.

                  1 Reply Last reply
                  1
                  • A Offline
                    A Offline
                    adamf663
                    wrote on last edited by
                    #9

                    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.

                    1 Reply Last reply
                    0
                    • jamzmJ Offline
                      jamzmJ Offline
                      jamzm
                      wrote on last edited by
                      #10

                      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

                      1 Reply Last reply
                      0
                      • Vincent GijsenV Offline
                        Vincent GijsenV Offline
                        Vincent Gijsen
                        wrote on last edited by
                        #11

                        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

                        1 Reply Last reply
                        0
                        • alowhumA alowhum

                          I'm also building a sleep tracker alarm clock. This is what I'm working on:

                          Software:

                          • Use Sadeh algorithm.
                            Example. Simple explanation. Here's some hardcore science.

                          Hardware:

                          • 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.

                          Interface

                          • 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.

                          Issues

                          • 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.

                          Interesting sources

                          Commercial devices comparison
                          http://sleep.cs.brown.edu/comparison/
                          https://blog.adafruit.com/2016/05/31/smarter-sleep/
                          https://onlinelibrary.wiley.com/doi/full/10.1111/j.1365-2869.2008.00706.x

                          Maker creations
                          https://code.google.com/archive/p/lolosalarmclock/ (2010, download the zip from Google Code). Youtube Video.
                          http://flyingpudding.com/projects/sleep_tracker/
                          https://www.instructables.com/id/WeggUp-A-sleeping-cycle-and-light-alarm-clocke/
                          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
                          track heart-rate
                          breathing
                          body temperature
                          sound
                          ambient light
                          EEG (brainwaves)
                          (source)

                          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

                          scalzS Offline
                          scalzS Offline
                          scalz
                          Hardware Contributor
                          wrote on last edited by scalz
                          #12

                          @alowhum said in Has anyone here made a sleep tracker for measuring your quality of sleep at night?:

                          • 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 :)

                          1 Reply Last reply
                          0
                          • alowhumA Offline
                            alowhumA Offline
                            alowhum
                            Plugin Developer
                            wrote on last edited by
                            #13

                            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.
                            NeverDieN 1 Reply Last reply
                            1
                            • alowhumA alowhum

                              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.
                              NeverDieN Offline
                              NeverDieN Offline
                              NeverDie
                              Hero Member
                              wrote on last edited by NeverDie
                              #14

                              @alowhum Interesting information. Do you know whether you actually feel better if you wake up according to that algorithm?

                              1 Reply Last reply
                              0
                              • alowhumA Offline
                                alowhumA Offline
                                alowhum
                                Plugin Developer
                                wrote on last edited by
                                #15

                                Yes, you do. This is the algorithm used in most of the armbands/apps.

                                1 Reply Last reply
                                1
                                • Z Offline
                                  Z Offline
                                  Zeph
                                  Hero Member
                                  wrote on last edited by
                                  #16

                                  Some thoughts.

                                  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?).

                                  1 Reply Last reply
                                  0
                                  • NeverDieN Offline
                                    NeverDieN Offline
                                    NeverDie
                                    Hero Member
                                    wrote on last edited by
                                    #17

                                    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?

                                    1 Reply Last reply
                                    0
                                    • alowhumA Offline
                                      alowhumA Offline
                                      alowhum
                                      Plugin Developer
                                      wrote on last edited by alowhum
                                      #18

                                      @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.)

                                      1 Reply Last reply
                                      0
                                      • NeverDieN Offline
                                        NeverDieN Offline
                                        NeverDie
                                        Hero Member
                                        wrote on last edited by NeverDie
                                        #19

                                        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.

                                        1 Reply Last reply
                                        0
                                        • nagelcN Offline
                                          nagelcN Offline
                                          nagelc
                                          wrote on last edited by
                                          #20

                                          : ) Masters & Johnson had some creative sensor designs, but I hadn't really considered the possibility of MySensors applications.

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          12

                                          Online

                                          11.7k

                                          Users

                                          11.2k

                                          Topics

                                          113.1k

                                          Posts


                                          Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • MySensors
                                          • OpenHardware.io
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular