Advertisement
pleasedontcode

"Sensor Setup" rev_25

Jan 18th, 2024
97
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: "Sensor Setup"
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2024-01-18 22:27:59
  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.   pinMode(frontSensor_HC_SR04_Echo_PIN_D4, INPUT);
  65.   pinMode(sensor_MAX30100_INT_PIN_D5, INPUT_PULLUP);
  66.   pinMode(alarm_ActiveBuzzer_output_PIN_D2, OUTPUT);
  67.   pinMode(frontSensor_HC_SR04_Trigger_PIN_D3, OUTPUT);
  68.  
  69.   Serial.begin(9600);
  70. }
  71.  
  72. void loop(void)
  73. {
  74.   // put your main code here, to run repeatedly:
  75.   updateOutputs(); // Refresh output data
  76.  
  77.   // Read distance from ultrasonic sensor in centimeters
  78.   unsigned int distance = ultrasonic.read();
  79.  
  80.   // Check if the distance is less than 20cm
  81.   if (distance < 20)
  82.   {
  83.     // Read heart rate from sensor
  84.     int heartRate = readHeartRate();
  85.    
  86.     // Check if heart rate is above 100bpm
  87.     if (heartRate > 100)
  88.     {
  89.       Serial.println("HUMAN STRESSED");
  90.     }
  91.   }
  92. }
  93.  
  94. void updateOutputs()
  95. {
  96.   digitalWrite(alarm_ActiveBuzzer_output_PIN_D2, alarm_ActiveBuzzer_output_PIN_D2_rawData);
  97.   digitalWrite(frontSensor_HC_SR04_Trigger_PIN_D3, frontSensor_HC_SR04_Trigger_PIN_D3_rawData);
  98. }
  99.  
  100. int readHeartRate()
  101. {
  102.   // Add your code to read heart rate from sensor
  103.   // Return the heart rate value
  104.   // This is just a placeholder
  105.   return 0;
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement