[Noob}Arduino freezes during millis count

Hello good people!

I have a question with my Arduino project. Basically I am using 2 sensors on the Arduino, DHT22, and PulseSensor, with the serial of 115200. So far I have managed to combine the code and it did work briefly. However today I noticed that the Arduino is basically froze every 2 seconds for a second of running the programme. I have included the code below.

I have set the miillis count interval for DHT to 2000 as that is what is required for the sensor to output correct data. So I am guessing the code ran fine during the interval when DHT is not activated, then it stopped for 1 second to read the temperature stuff, and resumed. But I couldn't work out where did I accidentally instructed the code to do so.

THANKS SO MUCH IN ADVANCE! :slight_smile: :slight_smile: :slight_smile: :slight_smile: :slight_smile: :slight_smile: :slight_smile: :slight_smile:

felixmod_uno03.01.2016ADADHTlib.zip (9.71 KB)

The 2 seconds sounds like a hint.

I notice your intervalDHT is 2 seconds. Change it to 4 seconds, and see if it takes 4 seconds to fail, in which case, the problem starts after something triggers in that "if" statement. My guess is that the call to dht.begin() or dht.readHumidity() kills it.

And which DHT library are you using??

It looks like you may be using the Grove library. If you look at the tutorial, dht.begin() is called once in setup(), not in loop() (which would result in multiple calls to begin()). That may be the cause of your problem.

Add some serial prints to narrow down the problem.

For others to read, here is the main sketch:

//--DHT---------
#include "DHT.h" 
#define DHTPIN 4
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
int serialvalue; // value for serial input
int started = 0; // flag for whether we've received serial yet
float prevhumidity;
float prevtemperature;
long previousMillisDHT = 0; //store last time the DHT sensor was updated
long intervalDHT = 2000;
float t;
float h;
//----End of DHT--------


//-----Pulse Sensor----
int pulsePin = 0;                 // Pulse Sensor purple wire connected to analog pin 0
int blinkPin = 12;                // pin to blink led at each beat
int fadePin = 5;                  // pin to do fancy classy fading blink at each beat
int fadeRate = 0;                 // used to fade LED on with PWM on fadePin

// Volatile Variables, used in the interrupt service routine!
volatile int BPM;                   // int that holds raw Analog in 0. updated every 2mS
volatile int Signal;                // holds the incoming raw data
volatile int IBI = 600;             // int that holds the time interval between beats! Must be seeded! 
volatile boolean Pulse = false;     // "True" when User's live heartbeat is detected. "False" when not a "live beat". 
volatile boolean QS = false;        // becomes true when Arduoino finds a beat.

// Regards Serial OutPut  -- Set This Up to your needs
static boolean serialVisual = false;   // Set to 'false' by Default.  Re-set to 'true' to see Arduino Serial Monitor ASCII Visual Pulse
//----End of Pulse Sensor define----

void setup() 
{ 
    Serial.begin(115200);  // open the arduino serial port
    pinMode(13, OUTPUT);
    digitalWrite(13, LOW);
    //-----Pulse Sensor-----
    pinMode(blinkPin,OUTPUT);         // pin that will blink to your heartbeat!
    pinMode(fadePin,OUTPUT);          // pin that will fade  to your heartbeat!
    //Serial.begin(115200);             // we agree to talk fast!
    interruptSetup();                 // sets up to read Pulse Sensor signal every 2mS 
    // IF YOU ARE POWERING The Pulse Sensor AT VOLTAGE LESS THAN THE BOARD VOLTAGE, 
    // UN-COMMENT THE NEXT LINE AND APPLY THAT VOLTAGE TO THE A-REF PIN
    //   analogReference(EXTERNAL);   
    //-----End of Pulse Sensor-----
}

void loop() 
{//---Pulse Sensor-----
    serialOutput() ;       
    
    if (QS == true){     // A Heartbeat Was Found
        // BPM and IBI have been Determined
        // Quantified Self "QS" true when arduino finds a heartbeat
        digitalWrite(blinkPin,HIGH);     // Blink LED, we got a beat. 
        fadeRate = 255;         // Makes the LED Fade Effect Happen
        // Set 'fadeRate' Variable to 255 to fade LED with pulse
        serialOutputWhenBeatHappens();   // A Beat Happened, Output that to serial.     
        QS = false;                      // reset the Quantified Self flag for next time    
    }
    
    ledFadeToBeat();                      // Makes the LED Fade Effect Happen 
    //delay(20);                            //  take a break
    //-----End of Pulse Sensor

    int sensorValue = analogRead(A0);
    int sensorValue1 = analogRead(A1);
    int sensorValue2 = analogRead(A2);
    int sensorValue3 = analogRead(A3);
    int sensorValue4 = analogRead(A4);
    int sensorValue5 = analogRead(A5);
    int sensorValue6 = BPM;

    //DHT.read22(DHT22_PIN);

    unsigned long currentMillis = millis();

    if(currentMillis - previousMillisDHT >= intervalDHT) 
    {
        //save the last time DHT is read
        previousMillisDHT = currentMillis;
        dht.begin();
        //-------filtering the flickering 0 results of the DHT sensor
        if(dht.readHumidity() == 0)
        {
            h = prevhumidity;
        } else {
            h = dht.readHumidity();
            prevhumidity = h;
        }

        if(dht.readTemperature() == 0)
        {
            t = prevtemperature;
            
        } else {
            t = dht.readTemperature();
            prevtemperature = t;
        }
        //-----end of filter
        
    } else {
        t = prevtemperature;
        h = prevhumidity;
    }


    if(Serial.available()) // check to see if there's serial data in the buffer
    {
        serialvalue = Serial.read(); // read a byte of serial data
        started = 1; // set the started flag to on
        if (serialvalue==14)
        {
            digitalWrite(13, HIGH);
        }
        if (serialvalue==13)
        {
            digitalWrite(13, LOW);
        }
    }
    if(started) { // loop once serial data has been received

        Serial.print(sensorValue); // print the first input
        Serial.print(" "); // print a space
        Serial.print(sensorValue1); // print the second input
        Serial.print(" "); // print a space
        Serial.print(sensorValue2); // print the third input
        Serial.print(" "); // print a space
        Serial.print(sensorValue3); // print the fourth input
        Serial.print(" "); // print a space
        Serial.print(sensorValue4); // print the second input
        Serial.print(" "); // print a space
        Serial.print(sensorValue5); // print the second input
        Serial.print(" "); // print a space
        Serial.print(sensorValue6); // print the second input
        Serial.print(" "); // print a space
        Serial.print(h);
        Serial.print(" ");
        Serial.print(t);



        Serial.println(); // print a line-feed



    }
}

void ledFadeToBeat(){
    fadeRate -= 15;                         //  set LED fade value
    fadeRate = constrain(fadeRate,0,255);   //  keep LED fade value from going into negative numbers!
    analogWrite(fadePin,fadeRate);          //  fade LED
}

arduinodlb:
The 2 seconds sounds like a hint.

I notice your intervalDHT is 2 seconds. Change it to 4 seconds, and see if it takes 4 seconds to fail, in which case, the problem starts after something triggers in that "if" statement. My guess is that the call to dht.begin() or dht.readHumidity() kills it.

And which DHT library are you using??

It looks like you may be using the Grove library. If you look at the tutorial, dht.begin() is called once in setup(), not in loop() (which would result in multiple calls to begin()). That may be the cause of your problem.

Add some serial prints to narrow down the problem.

For others to read, here is the main sketch:

Thanks for the quick reply!

I have experimented with what you suggested, turns out the intervalDHT is related, but then I went ahead to remove all the millis counting code to see does it gives out a continuous stream of data, the stream still stops at every 2 seconds...

//--DHT---------
#include "DHT.h" 
#define DHTPIN 4
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
int serialvalue; // value for serial input
int started = 0; // flag for whether we've received serial yet
float prevhumidity;
float prevtemperature;

float t;
float h;
//----End of DHT--------


//-----Pulse Sensor----
int pulsePin = 0;                 // Pulse Sensor purple wire connected to analog pin 0
int blinkPin = 12;                // pin to blink led at each beat
int fadePin = 5;                  // pin to do fancy classy fading blink at each beat
int fadeRate = 0;                 // used to fade LED on with PWM on fadePin

// Volatile Variables, used in the interrupt service routine!
volatile int BPM;                   // int that holds raw Analog in 0. updated every 2mS
volatile int Signal;                // holds the incoming raw data
volatile int IBI = 600;             // int that holds the time interval between beats! Must be seeded! 
volatile boolean Pulse = false;     // "True" when User's live heartbeat is detected. "False" when not a "live beat". 
volatile boolean QS = false;        // becomes true when Arduoino finds a beat.

// Regards Serial OutPut  -- Set This Up to your needs
static boolean serialVisual = false;   // Set to 'false' by Default.  Re-set to 'true' to see Arduino Serial Monitor ASCII Visual Pulse
//----End of Pulse Sensor define----

void setup() 
{ 
Serial.begin(115200);  // open the arduino serial port
pinMode(13, OUTPUT);
digitalWrite(13, LOW);
//-----Pulse Sensor-----
pinMode(blinkPin,OUTPUT);         // pin that will blink to your heartbeat!
  pinMode(fadePin,OUTPUT);          // pin that will fade  to your heartbeat!
  //Serial.begin(115200);             // we agree to talk fast!
  interruptSetup();                 // sets up to read Pulse Sensor signal every 2mS 
   // IF YOU ARE POWERING The Pulse Sensor AT VOLTAGE LESS THAN THE BOARD VOLTAGE, 
   // UN-COMMENT THE NEXT LINE AND APPLY THAT VOLTAGE TO THE A-REF PIN
//   analogReference(EXTERNAL);   
//-----End of Pulse Sensor-----
dht.begin();
}

void loop() 
{//---Pulse Sensor-----
  serialOutput() ;       
    
  if (QS == true){     // A Heartbeat Was Found
                       // BPM and IBI have been Determined
                       // Quantified Self "QS" true when arduino finds a heartbeat
        digitalWrite(blinkPin,HIGH);     // Blink LED, we got a beat. 
        fadeRate = 255;         // Makes the LED Fade Effect Happen
                                // Set 'fadeRate' Variable to 255 to fade LED with pulse
        serialOutputWhenBeatHappens();   // A Beat Happened, Output that to serial.     
        QS = false;                      // reset the Quantified Self flag for next time    
  }
     
  ledFadeToBeat();                      // Makes the LED Fade Effect Happen 
                        //  take a break
//-----End of Pulse Sensor

  int sensorValue = analogRead(A0);
  int sensorValue1 = analogRead(A1);
  int sensorValue2 = analogRead(A2);
  int sensorValue3 = analogRead(A3);
  int sensorValue4 = analogRead(A4);
  int sensorValue5 = analogRead(A5);
  int sensorValue6 = BPM;
  
  //DHT.read22(DHT22_PIN);
 
  
    
    //-------filtering the flickering 0 results of the DHT sensor
 if(dht.readHumidity() == 0)
    {
      h = prevhumidity;
    } else {
      h = dht.readHumidity();
      prevhumidity = h;
    }
  
  if(dht.readTemperature() == 0)
    {
      t = prevtemperature;
      
    } else {
      t = dht.readTemperature();
      prevtemperature = t;
    }
//-----end of filter
    
  

if(Serial.available()) // check to see if there's serial data in the buffer
{
 serialvalue = Serial.read(); // read a byte of serial data
 started = 1; // set the started flag to on
 if (serialvalue==14)
    {
      digitalWrite(13, HIGH);
    }
     if (serialvalue==13)
    {
      digitalWrite(13, LOW);
    }
}
if(started) { // loop once serial data has been received
 
 Serial.print(sensorValue); // print the first input
 Serial.print(" "); // print a space
 Serial.print(sensorValue1); // print the second input
 Serial.print(" "); // print a space
 Serial.print(sensorValue2); // print the third input
 Serial.print(" "); // print a space
 Serial.print(sensorValue3); // print the fourth input
 Serial.print(" "); // print a space
 Serial.print(sensorValue4); // print the second input
 Serial.print(" "); // print a space
 Serial.print(sensorValue5); // print the second input
 Serial.print(" "); // print a space
 Serial.print(sensorValue6); // print the second input
 Serial.print(" "); // print a space
 Serial.print(h);
 Serial.print(" ");
 Serial.print(t);
 


 Serial.println(); // print a line-feed
 

 
}
}
 
void ledFadeToBeat(){
    fadeRate -= 15;                         //  set LED fade value
    fadeRate = constrain(fadeRate,0,255);   //  keep LED fade value from going into negative numbers!
    analogWrite(fadePin,fadeRate);          //  fade LED
  }

I don't have one of those DHT sensors but I seem to remember other Threads where the library takes a long time to read the sensor.

If that is the problem I think there is a way to start a reading and come back later to get the result - rather than standing beside the cooker waiting for the kettle to boil.

...R

seafox21:
Thanks for the quick reply!

I have experimented with what you suggested, turns out the intervalDHT is related, but then I went ahead to remove all the millis counting code to see does it gives out a continuous stream of data, the stream still stops at every 2 seconds...

//--DHT---------

#include "DHT.h"
#define DHTPIN 4
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
int serialvalue; // value for serial input
int started = 0; // flag for whether we've received serial yet
float prevhumidity;
float prevtemperature;

float t;
float h;
//----End of DHT--------

//-----Pulse Sensor----
int pulsePin = 0;                // Pulse Sensor purple wire connected to analog pin 0
int blinkPin = 12;                // pin to blink led at each beat
int fadePin = 5;                  // pin to do fancy classy fading blink at each beat
int fadeRate = 0;                // used to fade LED on with PWM on fadePin

// Volatile Variables, used in the interrupt service routine!
volatile int BPM;                  // int that holds raw Analog in 0. updated every 2mS
volatile int Signal;                // holds the incoming raw data
volatile int IBI = 600;            // int that holds the time interval between beats! Must be seeded!
volatile boolean Pulse = false;    // "True" when User's live heartbeat is detected. "False" when not a "live beat".
volatile boolean QS = false;        // becomes true when Arduoino finds a beat.

// Regards Serial OutPut  -- Set This Up to your needs
static boolean serialVisual = false;  // Set to 'false' by Default.  Re-set to 'true' to see Arduino Serial Monitor ASCII Visual Pulse
//----End of Pulse Sensor define----

void setup()
{
Serial.begin(115200);  // open the arduino serial port
pinMode(13, OUTPUT);
digitalWrite(13, LOW);
//-----Pulse Sensor-----
pinMode(blinkPin,OUTPUT);        // pin that will blink to your heartbeat!
  pinMode(fadePin,OUTPUT);          // pin that will fade  to your heartbeat!
  //Serial.begin(115200);            // we agree to talk fast!
  interruptSetup();                // sets up to read Pulse Sensor signal every 2mS
  // IF YOU ARE POWERING The Pulse Sensor AT VOLTAGE LESS THAN THE BOARD VOLTAGE,
  // UN-COMMENT THE NEXT LINE AND APPLY THAT VOLTAGE TO THE A-REF PIN
//  analogReference(EXTERNAL); 
//-----End of Pulse Sensor-----
dht.begin();
}

void loop()
{//---Pulse Sensor-----
  serialOutput() ;     
   
  if (QS == true){    // A Heartbeat Was Found
                      // BPM and IBI have been Determined
                      // Quantified Self "QS" true when arduino finds a heartbeat
        digitalWrite(blinkPin,HIGH);    // Blink LED, we got a beat.
        fadeRate = 255;        // Makes the LED Fade Effect Happen
                                // Set 'fadeRate' Variable to 255 to fade LED with pulse
        serialOutputWhenBeatHappens();  // A Beat Happened, Output that to serial.   
        QS = false;                      // reset the Quantified Self flag for next time   
  }
   
  ledFadeToBeat();                      // Makes the LED Fade Effect Happen
                        //  take a break
//-----End of Pulse Sensor

int sensorValue = analogRead(A0);
  int sensorValue1 = analogRead(A1);
  int sensorValue2 = analogRead(A2);
  int sensorValue3 = analogRead(A3);
  int sensorValue4 = analogRead(A4);
  int sensorValue5 = analogRead(A5);
  int sensorValue6 = BPM;
 
  //DHT.read22(DHT22_PIN);

//-------filtering the flickering 0 results of the DHT sensor
if(dht.readHumidity() == 0)
    {
      h = prevhumidity;
    } else {
      h = dht.readHumidity();
      prevhumidity = h;
    }
 
  if(dht.readTemperature() == 0)
    {
      t = prevtemperature;
     
    } else {
      t = dht.readTemperature();
      prevtemperature = t;
    }
//-----end of filter

if(Serial.available()) // check to see if there's serial data in the buffer
{
serialvalue = Serial.read(); // read a byte of serial data
started = 1; // set the started flag to on
if (serialvalue==14)
    {
      digitalWrite(13, HIGH);
    }
    if (serialvalue==13)
    {
      digitalWrite(13, LOW);
    }
}
if(started) { // loop once serial data has been received

Serial.print(sensorValue); // print the first input
Serial.print(" "); // print a space
Serial.print(sensorValue1); // print the second input
Serial.print(" "); // print a space
Serial.print(sensorValue2); // print the third input
Serial.print(" "); // print a space
Serial.print(sensorValue3); // print the fourth input
Serial.print(" "); // print a space
Serial.print(sensorValue4); // print the second input
Serial.print(" "); // print a space
Serial.print(sensorValue5); // print the second input
Serial.print(" "); // print a space
Serial.print(sensorValue6); // print the second input
Serial.print(" "); // print a space
Serial.print(h);
Serial.print(" ");
Serial.print(t);

Serial.println(); // print a line-feed

}
}

void ledFadeToBeat(){
    fadeRate -= 15;                        //  set LED fade value
    fadeRate = constrain(fadeRate,0,255);  //  keep LED fade value from going into negative numbers!
    analogWrite(fadePin,fadeRate);          //  fade LED
  }

Well, this looks wrong:

    //-------filtering the flickering 0 results of the DHT sensor
 if(dht.readHumidity() == 0)
    {
      h = prevhumidity;
    } else {
      h = dht.readHumidity();
      prevhumidity = h;
    }
  
  if(dht.readTemperature() == 0)
    {
      t = prevtemperature;
      
    } else {
      t = dht.readTemperature();
      prevtemperature = t;
    }
//-----end of filter

try something like this:

    //-------filtering the flickering 0 results of the DHT sensor
 h = dht.readHumidity();
 if(h == 0)
    {
      h = prevhumidity;
    } else {
      prevhumidity = h;
    }
  
  t = dht.readTemperature();
  if(t == 0)
    {
      t = prevtemperature;
    } else {
      prevtemperature = t;
    }
//-----end of filter

otherwise you are reading the sensor twice for no reason, and could still get zeros.

comment out the pulse sensor code and see if the Arduino stops. Do the same for the DHT (and put the pulse sensor code back in) so you can work out which of the sensor code is stopping the Arduino.

Hi guys, so I have tried to modifying the code, and switching libraries for the DHT sensor. In the very original code, I used the library from LadyADA, and i think it has a natural code inside the library that instruct the sensor to stop every 2 seconds as a refresh. Now I have switched to the library provided by Rob Tillaart, which doesn't have a refresh limit, so the code runs smoothly with the PulseSensor code. However, the DHT readings are now all over the place. It is outputting some incorrect data that won't react with the fluctuation of the room temperature. Is there any solution to keep the DHT running and outputting an accurate data whilst the pulse sensor code remains active? Thanks again for all the help so far!

seafox21:
Is there any solution to keep the DHT running and outputting an accurate data whilst the pulse sensor code remains active?

Not unless you post your latest code.
You know exactly what changes you made, but we don't.

...R

When you post your latest code, PLEASE:

  • Use the Auto-Format function of the IDE (CTRL-T), and
  • Copy and paste using the code tags button (looks like </> in the toolbar above your post).

Terribly sorry, here it is!
This one is with Rob's library, with continuous run, no interruption but incorrect data from the DHT sensor

//--DHT---------
#include <dht.h> 
#define DHT22_PIN 4
#define DHTTYPE DHT22
dht DHT;
int serialvalue; // value for serial input
int started = 0; // flag for whether we've received serial yet
float prevhumidity;
float prevtemperature;
long previousMillisDHT = 0; //store last time the DHT sensor was updated
long intervalDHT = 2000;
float t;
float h;
//----End of DHT--------


//-----Pulse Sensor----
int pulsePin = 0;                 // Pulse Sensor purple wire connected to analog pin 0
int blinkPin = 12;                // pin to blink led at each beat
int fadePin = 5;                  // pin to do fancy classy fading blink at each beat
int fadeRate = 0;                 // used to fade LED on with PWM on fadePin

// Volatile Variables, used in the interrupt service routine!
volatile int BPM;                   // int that holds raw Analog in 0. updated every 2mS
volatile int Signal;                // holds the incoming raw data
volatile int IBI = 600;             // int that holds the time interval between beats! Must be seeded! 
volatile boolean Pulse = false;     // "True" when User's live heartbeat is detected. "False" when not a "live beat". 
volatile boolean QS = false;        // becomes true when Arduoino finds a beat.

// Regards Serial OutPut  -- Set This Up to your needs
static boolean serialVisual = false;   // Set to 'false' by Default.  Re-set to 'true' to see Arduino Serial Monitor ASCII Visual Pulse
//----End of Pulse Sensor define---

void setup() 
{ 
Serial.begin(115200);  // open the arduino serial port
pinMode(13, OUTPUT);
digitalWrite(13, LOW);
//-----Pulse Sensor-----
pinMode(blinkPin,OUTPUT);         // pin that will blink to your heartbeat!
  pinMode(fadePin,OUTPUT);          // pin that will fade  to your heartbeat!
  //Serial.begin(115200);             // we agree to talk fast!
  interruptSetup();                 // sets up to read Pulse Sensor signal every 2mS 
   // IF YOU ARE POWERING The Pulse Sensor AT VOLTAGE LESS THAN THE BOARD VOLTAGE, 
   // UN-COMMENT THE NEXT LINE AND APPLY THAT VOLTAGE TO THE A-REF PIN
//   analogReference(EXTERNAL);   
//-----End of Pulse Sensor-----
DHT.read22(DHT22_PIN);
}

void loop() 
{//---Pulse Sensor-----
  serialOutput() ;       
    
  if (QS == true){     // A Heartbeat Was Found
                       // BPM and IBI have been Determined
                       // Quantified Self "QS" true when arduino finds a heartbeat
        digitalWrite(blinkPin,HIGH);     // Blink LED, we got a beat. 
        fadeRate = 255;         // Makes the LED Fade Effect Happen
                                // Set 'fadeRate' Variable to 255 to fade LED with pulse
        serialOutputWhenBeatHappens();   // A Beat Happened, Output that to serial.     
        QS = false;                      // reset the Quantified Self flag for next time    
  }
     
  ledFadeToBeat();                      // Makes the LED Fade Effect Happen 
   //delay(20);                            //  take a break
//-----End of Pulse Sensor

  int sensorValue = analogRead(A0);
  int sensorValue1 = analogRead(A1);
  int sensorValue2 = analogRead(A2);
  int sensorValue3 = analogRead(A3);
  int sensorValue4 = analogRead(A4);
  int sensorValue5 = analogRead(A5);
  int sensorValue6 = BPM;
  
 
 
  unsigned long currentMillis = millis();

  if(currentMillis - previousMillisDHT >= intervalDHT) 
  {
    //save the last time DHT is read
    previousMillisDHT = currentMillis;
    
    //-------filtering the flickering 0 results of the DHT sensor
 //-------filtering the flickering 0 results of the DHT sensor
 h = DHT.humidity;
 if(h == 0)
    {
      h = prevhumidity;
    } else {
      prevhumidity = h;
    }
  
  t = DHT.temperature;
  if(t == 0)
    {
      t = prevtemperature;
    } else {
      prevtemperature = t;
    }

//-----end of filter
    
  }
  

if(Serial.available()) // check to see if there's serial data in the buffer
{
 serialvalue = Serial.read(); // read a byte of serial data
 started = 1; // set the started flag to on
 if (serialvalue==14)
    {
      digitalWrite(13, HIGH);
    }
     if (serialvalue==13)
    {
      digitalWrite(13, LOW);
    }
}
if(started) { // loop once serial data has been received
 
 Serial.print(sensorValue); // print the first input
 Serial.print(" "); // print a space
 Serial.print(sensorValue1); // print the second input
 Serial.print(" "); // print a space
 Serial.print(sensorValue2); // print the third input
 Serial.print(" "); // print a space
 Serial.print(sensorValue3); // print the fourth input
 Serial.print(" "); // print a space
 Serial.print(sensorValue4); // print the second input
 Serial.print(" "); // print a space
 Serial.print(sensorValue5); // print the second input
 Serial.print(" "); // print a space
 Serial.print(sensorValue6); // print the second input
 Serial.print(" "); // print a space
 Serial.print(h);
 Serial.print(" ");
 Serial.print(t);
 


 Serial.println(); // print a line-feed
 

 
}
}
 
void ledFadeToBeat(){
    fadeRate -= 15;                         //  set LED fade value
    fadeRate = constrain(fadeRate,0,255);   //  keep LED fade value from going into negative numbers!
    analogWrite(fadePin,fadeRate);          //  fade LED
  }

seafox21:
Terribly sorry, here it is!
This one is with Rob's library, with continuous run, no interruption but incorrect data from the DHT sensor

//--DHT---------

#include <dht.h>
#define DHT22_PIN 4
#define DHTTYPE DHT22
dht DHT;
int serialvalue; // value for serial input
int started = 0; // flag for whether we've received serial yet
float prevhumidity;
float prevtemperature;
long previousMillisDHT = 0; //store last time the DHT sensor was updated
long intervalDHT = 2000;
float t;
float h;
//----End of DHT--------

//-----Pulse Sensor----
int pulsePin = 0;                // Pulse Sensor purple wire connected to analog pin 0
int blinkPin = 12;                // pin to blink led at each beat
int fadePin = 5;                  // pin to do fancy classy fading blink at each beat
int fadeRate = 0;                // used to fade LED on with PWM on fadePin

// Volatile Variables, used in the interrupt service routine!
volatile int BPM;                  // int that holds raw Analog in 0. updated every 2mS
volatile int Signal;                // holds the incoming raw data
volatile int IBI = 600;            // int that holds the time interval between beats! Must be seeded!
volatile boolean Pulse = false;    // "True" when User's live heartbeat is detected. "False" when not a "live beat".
volatile boolean QS = false;        // becomes true when Arduoino finds a beat.

// Regards Serial OutPut  -- Set This Up to your needs
static boolean serialVisual = false;  // Set to 'false' by Default.  Re-set to 'true' to see Arduino Serial Monitor ASCII Visual Pulse
//----End of Pulse Sensor define---

void setup()
{
Serial.begin(115200);  // open the arduino serial port
pinMode(13, OUTPUT);
digitalWrite(13, LOW);
//-----Pulse Sensor-----
pinMode(blinkPin,OUTPUT);        // pin that will blink to your heartbeat!
  pinMode(fadePin,OUTPUT);          // pin that will fade  to your heartbeat!
  //Serial.begin(115200);            // we agree to talk fast!
  interruptSetup();                // sets up to read Pulse Sensor signal every 2mS
  // IF YOU ARE POWERING The Pulse Sensor AT VOLTAGE LESS THAN THE BOARD VOLTAGE,
  // UN-COMMENT THE NEXT LINE AND APPLY THAT VOLTAGE TO THE A-REF PIN
//  analogReference(EXTERNAL); 
//-----End of Pulse Sensor-----
DHT.read22(DHT22_PIN);
}

void loop()
{//---Pulse Sensor-----
  serialOutput() ;     
   
  if (QS == true){    // A Heartbeat Was Found
                      // BPM and IBI have been Determined
                      // Quantified Self "QS" true when arduino finds a heartbeat
        digitalWrite(blinkPin,HIGH);    // Blink LED, we got a beat.
        fadeRate = 255;        // Makes the LED Fade Effect Happen
                                // Set 'fadeRate' Variable to 255 to fade LED with pulse
        serialOutputWhenBeatHappens();  // A Beat Happened, Output that to serial.   
        QS = false;                      // reset the Quantified Self flag for next time   
  }
   
  ledFadeToBeat();                      // Makes the LED Fade Effect Happen
  //delay(20);                            //  take a break
//-----End of Pulse Sensor

int sensorValue = analogRead(A0);
  int sensorValue1 = analogRead(A1);
  int sensorValue2 = analogRead(A2);
  int sensorValue3 = analogRead(A3);
  int sensorValue4 = analogRead(A4);
  int sensorValue5 = analogRead(A5);
  int sensorValue6 = BPM;

unsigned long currentMillis = millis();

if(currentMillis - previousMillisDHT >= intervalDHT)
  {
    //save the last time DHT is read
    previousMillisDHT = currentMillis;
   
    //-------filtering the flickering 0 results of the DHT sensor
//-------filtering the flickering 0 results of the DHT sensor
h = DHT.humidity;
if(h == 0)
    {
      h = prevhumidity;
    } else {
      prevhumidity = h;
    }
 
  t = DHT.temperature;
  if(t == 0)
    {
      t = prevtemperature;
    } else {
      prevtemperature = t;
    }

//-----end of filter
   
  }

if(Serial.available()) // check to see if there's serial data in the buffer
{
serialvalue = Serial.read(); // read a byte of serial data
started = 1; // set the started flag to on
if (serialvalue==14)
    {
      digitalWrite(13, HIGH);
    }
    if (serialvalue==13)
    {
      digitalWrite(13, LOW);
    }
}
if(started) { // loop once serial data has been received

Serial.print(sensorValue); // print the first input
Serial.print(" "); // print a space
Serial.print(sensorValue1); // print the second input
Serial.print(" "); // print a space
Serial.print(sensorValue2); // print the third input
Serial.print(" "); // print a space
Serial.print(sensorValue3); // print the fourth input
Serial.print(" "); // print a space
Serial.print(sensorValue4); // print the second input
Serial.print(" "); // print a space
Serial.print(sensorValue5); // print the second input
Serial.print(" "); // print a space
Serial.print(sensorValue6); // print the second input
Serial.print(" "); // print a space
Serial.print(h);
Serial.print(" ");
Serial.print(t);

Serial.println(); // print a line-feed

}
}

void ledFadeToBeat(){
    fadeRate -= 15;                        //  set LED fade value
    fadeRate = constrain(fadeRate,0,255);  //  keep LED fade value from going into negative numbers!
    analogWrite(fadePin,fadeRate);          //  fade LED
  }

Have a look at Rob's example here:

You need to read the dht every loop(), not once in setup() (remove the read from setup()).

Like:

loop()
{
    int chk = DHT.read22(DHT22_PIN);

/*
    switch (chk)
    {
    case DHTLIB_OK:
        //Serial.print("OK,\t");
        break;
    case DHTLIB_ERROR_CHECKSUM:
        Serial.print("Checksum error,\t");
        break;
    case DHTLIB_ERROR_TIMEOUT:
        Serial.print("Time out error,\t");
        break;
    case DHTLIB_ERROR_CONNECT:
        Serial.print("Connect error,\t");
        break;
    case DHTLIB_ERROR_ACK_L:
        Serial.print("Ack Low error,\t");
        break;
    case DHTLIB_ERROR_ACK_H:
        Serial.print("Ack High error,\t");
        break;
    default:
        Serial.print("Unknown error,\t");
        break;
    }
*/

    // DISPLAY DATA
    h = DHT.humidity;
}

after a few days of experimentation, this is what i have so far, still outputing either 0s or incorrect data, here is the latest code with rob library...

//--DHT---------
#include <dht.h> 
#define DHT22_PIN 4
//#define DHTTYPE DHT22
dht DHT;
int serialvalue; // value for serial input
int started = 0; // flag for whether we've received serial yet
float prevhumidity;
float prevtemperature;
long previousMillisDHT = 0; //store last time the DHT sensor was updated
long intervalDHT = 2000;
long realtimeinterval = 0;
float t;
float h;
//----End of DHT--------


//-----Pulse Sensor----
int pulsePin = 0;                 // Pulse Sensor purple wire connected to analog pin 0
int blinkPin = 12;                // pin to blink led at each beat
int fadePin = 5;                  // pin to do fancy classy fading blink at each beat
int fadeRate = 0;                 // used to fade LED on with PWM on fadePin

// Volatile Variables, used in the interrupt service routine!
volatile int BPM;                   // int that holds raw Analog in 0. updated every 2mS
volatile int Signal;                // holds the incoming raw data
volatile int IBI = 600;             // int that holds the time interval between beats! Must be seeded! 
volatile boolean Pulse = false;     // "True" when User's live heartbeat is detected. "False" when not a "live beat". 
volatile boolean QS = false;        // becomes true when Arduoino finds a beat.

// Regards Serial OutPut  -- Set This Up to your needs
static boolean serialVisual = false;   // Set to 'false' by Default.  Re-set to 'true' to see Arduino Serial Monitor ASCII Visual Pulse
//----End of Pulse Sensor define---

void setup() 
{ 
Serial.begin(115200);  // open the arduino serial port
pinMode(13, OUTPUT);
digitalWrite(13, LOW);
//-----Pulse Sensor-----
pinMode(blinkPin,OUTPUT);         // pin that will blink to your heartbeat!
  pinMode(fadePin,OUTPUT);          // pin that will fade  to your heartbeat!
  //Serial.begin(115200);             // we agree to talk fast!
  interruptSetup();                 // sets up to read Pulse Sensor signal every 2mS 
   // IF YOU ARE POWERING The Pulse Sensor AT VOLTAGE LESS THAN THE BOARD VOLTAGE, 
   // UN-COMMENT THE NEXT LINE AND APPLY THAT VOLTAGE TO THE A-REF PIN
//   analogReference(EXTERNAL);   
//-----End of Pulse Sensor-----

}

void loop() 
{//---Pulse Sensor-----
  serialOutput() ;       
    
  if (QS == true){     // A Heartbeat Was Found
                       // BPM and IBI have been Determined
                       // Quantified Self "QS" true when arduino finds a heartbeat
        digitalWrite(blinkPin,HIGH);     // Blink LED, we got a beat. 
        fadeRate = 255;         // Makes the LED Fade Effect Happen
                                // Set 'fadeRate' Variable to 255 to fade LED with pulse
        serialOutputWhenBeatHappens();   // A Beat Happened, Output that to serial.     
        QS = false;                      // reset the Quantified Self flag for next time    
  }
     
  ledFadeToBeat();                      // Makes the LED Fade Effect Happen 
   //delay(20);                            //  take a break
//-----End of Pulse Sensor

  int sensorValue = analogRead(A0);
  int sensorValue1 = analogRead(A1);
  int sensorValue2 = analogRead(A2);
  int sensorValue3 = analogRead(A3);
  int sensorValue4 = analogRead(A4);
  int sensorValue5 = analogRead(A5);
  int sensorValue6 = BPM;
  
  unsigned long currentMillis = millis();
  currentMillis - previousMillisDHT == realtimeinterval;


switch (realtimeinterval)
{
  case 2000:
  previousMillisDHT = currentMillis;
  DHT.read22(DHT22_PIN);
  h = DHT.humidity;
  if(h == 0)
  {
   h = prevhumidity;
  } else {
    prevhumidity = h;
  }
  t = DHT.temperature;
  if(t == 0)
  {
    t = prevtemperature;
  } else {
    prevtemperature = t;
  }
  break;
  
}


  //if(currentMillis - previousMillisDHT >= intervalDHT) 
  //{
    //save the last time DHT is read
    //previousMillisDHT = currentMillis;
     //DHT.read22(DHT22_PIN);
    //-------filtering the flickering 0 results of the DHT sensor
 //-------filtering the flickering 0 results of the DHT sensor
  //h = DHT.humidity;
 //if(h == 0)
   // {
     // h = prevhumidity;
    //} else {
    //  prevhumidity = h;
   // }
  
  //t = DHT.temperature;
  //if(t == 0)
    //{
      //t = prevtemperature;
    //} else {
      //prevtemperature = t;
    //}

//-----end of filter
    
 // } 
  

if(Serial.available()) // check to see if there's serial data in the buffer
{
 serialvalue = Serial.read(); // read a byte of serial data
 started = 1; // set the started flag to on
 if (serialvalue==14)
    {
      digitalWrite(13, HIGH);
    }
     if (serialvalue==13)
    {
      digitalWrite(13, LOW);
    }
}
if(started) { // loop once serial data has been received
 
 Serial.print(sensorValue); // print the first input
 Serial.print(" "); // print a space
 Serial.print(sensorValue1); // print the second input
 Serial.print(" "); // print a space
 Serial.print(sensorValue2); // print the third input
 Serial.print(" "); // print a space
 Serial.print(sensorValue3); // print the fourth input
 Serial.print(" "); // print a space
 Serial.print(sensorValue4); // print the second input
 Serial.print(" "); // print a space
 Serial.print(sensorValue5); // print the second input
 Serial.print(" "); // print a space
 Serial.print(sensorValue6); // print the second input
 Serial.print(" "); // print a space
 Serial.print(DHT.humidity, 1);
 Serial.print(" ");
 Serial.print(DHT.temperature, 1);
 


 Serial.println(); // print a line-feed
 

 
}
}
 
void ledFadeToBeat(){
    fadeRate -= 15;                         //  set LED fade value
    fadeRate = constrain(fadeRate,0,255);   //  keep LED fade value from going into negative numbers!
    analogWrite(fadePin,fadeRate);          //  fade LED
  }

still outputing either 0s or incorrect data

For what variable? Anonymous printing sucks. Identify EVERYTHING, so you know what is what.