Advertisement
pleasedontcode

"Sensing Stress" rev_29

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