I combined both the heart pulse sensor code and the DHT11 code. I can get a decent reading from the pulse sensor however an error is given from the DHT11 sensor. I am able to get them to function normally when i set them up individually however when i combine the 2 setups, I am unable to get a reading from the DHT11 although i can get one from the pulse sensor.

I am using ArduinoUNO, DHT11 humidity and temp sensor, and the Pulse Sensor.


#include <SimpleDHT.h>
#define USE_ARDUINO_INTERRUPTS true    // Set-up low-level interrupts for most acurate BPM math.
#include <PulseSensorPlayground.h>     // Includes the PulseSensorPlayground Library.   

//  Variables
const int PulseWire = A0;       // PulseSensor PURPLE WIRE connected to ANALOG PIN 0
const int LED13 = 13;          // The on-board Arduino LED, close to PIN 13.
int Threshold = 550;           // Determine which Signal to "count as a beat" and which to ignore.
const int pinDHT11 = 2;
SimpleDHT11 dht11(pinDHT11);                               // 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(115200);          // For Serial Monitor
  // Configure the PulseSensor object, by assigning our variables to it. 

  pulseSensor.blinkOnPulse(LED13);       //auto-magically blink Arduino's LED with heartbeat.

  // 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.  

void loop() {

 int myBPM = pulseSensor.getBeatsPerMinute();  // Calls function on our pulseSensor object that returns BPM as an "int".
                                               // "myBPM" hold this BPM value now. 

if (pulseSensor.sawStartOfBeat()) {            // Constantly test to see if "a beat happened". 
 Serial.println("♥  A HeartBeat Happened ! "); // 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. 

  delay(20);                    // considered best practice in a simple sketch.
 Serial.println("Sample DHT11...");

  // read without samples.
  byte temperature = 0;
  byte humidity = 0;
  int err = SimpleDHTErrSuccess;
  if ((err = dht11.read(&temperature, &humidity, NULL)) != SimpleDHTErrSuccess) {
  Serial.print("Read DHT11 failed, err="); Serial.println(err);delay(1000);

  Serial.print("Sample OK: ");
  Serial.print((int)temperature); Serial.print(" *C, "); 
  Serial.print((int)humidity); Serial.println(" H");

  // DHT11 sampling rate is 1HZ.
  • The code can be improved, but I don't see an obvious reason why this should not work. It is likely the 2 Arduino libraries are using the same processor resource. You might have to read through the code for the DHT and PulseSensor to determine and fix the problem. Or you may blindly try to simplify your sketch until more features work. For example, it appears unnecessary to enable interrupts as the basic PulseSensorPlayground example does not use interrupts. – st2000 Sep 25 at 14:36
  • 1
    Hint: Try using the PulseSensor library without interrupts. – Mikael Patel Sep 25 at 23:10
  • currently i have edited my code. the DHT11 works now but the pulse sensor still does not work. I have found that the pulse sensor requires interrupts in order for the code to work but DHT11 does not need interrupts in order for it to work. is there some way that i can detach the interrupts for DHT11 code and attach the interrupts for the pulse sensor?? – angelina ambrosia Oct 1 at 16:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.