Combine DHT11 temp&humi Sensor with IR transmitter/Receiver

Good Evening to everyone,

I like to automate a few things around my home. I know how to program and i am not exactly new to Arduino but it is not an every day task either.
To the question:

I can read temperatures on Serial from the DHT11 sensor if i use the code for it alone and the same with receive/transmit. The DHT11 sensor needs a delay time (>1300) otherwise it prints only -999.
So i have to combine the continues “reading” for the transmitter (no use of delay) with a delay for the DHT11 to be read correctly. As a work around i used an if and a counter (with a minor delay). But the program bypasses the If statement and the DHT11 sensor’s values never appear. I am working on it the last 4 hours and i am really frustrated for not seeing something that will be obvious, that’s why i beg for your help. The Code is the following:

#include <IRremote.h>
#include <dht.h>

dht DHT;

#define DHT11_PIN 7

IRrecv receiver(2); // receiver is connected to pin2
IRsend sender;
decode_results results;

long repetitions;
long count;
float min_delay;
float Sensor_delay;
unsigned int durations[100];
void (*reset)(void) = 0;

void setup() {
  receiver.enableIRIn(); // start receiving signals
  min_delay = 0.01;
  Sensor_delay = 0;

void loop() {
   Serial.println(Sensor_delay); \\Debugging
   if (Sensor_delay == 1.00){
      Serial.println("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"); \\Frustrated Debugging Line :D
      Sensor_delay = 0;
      int chk = DHT.read11(DHT11_PIN);
      Serial.print("Temperature = ");
      Serial.print("Humidity = ");

  if(Serial.available()) {

    // parse the text
    repetitions = Serial.parseInt();
    count = Serial.parseInt();
    for(int i = 0; i < count; i++)
      durations[i] = Serial.parseInt();

    // send the command using 40kHz PWM
    for(int i = 0; i < repetitions; i++) {
      sender.sendRaw(durations, count, 40);

    // for a bit of fault tolerance, reset the arduino after receiving any command

  // check if a decoded infrared signal is available
  if(receiver.decode(&results)) {
    Serial.println(results.value, HEX);
    Serial.print(results.rawlen - 1);
    for(int i = 1; i < results.rawlen; i++) {
      unsigned int number = results.rawbuf[i] * USECPERTICK;
  Sensor_delay = (Sensor_delay + min_delay);

PS1: The Board is an Arduino Uno
PS2: I also have a receiver on, in case i want to record any IR codes (so i don’t plug and unplug cables on my board)
PS3: The original codes (before the combination) are here:


The delay function takes an integer value (number of milliseconds), not a float (which I'm guessing is seconds). Also, NEVER, NEVER, NEVER compare a float to another float for equality, due to how floats are stored, your 1.0 may actually be 0.999999999999999 or something else that is not the same.

Also, check out the example "BlinkWithoutDelay" to see a better approach to implementing a delay in your code while still keeping it responsive.

And get rid of that silly reset().

I can't thank you enough blh64. Indeed when i changed from the " == " to " >= " it worked so your eye caught immediately the error.

It was a silly question and a noob mistake i assume but after spending hours troubleshooting the code i knew i needed help.

So thank you once again.


Edit: And i threw the reset() out the window!! :D