Advertisement
pleasedontcode

Sensor Monitoring rev_24

Dec 28th, 2023
98
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 Monitoring
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2023-12-29 00:14:36
  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.
  29. ********* User code review feedback **********/
  30.  
  31. /****** DEFINITION OF LIBRARIES *****/
  32. #include <Arduino.h>
  33. #include <Wire.h>
  34. #include <Ultrasonic.h>
  35.  
  36. /****** FUNCTION PROTOTYPES *****/
  37. void setup(void);
  38. void loop(void);
  39. int readHeartRate();
  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 = 0x57;
  53.  
  54. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  55. Ultrasonic ultrasonic(frontSensor_HC_SR04_Trigger_PIN_D3, frontSensor_HC_SR04_Echo_PIN_D4);
  56.  
  57. void setup(void)
  58. {
  59.   pinMode(frontSensor_HC_SR04_Echo_PIN_D4, INPUT);
  60.   pinMode(sensor_MAX30100_INT_PIN_D5, INPUT_PULLUP);
  61.  
  62.   pinMode(alarm_ActiveBuzzer_output_PIN_D2, OUTPUT);
  63.   pinMode(frontSensor_HC_SR04_Trigger_PIN_D3, OUTPUT);
  64.  
  65.   Serial.begin(9600);
  66. }
  67.  
  68. void loop(void)
  69. {
  70.   // Read distance using ultrasonic sensor
  71.   int distance = ultrasonic.read();
  72.  
  73.   Serial.print("Distance in CM: ");
  74.   Serial.println(distance);
  75.  
  76.   // Check if the distance is less than 20cm
  77.   if (distance < 20)
  78.   {
  79.     // Read heart rate using MAX30100 sensor
  80.     int heartRate = readHeartRate();
  81.     Serial.print("Heart Rate: ");
  82.     Serial.println(heartRate);
  83.  
  84.     // Check if heart rate is above 100 bpm
  85.     if (heartRate > 100)
  86.     {
  87.       Serial.println("HUMAN STRESSED");
  88.     }
  89.   }
  90.  
  91.   delay(1000);
  92. }
  93.  
  94. int readHeartRate()
  95. {
  96.   // TODO: Implement code to read heart rate using the MAX30100 sensor
  97.   // Return the heart rate value
  98.   return 0;
  99. }
  100.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement