This is an old revision of the document!


Sleep Environment Monitor

Introduction

Context

Everyone knows how important it is to sleep well, both for staying energized and productive and, more importantly, for maintaining good long-term health. Some individuals naturally sleep better than others. Nowadays, we understand that certain behaviors on our part can help, such as adhering to schedules (getting 8 hours of sleep and going to bed before 11 PM for instance), regularly engaging in physical activity, or avoiding screens two hours before bedtime. Through traveling and trying out different rooms, I've noticed that depending on the location, sleep quality can be affected. While we know that the quality of the mattress or pillow can have an impact, it's more challenging to measure the external environment's influence on sleep quality and whether it contributes to restful nights.

Therefore, for this class project, I've chosen to create a system that will help monitor and identify if certain external factors might be causing poor sleep. This could provide insights into what needs improvement (better ventilation, adjusting the temperature, etc.).

Project Description

The idea behind this project is to gather measurements of various physical metrics that can impact sleep. Five metrics have been selected: the amount of light, sound levels, temperature, humidity, and the CO2 concentration (or rather, the CO2 equivalent) in the room. These physical aspects are known to affect sleep, and we are familiar with the scales used to determine if sleep quality is affected.

The values will be collected through sensors managed by an ESP32 and stored in a Firebase database. The user can initiate the recording from a web interface at bedtime and can visualize the progression of measurements throughout the night on the same interface. This will also allow the evaluation of whether certain periods during the night are better than others. An overall score for the surrounding environment's quality, derived from the five metrics, will be displayed by the web interface.

Architecture

System overview

To use the system, a user utilizes a web interface. Authentication is necessary to protect the data. Multiple users can be connected and use the system simultaneously. On the web interface, the user can either view data from previous recordings or start a new recording. The hardware must be powered on, connected to the internet, and possess the correct identification values to access the remote database. The user needs to place it in the room where they want to take measurements, then they can start and stop the recording from the web interface. The web application and the ESP32 do not communicate directly but access data stored in the cloud within a Firebase database. The database contains the measurements as well as the system state, indicating whether a recording is ongoing or not, allowing for the preservation of the state even after disconnecting from the web application. When a recording is in progress, the data updates in real-time on the web application.

The diagram below provides an overview of the global system logic:

Hardware

Components

  • BOARD:
    • LOLIN32 v1.0.0 - based on the ESP-WROOM-32 module that integrates WIFI and bluetooth
  • SENSORS:
    • BH1750: a digital ambient light sensor for I2C bus interface
    • CCS811: an ultra-low power digital gas sensor solution which integrates a metal oxide (MOX) gas sensor to detect a wide range of Volatile Organic Compounds (VOCs) for indoor air quality monitoring (I2C interface)
    • HDC2010: a low power and high accuracy integrated humidity and temperature sensor (I2C interface)
    • Dablle soundmeter: Dabble is a Smartphone app that offers modules to control hardware via Bluetooth and especially to access Smartphone sensors. Used in this project to connect to a smartphone's microphone and get a soundmeter.

Circuit Diagram

Real-life view

TODO : insert a photo here

Software

Used methods for quality rating

For each measurement, the system assigns an overall score calculated from five criteria. The overall score for the recording is the average of these overall scores. As this score is derived from 5 criteria, each criterion constitutes 1/5 or 20% of the score. The calculation is not based on a continuous function but rather on intervals. Each measurement is divided into 5 intervals, and depending on which interval the measured value falls into, it contributes 0, 5, 10, 15, or 20% to the score. In fact, a sixth interval is added which represents the threshold limit. If the value is exceptionally poor and exceeds this interval, it is considered to significantly degrade sleep quality and even outweigh the other criteria. Consequently, the score is lowered by 10%.

These intervals were estimated based on recommendations found in literature (for example, ideal temperature or brightness in a bedroom) and by comparing values to references (what does 40 dB correspond to, for instance). For further information about information sources, please refer to the references section.

To summarize, here are the value intervals and the points they contribute for each measured parameter:

Code & Structure

The application logic is divided into three parts:

  • Administration of the Firebase database
  • The hardware code based on Arduino
  • The web application code made in HTML, JS, and CSS
Firebase
  • Data structure

The data is organized by users. For greater stability, the system state, i.e., whether a recording is in progress or not, is directly saved in the database. This allows for the disconnection of the web interface or even the ESP32 without crashing the system. Recordings are organized by an ID, and each recording contains multiple measurements taken at regular intervals. Each measurement includes the five metrics collected by the system, along with a timestamp and the overall score evaluated for that specific measurement. The following schema outlines the database structure:

  • Rules and access rights

As seen above, the data is segregated by user. Authentication occurs through email and password, and each user is assigned a unique identifier. Each user can access only their respective data. To achieve this, access rules need to be defined as follows:

{
  "rules": {
    "UsersData": {
      "$user_id": {
        ".read": "auth !== null && auth.uid === $user_id",
        ".write": "auth !== null && auth.uid === $user_id",
      }
    }
  }
}
Arduino

TODO: describe the main concepts of the arduino part

Web app

TODO : same for the web app

Results

TODO: show a result example and explain how to interpret it

Conclusion

TODO: conclude

References

TODO: insert references

iothings/proiecte/2023/sleepenvironmentmonitor.1703702950.txt.gz · Last modified: 2023/12/27 20:49 by taddeo.dadamo
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0