This is an old revision of the document!
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.).
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.
TODO : change the links
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:
TODO : insert a photo here
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:
The application logic is divided into three parts:
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:
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", } } } }
TODO: describe the main concepts of the arduino part
TODO : same for the web app
TODO: show a result example and explain how to interpret it
TODO: conclude
Hardware
CC811 + HDC2010 I2C sensor breakout
ESP32 WeMos LOLIN32 schematic v1.0.0
ESP32 WeMos LOLIN32 high resolution pinout and specs
External Libraries
Litterature