Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* Pleasedontcode.com **********
- Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- - Terms and Conditions:
- You have a non-exclusive, revocable, worldwide, royalty-free license
- for personal and commercial use. Attribution is optional; modifications
- are allowed, but you're responsible for code maintenance. We're not
- liable for any loss or damage. For full terms,
- please visit pleasedontcode.com/termsandconditions.
- - Project: Stress Detection
- - Source Code compiled for: Arduino Nano
- - Source Code created on: 2023-12-20 01:56:21
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* if distance is lower than 50cm, so measure heart */
- /* rate and if this is above 100bpm, so print on */
- /* serial monitor "HUMAN STRESSED". */
- /****** END SYSTEM REQUIREMENTS *****/
- /****** DEFINITION OF LIBRARIES *****/
- #include <Arduino.h>
- #include <Wire.h>
- #include <Ultrasonic.h>
- #include <MAX30100_PulseOximeter.h>
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- /***** DEFINITION OF DIGITAL INPUT PINS *****/
- const uint8_t frontSensor_HC_SR04_Echo_PIN_D3 = 3;
- const uint8_t sensor_MAX30100_INT_PIN_D4 = 4;
- /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
- const uint8_t frontSensor_HC_SR04_Trigger_PIN_D2 = 2;
- /***** DEFINITION OF I2C PINS *****/
- const uint8_t sensor_MAX30100_I2C_PIN_SDA_A4 = A4;
- const uint8_t sensor_MAX30100_I2C_PIN_SCL_A5 = A5;
- /****** DEFINITION OF LIBRARY CLASS INSTANCES*****/
- Ultrasonic frontSensor(frontSensor_HC_SR04_Trigger_PIN_D2, frontSensor_HC_SR04_Echo_PIN_D3);
- PulseOximeter pulseOximeter;
- void setup(void)
- {
- // put your setup code here, to run once:
- pinMode(frontSensor_HC_SR04_Echo_PIN_D3, INPUT);
- pinMode(sensor_MAX30100_INT_PIN_D4, INPUT_PULLUP);
- pinMode(frontSensor_HC_SR04_Trigger_PIN_D2, OUTPUT);
- // Initialize the MAX30100 Pulse Oximeter
- if (!pulseOximeter.begin()) {
- Serial.println("Failed to initialize MAX30100!");
- while (1);
- }
- else {
- Serial.println("MAX30100 initialized successfully!");
- }
- }
- void loop(void)
- {
- // put your main code here, to run repeatedly:
- // Measure the distance using the ultrasonic sensor
- unsigned int distance = frontSensor.read();
- // Check if the distance is lower than 50cm
- if (distance < 50) {
- // Measure the heart rate using the MAX30100 Pulse Oximeter
- pulseOximeter.update();
- float heartRate = pulseOximeter.getHeartRate();
- // Check if the heart rate is above 100 bpm
- if (heartRate > 100) {
- Serial.println("HUMAN STRESSED");
- }
- }
- // Delay for a short period before repeating the loop
- delay(1000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement