Hi!
I have a program with 2 sections in the loop, one for a heartrate monitor, and one for a temperature sensor. The temperature section reads 0 when interrupts are on, but the Heartrate section needs interrupts to work. I'm trying to find a way to toggle interrupts on and off within the loop, but noInterrupts() and interrupts() don't seem to be working properly. Is there anything I can do?
I'm using a Pulse Sensor Heartrate Monitor, and a DHT11 temperature sensor if that helps.
Code:
#include <dht.h>
#define USE_ARDUINO_INTERRUPTS true // Set-up low-level interrupts for most acurate BPM math.
#include <PulseSensorPlayground.h> // Includes the PulseSensorPlayground Library.
dht DHT;
#define DHT11_PIN A1
// Variables
const int PulseWire = 0; // PulseSensor PURPLE WIRE connected to ANALOG PIN 0
const int LED = 13; // The on-board Arduino LED, close to PIN 13.
int Threshold = 200; // Determine which Signal to "count as a beat" and which to ignore.
// Use the "Gettting Started Project" to fine-tune Threshold Value beyond default setting.
// Otherwise leave the default "550" value.
PulseSensorPlayground pulseSensor; // Creates an instance of the PulseSensorPlayground object called "pulseSensor"
void setup() {
Serial.begin(9600); // For Serial Monitor
// Configure the PulseSensor object, by assigning our variables to it.
pulseSensor.analogInput(PulseWire);
pulseSensor.blinkOnPulse(LED); //auto-magically blink Arduino's LED with heartbeat.
pulseSensor.setThreshold(Threshold);
// Double-check the "pulseSensor" object was created and "began" seeing a signal.
if (pulseSensor.begin()) {
Serial.println("We created a pulseSensor Object !"); //This prints one time at Arduino power-up, or on Arduino reset.
}
}
unsigned long lastTemp = 0;
int intervalTemp = 1000;
void loop() {
//temp sensor
if (millis() - lastTemp >= intervalTemp) {
lastTemp = millis();
int chk = DHT.read11(DHT11_PIN);
Serial.print("Temperature = ");
Serial.println(DHT.temperature);
Serial.print("Humidity % = ");
Serial.println(DHT.humidity);
}
//heartbeat monitor
if (pulseSensor.sawStartOfBeat()) { // Constantly test to see if "a beat happened".
int myBPM = pulseSensor.getBeatsPerMinute(); // Calls function on our pulseSensor object that returns BPM as an "int".
// "myBPM" hold this BPM value now.
Serial.println("Heartbeat detected:"); // If test is "true", print a message "a heartbeat happened".
Serial.print("BPM: "); // Print phrase "BPM: "
Serial.println(myBPM); // Print the value inside of myBPM.
}
}
Any help would be appreciated. Thanks!