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() {
Serial.begin(9600);
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.println(DHT.temperature);
Serial.print("Humidity = ");
Serial.println(DHT.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);
delay(50);
}
// for a bit of fault tolerance, reset the arduino after receiving any command
reset();
}
// 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;
Serial.print(",");
Serial.print(number);
}
Serial.println("");
receiver.resume();
}
delay(min_delay);
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:
and