//declare global parameters as needed----------
#include<Wire.h> //to handle DS1307 using I2C Bus; I have problem with RTClib.h Library
#include <DallasTemperature.h> //to handle DS18B20 sensor
#include<LiquidCrystal_I2C.h> //to handle I2CLCD
LiquidCrystal_I2C lcd(0x27, 16, 2); //wiring function for I2CLCD
unsigned int dsTemp; //to hold integer value for the Temperature given by DS18B20
#define ONE_WIRE_BUS 10 //DPin-10 is the signal wire for DS18B20 with 2.2k pull-up
OneWire oneWire(ONE_WIRE_BUS); //DS18B20 is an 1-Wire device
DallasTemperature sensors(&oneWire); //we are using dallas library
void setup()
{
Serial.begin(9600); //Initialize Serial Monitor at 9600 Bd
Wire.begin(); //Intialize I2C Bus
//------------------------------------------------------------------
lcd.init(); //initialize I2CLCD
lcd.backlight();
//------------------------------------------------------------------
pinMode(12, OUTPUT); //relay control is DPin-12
//------------------------------------------------------------------
setIntialTimeInRTC(); //set initial time in 24 hrs format
}
void loop()
{
showTimeOnLCD(); //acquire Time and show on Top Line of LCD
showTempOnLCD(); //acquire temperature and show on Bottom line of LCD
makeDecisionMorning(); //8am - 8pm ---> 08:00:00 -- 20:00:00
makeDecisionEvening(); //8pm - 8am ---> 20:00:00 -- 08:00:00
}
void setIntialTimeInRTC() //set initial time manually at: (say) 23 : 58 : 36
{
Wire.beginTransmission(0x68); //START, Roll Cal
Wire.write(0x00); //set SEC Register address
Wire.write(0x36); //set SEC Register value (BCD)
Wire.write(0x58); //set MIN Register value
Wire.write(0x23); //set HRS Register value
Wire.endTransmission(); //Execute the above queued data, ACK, STOP
}
void showTimeOnLCD()
{
Wire.beginTransmission(0x68); //START, Roll Cal
Wire.write(0x00); //set SEC Register address
Wire.endTransmission(); //Execute the above queued data, ACK, STOP
Wire.requestFrom(0x68, 3); //SEC, MIN, and HRS to read from RTC as BCD
byte bcdSeconds = Wire.read();
byte bcdMinutes = Wire.read();
byte bcdHours = Wire.read();
//bcdHours = bcdHours & 0b00111111;
lcd.setCursor(0, 0);
lcd.print("Time = ");
//show HRS--
lcd.write((bcdHours>>4) + 0x30);
lcd.write((bcdHours & 0x0F) + 0x30);
lcd.write(':');
//show MIN--
lcd.write((bcdMinutes>>4) + 0x30);
lcd.write((bcdMinutes & 0x0F) + 0x30);
lcd.print(':');
//show SEC
lcd.write((bcdSeconds>>4) + 0x30);
lcd.write((bcdSeconds & 0x0F) + 0x30);
}
void showTempOnLCD()
{
sensors.requestTemperatures(); // Temp conversion command; waiting here until comversion is done
dsTemp = sensors.getTempCByIndex(0); //read temp data from Sensor #0 and convert to celsius float
lcd.setCursor(0, 1);
lcd.print("Temp = ");
lcd.print(dsTemp);
lcd.write(0xDF);
lcd.print('C');
// delay(500); //sample temperature at 2-sec interval
}
void makeDecisionMorning() //8am - 8pm Heater ON when Temp is >=10 C and <=30 C
{
dsTemp = sensors.getTempCByIndex(0);
if(dsTemp >=10)
{
if(dsTemp <= 30)
{
digitalWrite(11, HIGH); //Heater ON
return;
}
}
digitalWrite(12, LOW); //Heater OFF
}
void makeDecisionEvening()
{
dsTemp = sensors.getTempCByIndex(0);
lcd.setCursor(14, 1);
lcd.print(dsTemp);
if(dsTemp >=20)
{
if(dsTemp <= 30)
{
digitalWrite(12, HIGH);
return;
}
}
digitalWrite(12, LOW);
}
Mon nouveau programme j'aimerais savoir si il marche s'il vous plait .