Advertisement
pleasedontcode

Stress Detection rev_25

Dec 19th, 2023
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: Stress Detection
  13.     - Source Code compiled for: Arduino Nano
  14.     - Source Code created on: 2023-12-20 01:56:21
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* if distance is lower than 50cm, so measure heart */
  21.     /* rate and if this is above 100bpm, so print on */
  22.     /* serial monitor "HUMAN STRESSED". */
  23. /****** END SYSTEM REQUIREMENTS *****/
  24.  
  25. /****** DEFINITION OF LIBRARIES *****/
  26. #include <Arduino.h>
  27. #include <Wire.h>
  28. #include <Ultrasonic.h>
  29. #include <MAX30100_PulseOximeter.h>
  30.  
  31. /****** FUNCTION PROTOTYPES *****/
  32. void setup(void);
  33. void loop(void);
  34.  
  35. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  36. const uint8_t frontSensor_HC_SR04_Echo_PIN_D3 = 3;
  37. const uint8_t sensor_MAX30100_INT_PIN_D4 = 4;
  38.  
  39. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  40. const uint8_t frontSensor_HC_SR04_Trigger_PIN_D2 = 2;
  41.  
  42. /***** DEFINITION OF I2C PINS *****/
  43. const uint8_t sensor_MAX30100_I2C_PIN_SDA_A4 = A4;
  44. const uint8_t sensor_MAX30100_I2C_PIN_SCL_A5 = A5;
  45.  
  46. /****** DEFINITION OF LIBRARY CLASS INSTANCES*****/
  47. Ultrasonic frontSensor(frontSensor_HC_SR04_Trigger_PIN_D2, frontSensor_HC_SR04_Echo_PIN_D3);
  48. PulseOximeter pulseOximeter;
  49.  
  50. void setup(void)
  51. {
  52.   // put your setup code here, to run once:
  53.  
  54.   pinMode(frontSensor_HC_SR04_Echo_PIN_D3, INPUT);
  55.   pinMode(sensor_MAX30100_INT_PIN_D4, INPUT_PULLUP);
  56.  
  57.   pinMode(frontSensor_HC_SR04_Trigger_PIN_D2, OUTPUT);
  58.  
  59.   // Initialize the MAX30100 Pulse Oximeter
  60.   if (!pulseOximeter.begin()) {
  61.     Serial.println("Failed to initialize MAX30100!");
  62.     while (1);
  63.   }
  64.   else {
  65.     Serial.println("MAX30100 initialized successfully!");
  66.   }
  67. }
  68.  
  69. void loop(void)
  70. {
  71.   // put your main code here, to run repeatedly:
  72.  
  73.   // Measure the distance using the ultrasonic sensor
  74.   unsigned int distance = frontSensor.read();
  75.  
  76.   // Check if the distance is lower than 50cm
  77.   if (distance < 50) {
  78.     // Measure the heart rate using the MAX30100 Pulse Oximeter
  79.     pulseOximeter.update();
  80.     float heartRate = pulseOximeter.getHeartRate();
  81.  
  82.     // Check if the heart rate is above 100 bpm
  83.     if (heartRate > 100) {
  84.       Serial.println("HUMAN STRESSED");
  85.     }
  86.   }
  87.  
  88.   // Delay for a short period before repeating the loop
  89.   delay(1000);
  90. }
  91.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement