Advertisement
pleasedontcode

Sensor Monitoring rev_22

Dec 19th, 2023
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 Monitoring
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2023-12-20 01:15:25
  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 <Arduino.h>
  27. #include <Wire.h>
  28. #include <Ultrasonic.h>
  29. #include <MAX30100_PulseOximeter.h>
  30.  
  31. /****** FUNCTION PROTOTYPES *****/
  32. void setup(void);
  33. void loop(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 = 0x57; // Replace with the correct slave address
  47.  
  48. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  49. Ultrasonic ultrasonic(frontSensor_HC_SR04_Trigger_PIN_D3, frontSensor_HC_SR04_Echo_PIN_D4);
  50. PulseOximeter pulseOximeter;
  51.  
  52. void setup(void)
  53. {
  54.   // put your setup code here, to run once:
  55.  
  56.   pinMode(frontSensor_HC_SR04_Echo_PIN_D4, INPUT);
  57.   pinMode(sensor_MAX30100_INT_PIN_D5, INPUT_PULLUP);
  58.  
  59.   pinMode(alarm_ActiveBuzzer_output_PIN_D2, OUTPUT);
  60.   pinMode(frontSensor_HC_SR04_Trigger_PIN_D3, OUTPUT);
  61.  
  62.   // Initialize the MAX30100 sensor
  63.   Wire.begin();
  64.   pulseOximeter.begin();
  65. }
  66.  
  67. void loop(void)
  68. {
  69.   // put your main code here, to run repeatedly:
  70.  
  71.   // Read the distance from the ultrasonic sensor
  72.   unsigned int distance = ultrasonic.read();
  73.  
  74.   // Check if the distance is less than 20cm
  75.   if (distance < 20) {
  76.     // Read the heart rate from the MAX30100 sensor
  77.     pulseOximeter.update();
  78.     float heartRate = pulseOximeter.getHeartRate();
  79.  
  80.     // Check if the heart rate is above 100bpm
  81.     if (heartRate > 100) {
  82.       Serial.println("HUMAN STRESSED");
  83.     }
  84.   }
  85. }
  86.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement