Hi all.This project so important for me.My project has 2 DHT11, 20X4 I2C LCD , ARDUINO UNO R3 , RELAY .Project can comparison values and read the two temperature.Values are Temperature 1(T1) and Temperature 2(T2).If T1 is bigger than T2,relay will open.If T1 is lower than T2,relay will close.If T1 is equal T2 ,relay will open then will close immediately.Im competed to read 2 temperature values.But I couldn't do other 2 situations.Im waiting your support.
#include <Wire.h>
#include <dht11.h>
#include <LiquidCrystal_I2C.h> // I2C LIBRARY
LiquidCrystal_I2C lcd(0x27,20,4);
#define relay 7
#define DHT1_PIN 8
#define DHT2_PIN 9
dht11 DHT11;
void setup() {
//INPUT AND OUTPUT
pinMode(relay,OUTPUT);
digitalWrite(relay,LOW);
//LCD Ekranın ilk açılmasında yazacaklar
lcd.begin();
lcd.setCursor(0,0);
lcd.print("PROJEM 1");
lcd.setCursor(0,1);
lcd.print("NECMETTIN ERBAKAN U.");
lcd.setCursor(0,2);
lcd.print("NASUH OGUZHAN SENSOY");
lcd.setCursor(0,3);
lcd.print("13:25-12/04/20");
delay(3000);
lcd.clear();
}
void loop() {
int chk = DHT11.read(DHT1_PIN);//FIRST TEMPERATURE VALUE(T1)
lcd.setCursor(0,0);
lcd.print("SICAKLIK-1:");
lcd.println((float)DHT11.temperature,0);
lcd.setCursor(14,0);
lcd.println("DERECE");
delay(500);
int chk2 = DHT11.read(DHT2_PIN);//SECOND TEMPERATURE VALUE(T2)
lcd.setCursor(0,1);
lcd.print("SICAKLIK-2:");
lcd.println((float)DHT11.temperature,0);
lcd.setCursor(14,1);
lcd.println("DERECE");
delay(100);
//COMPARISON OF TEMPERATURE VALUES(CHK AND CHK2)
if ( chk > chk2 )//T1 is bigger than T2
DHT11.read(DHT1_PIN);
DHT11.read(DHT2_PIN);
true;
digitalWrite(relay,HIGH);
delay(100);
//T2 is bigger than T2 and T1 = T2 ,I couldn't this situations
}
The chk and chk2 values are not the temperatures; they relate to the success or otherwise of the dht read. The example with the library shows them as DHTLIB_OK, DHTLIB_ERROR_CHECKSUM and so on.
The chk and chk2 values are not the temperatures; they relate to the success or otherwise of the dht read. The example with the library shows them as DHTLIB_OK, DHTLIB_ERROR_CHECKSUM and so on.
Thanks.Im showing correctly temperatures (with chk and chk2 ).If the temperature values are not chk and chk2,how can i compare the temperatures?
Why don't you do a serial print of those and see what they are? If both reads were clean, the return values chk and chk2 will both be DHTLIB_OK, and always equal.
Side issue:
Is it correct / acceptable / good practice to do two dht reads on different pins, from the same instance?
dht11 DHT11;
..
int chk = DHT11.read(DHT1_PIN);
..
int chk2 = DHT11.read(DHT2_PIN);
I would have been inclined to make two:
dht11 DHT11_1;
dht11 DHT11_2;
But I suppose it's ok since OP says the values displayed are correct.
You already display the temperatures in the lcd.print() lines, so you know where they come from.
So before you do the display, read those .temperatures into 2 more variables:
int chk = DHT11.read(DHT1_PIN);//FIRST TEMPERATURE VALUE
float T1=DHT11.temperature;
..
int chk2 = DHT11.read(DHT2_PIN); //SECOND TEMPERATURE VALUE
float T2=DHT11.temperature;
... then compare T1 and T2 rather than chk and chk2.
(Assuming it's ok to read two values from the two pins with the same instance; see my "side issue" above.)
The low is pretty much going to be ignored if the else is still invoked next time through loop(), since it will go low and immediately back to high. I wonder if a mechanical relay will even have a chance to react.
Then, assuming either that's right, or you need a delay() after the low, do you actually want the relay to oscillate high and low while the values T1 and T2 are equal. (Not that 2x floats are ever likely to be seen as identical anyway....)
The low is pretty much going to be ignored if the else is still invoked next time through loop(), since it will go low and immediately back to high. I wonder if a mechanical relay will even have a chance to react.
Then, assuming either that's right, or you need a delay() after the low, do you actually want the relay to oscillate high and low while the values T1 and T2 are equal. (Not that 2x floats are ever likely to be seen as identical anyway....)
You are telling truth. When T1 and T2 values are equal, I can request the relay to swing high and low.
It's going to be difficult to test in real life, since I think it's unlikely that floats from the 2 sensors will be deemed equal; not for long anyway. Perhaps you should // out the part where it actually puts the temps into T1 and T2, and hardcode them as identical values and see if it behaves as you wish:
//float T1=DHT11.temperature;//FIRST TEMPERATURE VALUE
float T1=50;
..
//float T2=DHT11.temperature;//SECOND TEMPERATURE VALUE
float T2=T1;
(You may want to consider some hysteresis here, and rather check if T1 and T2 are within (say) 2 or 3 degrees of each other?)