noInterrupts() does not seem to work as it should

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!

That should not be the case.

1 Like

Check your temperature measurement only, with and without interrupts. If it works even with interrupts enabled then the Pulse Sensor comes with a crappy library.

Do you know if there's anywhere I could find another library?

Maybe try a non- blocking version of the dht library instead: GitHub - olewolf/DHT_nonblocking: Non-blocking Arduino library for the DHT11, DHT21, and DHT22 sensors
Wrapping code in a noInterrupts()/interrupts() block, if that is what you are doing, has to be done with care because it could cause a failure, for example delay() relies on interrupts.

1 Like

Thank you so so so much!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.