Advertisement
pleasedontcode

"Stress Detector" rev_30

Jan 18th, 2024
96
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 Detector"
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2024-01-18 23:30:08
  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.  
  26. /********* User code review feedback **********
  27. #### Feedback 1 ####
  28. - print hello in loop
  29. ********* User code review feedback **********/
  30.  
  31. /****** DEFINITION OF LIBRARIES *****/
  32. #include <Wire.h>
  33. #include <Ultrasonic.h>
  34.  
  35. /****** FUNCTION PROTOTYPES *****/
  36. void setup(void);
  37. void loop(void);
  38. void updateOutputs(void);
  39. int readHeartRate(void);
  40.  
  41. /****** SYSTEM REQUIREMENTS *****/
  42. /****** SYSTEM REQUIREMENT 1 *****/
  43. /* if distance is less than 20cm so read heart rate. */
  44. /* If heart rate is above 100bpm so print on serial */
  45. /* "HUMAN STRESSED". */
  46. /****** END SYSTEM REQUIREMENTS *****/
  47.  
  48. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  49. const uint8_t frontSensor_HC_SR04_Echo_PIN_D4 = 4;
  50. const uint8_t sensor_MAX30100_INT_PIN_D5 = 5;
  51.  
  52. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  53. const uint8_t alarm_ActiveBuzzer_output_PIN_D2 = 2;
  54. const uint8_t frontSensor_HC_SR04_Trigger_PIN_D3 = 3;
  55.  
  56. /***** DEFINITION OF I2C PINS *****/
  57. const uint8_t sensor_MAX30100_I2C_PIN_SDA_A4 = A4;
  58. const uint8_t sensor_MAX30100_I2C_PIN_SCL_A5 = A5;
  59. const uint8_t sensor_MAX30100_I2C_SLAVE_ADDRESS = 87;
  60.  
  61. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  62. /***** used to store raw data *****/
  63. bool alarm_ActiveBuzzer_output_PIN_D2_rawData = 0;
  64. bool frontSensor_HC_SR04_Trigger_PIN_D3_rawData = 0;
  65.  
  66. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  67. /***** used to store data after characteristic curve transformation *****/
  68. float alarm_ActiveBuzzer_output_PIN_D2_phyData = 0.0;
  69. float frontSensor_HC_SR04_Trigger_PIN_D3_phyData = 0.0;
  70.  
  71. /****** DEFINITION OF LIBRARIES CLASS INSTANCES *****/
  72. Ultrasonic ultrasonic(frontSensor_HC_SR04_Trigger_PIN_D3, frontSensor_HC_SR04_Echo_PIN_D4);
  73.  
  74. void setup(void)
  75. {
  76.   // put your setup code here, to run once:
  77.  
  78.   pinMode(frontSensor_HC_SR04_Echo_PIN_D4, INPUT);
  79.   pinMode(sensor_MAX30100_INT_PIN_D5, INPUT_PULLUP);
  80.  
  81.   pinMode(alarm_ActiveBuzzer_output_PIN_D2, OUTPUT);
  82.   pinMode(frontSensor_HC_SR04_Trigger_PIN_D3, OUTPUT);
  83.  
  84.   Serial.begin(9600); // Initialize serial communication
  85. }
  86.  
  87. void loop(void)
  88. {
  89.   // put your main code here, to run repeatedly:
  90.  
  91.   updateOutputs(); // Refresh output data
  92.  
  93.   unsigned int distance = ultrasonic.read(); // Read distance from ultrasonic sensor
  94.  
  95.   if (distance < 20) // Check if distance is less than 20cm
  96.   {
  97.     int heartRate = readHeartRate(); // Read heart rate
  98.    
  99.     if (heartRate > 100) // Check if heart rate is above 100bpm
  100.     {
  101.       Serial.println("HUMAN STRESSED");
  102.     }
  103.   }
  104.  
  105.   Serial.println("Hello"); // Print "Hello" on the serial monitor
  106.  
  107.   delay(1000); // Delay for 1 second
  108. }
  109.  
  110. int readHeartRate()
  111. {
  112.   // Implement heart rate reading logic here
  113.   // Replace with appropriate code to read heart rate from MAX30100 sensor
  114.  
  115.   return 0; // Replace with actual heart rate value
  116. }
  117.  
  118. void updateOutputs()
  119. {
  120.   digitalWrite(alarm_ActiveBuzzer_output_PIN_D2, alarm_ActiveBuzzer_output_PIN_D2_rawData);
  121.   digitalWrite(frontSensor_HC_SR04_Trigger_PIN_D3, frontSensor_HC_SR04_Trigger_PIN_D3_rawData);
  122. }
  123.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement