Advertisement
pleasedontcode

Arduino Alarming rev_26

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: Arduino Alarming
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2024-01-18 22:30:40
  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. - generate another code solution
  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. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  42. const uint8_t frontSensor_HC_SR04_Echo_PIN_D4 = 4;
  43. const uint8_t sensor_MAX30100_INT_PIN_D5 = 5;
  44.  
  45. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  46. const uint8_t alarm_ActiveBuzzer_output_PIN_D2 = 2;
  47. const uint8_t frontSensor_HC_SR04_Trigger_PIN_D3 = 3;
  48.  
  49. /***** DEFINITION OF I2C PINS *****/
  50. const uint8_t sensor_MAX30100_I2C_PIN_SDA_A4 = A4;
  51. const uint8_t sensor_MAX30100_I2C_PIN_SCL_A5 = A5;
  52. const uint8_t sensor_MAX30100_I2C_SLAVE_ADDRESS = 87;
  53.  
  54. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  55. /***** used to store raw data *****/
  56. bool alarm_ActiveBuzzer_output_PIN_D2_rawData = 0;
  57. bool frontSensor_HC_SR04_Trigger_PIN_D3_rawData = 0;
  58.  
  59. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  60. /***** used to store data after characteristic curve transformation *****/
  61. float alarm_ActiveBuzzer_output_PIN_D2_phyData = 0.0;
  62. float frontSensor_HC_SR04_Trigger_PIN_D3_phyData = 0.0;
  63.  
  64. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  65. Ultrasonic ultrasonic(frontSensor_HC_SR04_Trigger_PIN_D3, frontSensor_HC_SR04_Echo_PIN_D4);
  66.  
  67. void setup(void)
  68. {
  69.   // put your setup code here, to run once:
  70.   pinMode(frontSensor_HC_SR04_Echo_PIN_D4, INPUT);
  71.   pinMode(sensor_MAX30100_INT_PIN_D5, INPUT_PULLUP);
  72.   pinMode(alarm_ActiveBuzzer_output_PIN_D2, OUTPUT);
  73.   pinMode(frontSensor_HC_SR04_Trigger_PIN_D3, OUTPUT);
  74.  
  75.   Serial.begin(9600);
  76. }
  77.  
  78. void loop(void)
  79. {
  80.   // put your main code here, to run repeatedly:
  81.   updateOutputs(); // Refresh output data
  82.  
  83.   // Read distance from ultrasonic sensor in centimeters
  84.   unsigned int distance = ultrasonic.read();
  85.  
  86.   // Check if the distance is less than 20cm
  87.   if (distance < 20)
  88.   {
  89.     // Read heart rate from sensor
  90.     int heartRate = readHeartRate();
  91.    
  92.     // Check if heart rate is above 100bpm
  93.     if (heartRate > 100)
  94.     {
  95.       Serial.println("HUMAN STRESSED");
  96.     }
  97.   }
  98. }
  99.  
  100. void updateOutputs()
  101. {
  102.   digitalWrite(alarm_ActiveBuzzer_output_PIN_D2, alarm_ActiveBuzzer_output_PIN_D2_rawData);
  103.   digitalWrite(frontSensor_HC_SR04_Trigger_PIN_D3, frontSensor_HC_SR04_Trigger_PIN_D3_rawData);
  104. }
  105.  
  106. int readHeartRate()
  107. {
  108.   // Add your code to read heart rate from sensor
  109.   // Return the heart rate value
  110.   // This is just a placeholder
  111.   return 0;
  112. }
  113.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement