Hardware Setup

The system uses three main sensors:

  1. MAX30102 - Optical heart rate and blood oxygen sensor
  2. GSR Sensor - Galvanic Skin Response sensor for stress detection
  3. BH1750 - Ambient light sensor

These sensors work together to collect physiological data that can indicate mental health status.

The sensors are connected as follows:

  • MAX30102 and BH1750 use I2C communication (connected to SDA and SCL pins)
  • GSR sensor is connected to analog pin 34

The code initializes these connections in the setup() function:

Code Implementation

The MAX30102 sensor detects heart rate by measuring changes in blood volume using optical technology (PPG). The code implements:

  1. IR LED shines light into the skin
  2. Photodetector measures reflected light
  3. Pulse detection algorithm identifies beats
  4. Beat-to-beat intervals are calculated for HRV

Based on Shaffer et al. (2014) HRV measurement standards

The moving average calculation separates the GSR signal into two components:

  • Tonic component (slow-changing baseline)
  • Phasic component (fast-changing responses)

This is implemented with a 5-sample moving average window:

Note: The window size of 5 samples was chosen based on Boucsein's (2012) research on electrodermal activity measurement.

HRV is calculated using SDNN (Standard Deviation of NN intervals), which is a well-established metric in psychophysiology research (Castaldo et al., 2019).

The code implements this by:

  1. Storing the last 16 RR intervals (time between heartbeats)
  2. Calculating the mean interval
  3. Computing the standard deviation of these intervals

HRV is an important indicator of autonomic nervous system activity and stress levels.

Mental Health Analysis

The system uses a neural network (defined in MentalHealthNN.h) that takes sensor inputs and outputs probabilities for four mental states:

  1. Normal
  2. Stress
  3. Anxiety
  4. Depression

The prediction happens in the detectMentalHealth() function:

The neural network was likely trained on labeled physiological data from individuals with known mental health conditions.

The BH1750 light sensor measures ambient light levels which are important because:

  • Light exposure affects circadian rhythms and mood (Golden et al., 2005)
  • Low light levels may correlate with depressive symptoms
  • Sudden light changes can indicate environmental stressors

The light data is read and included in the mental health analysis:

Data Upload

The system uploads sensor data to GitHub repositories every 10 seconds using the GitHub API:

  1. Data is formatted as JSON documents
  2. Base64 encoded for GitHub API requirements
  3. Uploaded using HTTP PUT requests with authentication
  4. SHA hashes are tracked for version control

Four separate JSON files are maintained for each sensor type and the mental status.