Advertisement
pleasedontcode

"Stress Detection" rev_27

Jan 18th, 2024
93
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 Uno
  14.     - Source Code created on: 2024-01-18 22:35:39
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* if distance is less than 20cm so read heart rate. */
  21.     /* If heart rate is above 100bpm so print on serial */
  22.     /* "HUMAN STRESSED". */
  23. /****** END SYSTEM REQUIREMENTS *****/
  24.  
  25. /****** DEFINITION OF LIBRARIES *****/
  26. #include <Wire.h>
  27. #include <Ultrasonic.h>
  28.  
  29. /****** FUNCTION PROTOTYPES *****/
  30. void setup();
  31. void loop();
  32. void updateOutputs();
  33.  
  34. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  35. const uint8_t frontSensor_HC_SR04_Echo_PIN_D4 = 4;
  36. const uint8_t sensor_MAX30100_INT_PIN_D5 = 5;
  37.  
  38. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  39. const uint8_t alarm_ActiveBuzzer_output_PIN_D2 = 2;
  40. const uint8_t frontSensor_HC_SR04_Trigger_PIN_D3 = 3;
  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. const uint8_t sensor_MAX30100_I2C_SLAVE_ADDRESS = 87;
  46.  
  47. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  48. /***** used to store raw data *****/
  49. bool alarm_ActiveBuzzer_output_PIN_D2_rawData = 0;
  50. bool frontSensor_HC_SR04_Trigger_PIN_D3_rawData = 0;
  51.  
  52. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  53. /***** used to store data after characteristic curve transformation *****/
  54. float alarm_ActiveBuzzer_output_PIN_D2_phyData = 0.0;
  55. float frontSensor_HC_SR04_Trigger_PIN_D3_phyData = 0.0;
  56.  
  57. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  58. Ultrasonic ultrasonic(frontSensor_HC_SR04_Trigger_PIN_D3, frontSensor_HC_SR04_Echo_PIN_D4);
  59.  
  60. void setup()
  61. {
  62.     // put your setup code here, to run once:
  63.  
  64.     pinMode(frontSensor_HC_SR04_Echo_PIN_D4, INPUT);
  65.     pinMode(sensor_MAX30100_INT_PIN_D5, INPUT_PULLUP);
  66.  
  67.     pinMode(alarm_ActiveBuzzer_output_PIN_D2, OUTPUT);
  68.     pinMode(frontSensor_HC_SR04_Trigger_PIN_D3, OUTPUT);
  69. }
  70.  
  71. void loop()
  72. {
  73.     // put your main code here, to run repeatedly:
  74.     updateOutputs(); // Refresh output data
  75.  
  76.     // Reading ultrasonic sensor distance
  77.     int distance = ultrasonic.read();
  78.  
  79.     // Check if distance is less than 20cm
  80.     if (distance < 20)
  81.     {
  82.         // Read heart rate (assuming it's stored in a variable named 'heartRate')
  83.         int heartRate = readHeartRate(); // Replace with the actual code to read heart rate
  84.  
  85.         // Check if heart rate is above 100 bpm
  86.         if (heartRate > 100)
  87.         {
  88.             Serial.println("HUMAN STRESSED");
  89.         }
  90.     }
  91. }
  92.  
  93. void updateOutputs()
  94. {
  95.     digitalWrite(alarm_ActiveBuzzer_output_PIN_D2, alarm_ActiveBuzzer_output_PIN_D2_rawData);
  96.     digitalWrite(frontSensor_HC_SR04_Trigger_PIN_D3, frontSensor_HC_SR04_Trigger_PIN_D3_rawData);
  97. }
  98.  
  99. int readHeartRate()
  100. {
  101.     // Replace with the actual code to read the heart rate
  102.     // Example: int heartRate = analogRead(A0);
  103.     int heartRate = analogRead(A0); // Replace with the actual code to read heart rate
  104.     return heartRate;
  105. }
  106.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement