Guys, I have a problem in my project.
It is to measure the internal temperature with 3 sensor "Tmed" = ((t2 +t3 +t4)/3) average.
this value should be compared to the external temperature "t1"
if the difference of the average internal to external temperature "(tmed - t1)" is less than 10 °C
The buzzer should be activated
and the average humidity "hmed" is less than 50% the buzzer should be activated.
In this sketch can not trigger the buzzer .. commands are right. I did another sketch with 2 DHT11 temperature variation and did and it worked perfect.
I think we're having some conflict because this sketch the same command does not work.
#include <Wire.h>
#include <DHT.h>
#include <LiquidCrystal.h>
#define DHT1PIN 10 // Sensor externo
#define DHT2PIN 12
#define DHT3PIN 9
#define DHT4PIN 8
#define DHTTYPE DHT11 // tipo de sensor DHT 11
#define DS1307_ADDRESS 0x68
byte zero = 0x00;
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
DHT dht1(DHT1PIN, DHTTYPE);
DHT dht2(DHT2PIN, DHTTYPE);
DHT dht3(DHT3PIN, DHTTYPE);
DHT dht4(DHT4PIN, DHTTYPE);
void setup() {
Wire.begin();
Serial.begin(9600);
lcd.begin(16, 2);
dht1.begin();
dht2.begin();
dht3.begin();
dht4.begin();
pinMode(13,OUTPUT); //Buzzer
//setDateTime();
}
void loop() {
printDate();
printsensor();
}
void setDateTime(){
byte second = 45; //0-59
byte minute = 15; //0-59
byte hour = 21; //0-23
byte weekDay = 3; //1-7
byte monthDay = 18; //1-31
byte month = 10; //1-12
byte year = 14; //0-99
Wire.beginTransmission(DS1307_ADDRESS);
Wire.write(zero); //stop Oscillator
Wire.write(decToBcd(second));
Wire.write(decToBcd(minute));
Wire.write(decToBcd(hour));
Wire.write(decToBcd(weekDay));
Wire.write(decToBcd(monthDay));
Wire.write(decToBcd(month));
Wire.write(decToBcd(year));
Wire.write(zero); //start
Wire.endTransmission();
}
byte decToBcd(byte val){
// Convert normal decimal numbers to binary coded decimal
return ( (val/10*16) + (val%10) );
}
byte bcdToDec(byte val) {
// Convert binary coded decimal to normal decimal numbers
return ( (val/16*10) + (val%16) );
}
void printDate(){
// Reset the register pointer
Wire.beginTransmission(DS1307_ADDRESS);
Wire.write(zero);
Wire.endTransmission();
Wire.requestFrom(DS1307_ADDRESS, 7);
int second = bcdToDec(Wire.read());
int minute = bcdToDec(Wire.read());
int hour = bcdToDec(Wire.read() & 0b111111); //24 hour time
int weekDay = bcdToDec(Wire.read()); //0-6 -> sunday - Saturday
int monthDay = bcdToDec(Wire.read());
int month = bcdToDec(Wire.read());
int year = bcdToDec(Wire.read());
//print the date EG 3/1/11 23:59:59
Serial.print(monthDay);
Serial.print("/");
Serial.print(month);
Serial.print("/");
Serial.print(year);
Serial.print(" ");
Serial.print(hour);
Serial.print(":");
Serial.print(minute);
Serial.print(":");
Serial.print(second);
}
void printsensor(){
int h1 = dht1.readHumidity(); //umidade externa
int t1 = dht1.readTemperature(); //temperatura externa
int h2 = dht2.readHumidity();
int t2 = dht2.readTemperature();
int h3 = dht3.readHumidity();
int t3 = dht3.readTemperature();
int h4 = dht4.readHumidity();
int t4 = dht4.readTemperature();
int hmed = ((h2 + h3 + h4)/3); //average internal humidity
int tmed = ((t2 + t3 + t4)/3); //average internal temperature
int tdif = (tmed - t1); //diference internal temperature with external
if (tdif<10)
{
digitalWrite(13,HIGH);
}
else
{
digitalWrite(13,LOW);
}
if (hmed<50)
{
digitalWrite(13,HIGH);
}
else
{
digitalWrite(13,LOW);
}
Serial.print(" ");
Serial.print(h1);
Serial.print(" ");
Serial.print(h2);
Serial.print(" ");
Serial.print(h3);
Serial.print(" ");
Serial.print(h4);
Serial.print(" ");
Serial.print(t1);
Serial.print(" ");
Serial.print(t2);
Serial.print(" ");
Serial.print(t3);
Serial.print(" ");
Serial.print(t4);
Serial.print(" ");
Serial.print(hmed);
Serial.print(" ");
Serial.print(tmed);
Serial.print(" ");
Serial.println(tdif);
delay(2000);
lcd.setCursor(0,0);
lcd.print("INT:");
lcd.setCursor(5,0);
lcd.print("T");
lcd.setCursor(6,0);
lcd.print(tmed);
lcd.setCursor(8,0);
lcd.print((char)223);
lcd.setCursor(9,0);
lcd.print("C");
lcd.setCursor(11,0);
lcd.print("Um");
lcd.setCursor(13,0);
lcd.print(hmed);
lcd.setCursor(15,0);
lcd.print("%");
lcd.setCursor(0,1);
lcd.print("EXT:");
lcd.setCursor(5,1);
lcd.print("T");
lcd.setCursor(6,1);
lcd.print(t1);
lcd.setCursor(8,1);
lcd.print((char)223);
lcd.setCursor(9,1);
lcd.print("C");
lcd.setCursor(11,1);
lcd.print("Um");
lcd.setCursor(13,1);
lcd.print(h1);
lcd.setCursor(15,1);
lcd.print("%");
}