Ryan Maddocks- Stress reduction- Final Submission

For this project I used the LCD display, a heart rate monitor and a button and decided to create something to help with stress/ to help lower your heart rate. This is because in my research I found that in 2013 there about 8.2 million cases of anxiety in England showing that it can affect a lot of people.

The Concept is for a device which can check your heart rate to be able to see when you are starting to get stressed and then you would get a warning that you need to breathe/ calm down, then when the button is pressed it will take you through a simple breathing exercise ( Inhale 5secs, Exhale 5secs). This was a standard exercise which I found in my research.

https://www.nhs.uk/mental-health/self-help/guides-tools-and-activities/breathing-exercises-for-stress/

Overall I am happy with the final result as I was able to create a final working model with a housing for the main components, which helped to make it easier to use and made it look final model look a lot cleaner. One thing I would like to change would be too add a bit more complexity to the idea as it is a fairly simple concept, one idea I had would be to add an extra component such as a thermistor that can also monitor your temperature as another way to monitor your stress levels. It would have also been nice to find a way to clean up the wires on the Arduino board, because the housing only covers the main components, however I didn’t want the housing to be too big which it likely would have been if I tried to create a housing that could hold everything.

Working Video

In the video I repeatedly tapped on the heart beat sensor in the video in order to trick the sensor into reading a higher heart rate so that I could demonstrate what happens when 120 BPM is reached and to show the message to say that you are getting too stressed, just by putting your finger on the sensor it should keep checking the heart rate and updating it on the LCD display, but tapping quickly allowed me to show the other features.

Model Images

These are some images of the model I created which also includes an image of the inside of the housing to show how the components fit into it. There are also images showing the different messages that display on the LCD display including the stress prompt, BPM and images of the breathing exercise.

Flowchart

Circuit Diagram

The Fritzing software did not have a heart rate sensor in it so I had to substitute the sensor and then label the sections so that the image would represent what the circuit would actually look like and how the pins would connect to the Arduino board. The software also did not contain the LCD display with the I2C module so I also used a substitute component which had the same pins and could be used to show how the LCD display connects to the Arduino.

Code

Arduino Create Link: https://create.arduino.cc/editor/ryanmaddocks/34b9c261-acec-43eb-a369-36e64284d327/preview

/*Referecnes
   https://pulsesensor.com/pages/getting-advanced
   https://arduino.stackexchange.com/questions/29040/how-do-i-repeat-a-piece-of-code
   https://arduinogetstarted.com/tutorials/arduino-button
*/
#define USE_ARDUINO_INTERRUPTS true    // Set-up low-level interrupts for most acurate BPM math.
#include <PulseSensorPlayground.h>     // Includes the PulseSensorPlayground Library.   
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
//  Variables
const int PulseWire = 0;       // PulseSensor PURPLE WIRE connected to ANALOG PIN 0
int Threshold = 550;           // Determine which Signal to "count as a beat" and which to ignore.
int buttonPin = 8;
int lastState = HIGH;
int currentState;

PulseSensorPlayground pulseSensor;  // Creates an instance of the PulseSensorPlayground object called "pulseSensor"
byte timer[] = { B11111, B11111, B11111, B11111, B11111, B11111, B11111, B11111};
LiquidCrystal_I2C lcd(0x27, 16, 2);

void setup() {
  Serial.begin(9600);          // For Serial Monitor

  // Configure the PulseSensor object, by assigning our variables to it.
  pulseSensor.analogInput(PulseWire);
  pulseSensor.setThreshold(Threshold);

  pulseSensor.begin();
  lcd.begin();
  lcd.backlight();
  lcd.createChar(0, timer);
  lcd.home();
  pinMode(buttonPin, INPUT_PULLUP);
}

void loop() {

  int myBPM = pulseSensor.getBeatsPerMinute();  // Calls function on our pulseSensor object that returns BPM as an "int".
  // "myBPM" hold this BPM value now.

  if (pulseSensor.sawStartOfBeat()) {            // Constantly test to see if "a beat happened".
    lcd.setCursor(8, 0);
    lcd.print("BPM:");                        // Print phrase "BPM:"
    lcd.setCursor(12, 0);
    lcd.println(myBPM);                        // Print the value inside of myBPM.
  }
  //Beathing excersice if heart rate is too high.
  if (myBPM >= 120) {

    lcd.setCursor(0, 0);
    lcd.print("Breathe");
    lcd.setCursor(0, 1);
    lcd.print("Push To Start");

  } else {
    lcd.setCursor(0, 0);
    lcd.print("       ");    //Clears Breathe from the display
    lcd.setCursor(0, 1);
    lcd.print("             ");    //Clears Push To Start from the display
  }
  // read the state of the pushbutton value:
  currentState = digitalRead(buttonPin);
  if (lastState == LOW && currentState == HIGH) {
    //Countdown before exercise
    lcd.clear();
    for (int countdown = 3; countdown > 0; countdown--)
    {
      lcd.setCursor(0, 1);
      lcd.println(countdown);
      delay(1000);
      lcd.setCursor(0, 1);
      lcd.print("   ");
    }
    //for loop repeats exercise 3 times
    for (int i = 0; i < 3; i++) {
      //Inhale
      lcd.setCursor(1, 0);
      lcd.print("Inhale");
      delay (1000);
      //for loop used to set cursor location
      for (int location = 0; location < 16; location++)
      {
        lcd.setCursor(location, 1);
        lcd.write ((byte)0);
        delay(312.4);
      }
      delay (1000);
      lcd.setCursor(1, 0);
      lcd.print("Exhale");
      //for loop used to set cursor location
      for (int location = 16; location >= 0; location--)
      {
        lcd.setCursor(location, 1);
        lcd.print (" ");
        delay(312.4);
      }
      //clears text "exhale"
      lcd.setCursor(1, 0);
      lcd.print ("      ");
      delay(1000);
    }
  }
  // save the the last state
  lastState = currentState;
}