thanks AWOL the code in the link for the timer and the other one in this post,
DrAzzy thanks very much you can take look at the code,
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <OneWire.h>
#include <DHT.h>
#include <DallasTemperature.h>
#include <SD.h>
#include <SPI.h>
#include <EEPROM.h>
DHT dht;
OneWire oneWire(8);
DallasTemperature sensors(&oneWire);
DeviceAddress Thermometer = { 0x28, 0xFF, 0x88, 0x1E, 0x02, 0x15, 0x02, 0x70 }; // Temperature Sensor
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
#define Cont 0x26 // relay board
int PinNo1e = 1;
int PinNo2e = 1;
int PinNo3e = 1;
int PinNo4e = 1;
int PinNo5e = 1;
int PinNo6e = 1;
int PinNo2 = 2;
int PinNo3 = 3;
int PinNo4 = 4;
int PinNo5 = 5;
int Minus = 0;
int Plus = 0;
int Ok = 0;
int Set = 0;
int push=0;
double tempC=0;
int Humid=0;
double val=0;
double SetT;
int SetH;
int SetVent1;
int SetVent2;
int SetTimer1;
int SetTimer2;
int hour=0;
long day=0;
byte binary=0;
long timenw=0;
long timepr1=0;
long timepr2=0;
long timepr3=0;
long timepr4=0;
int Ventc=0;
int Timec1=0;
int Timec2=0;
int rvent=0;
int ovent=0;
int rtimer=0;
int side=0;
void setup() {
// put your setup code here, to run once:
dht.setup(6); // data pin 9
Serial.begin(9600); //(Remove all 'Serial' commands if not needed)
Wire.begin();
Wire.write(0x00);
Wire.write(0x00);
day=EEPROM.read(6);
lcd.begin(20,4); // initialize the lcd for 20 chars 4 lines, turn on backlight
lcd.backlight();
sensors.setResolution(Thermometer, 12);
pinMode(PinNo2, INPUT); // declare pushbutton as input
pinMode(PinNo3, INPUT); // declare pushbutton as input
pinMode(PinNo4, INPUT); // declare pushbutton as input
pinMode(PinNo5, INPUT); // declare pushbutton as input
digitalWrite(PinNo2, HIGH);
digitalWrite(PinNo3, HIGH);
digitalWrite(PinNo4, HIGH);
digitalWrite(PinNo5, HIGH);
while (!Serial) {
;
}
pinMode(10, OUTPUT);
pinMode(4, OUTPUT);
sprintf(filename,"Log%04d.txt",day);
if (!SD.begin(4)){
return;
}
}
void Status(){
Wire.beginTransmission(Cont);
binary=B11111111;
if (PinNo1e==0){
binary=binary-B00000000;
}
if (PinNo2e==0){
binary=binary-B00000001;
}
if (PinNo3e==0){
binary=binary-B00000010;
}
if (PinNo4e==0){
binary=binary-B00000100;
}
if (PinNo5e==0){
binary=binary-B00010000;
}
if (PinNo6e==0){
binary=binary-B00100000;
}
Wire.write(binary);
Wire.endTransmission();
}
void button(){
Set = digitalRead(PinNo2); // read input value Set
Ok = digitalRead(PinNo3); // read input value Ok
Plus= digitalRead(PinNo4); // read input value
Minus= digitalRead(PinNo5); // read input value
if (push>0){
if(push<7){
if (Ok== LOW){
push=push+1;
}
}else{
push=0;
}
}
}
void normal(){
float Humid = dht.getHumidity();
lcd.setCursor(0, 0);
lcd.print("iBird Machine");
sensors.requestTemperatures();
lcd.setCursor(0, 1);
lcd.print("Temp:");
lcd.setCursor(5, 1);
float tempC = sensors.getTempC(Thermometer);
if(Minus==LOW){
lcd.print(SetT,1);
}else{
lcd.print(tempC,1);
}
lcd.print("C");
if(PinNo2e == 0){
lcd.print("!");
}else{
lcd.print("x");
}
lcd.print(" Hum:");
if(Minus==LOW){
lcd.print(SetH,1);
}else{
lcd.print(Humid, 0);
}
lcd.print("%");
if(PinNo4e == 0){
lcd.print("!");
}else{
lcd.print("x");
}
lcd.setCursor(0, 2);
lcd.print("Vent:");
if(Minus==LOW){
lcd.print((float)SetVent1, 0);
}else{
lcd.print((timenw-timepr2)/60000);
}
lcd.print("min");
if(PinNo3e == 0){
lcd.print("!");
}else{
lcd.print("x");
}
lcd.print(" Run:");
lcd.print((float)Ventc,0);
lcd.print(" ");
lcd.setCursor(0, 3);
lcd.print("Turn:");
if(Minus==LOW){
lcd.print((float)SetTimer1, 0);
}else{
lcd.print((timenw-timepr1)/60000);
}
lcd.print("min");
if(PinNo5e == 0 || PinNo6e == 0){
lcd.print("!");
}else{
lcd.print("x");
}
lcd.print(" Run:");
lcd.print((float)Timec1,0);
lcd.print(" ");
delay(750);
if(Set == LOW&&push==0){
push=1;
}
}
void loop() {
// put your main code here, to run repeatedly:
SDcard();
SetVal();
button();
if (push >0){
lcd.clear();
lcd.setCursor(0, 1);
}
if(push==0){
normal();
timer1();
timer2();
Control1();
}else if(push==1){
lcd.print("Temperature Setting");
// TempSet();
}else if(push==2){
lcd.print("Humidity Setting");
// HumidSet();
}else if(push==3){
lcd.print("Vent Timer 1 Setting");
// Vent1Set();
}else if(push==4){
lcd.print("Vent Timer 2 Setting");
// Vent2Set();
}else if(push==5){
lcd.print("Timer 1 Setting");
// Timer1Set();
}else if(push==6){
lcd.print("Timer 2 Setting");
// Timer2Set();
}
Status();
// initialize the lcd for 20 chars 4 lines, turn on backlight
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
while (!Serial) {
;
}
if (!SD.begin(4)){
return;
}
}
void SetVal(){
if (SetT > 38.2 || SetT<35.0){
SetT=37.7;
}
if (SetH < 20 || SetH> 80){
SetH=60;
}
if (SetVent1 > 120 || SetVent1<5){
SetVent1=60;
}
if (SetVent2 < 2 || SetVent2 > 60){
SetVent2=15;
}
if (SetTimer1 > 120 || SetTimer1 <30){
SetTimer1=90;
}
if (SetTimer2 <0 || SetTimer2>300){
SetTimer2=8;
}
if(millis()<=2000){
if(EEPROM.read(1)<20||EEPROM.read(1)>90||EEPROM.read(2)>120||EEPROM.read(2)<1){
EEPROM.write(0,(SetT*10)-256);
EEPROM.write(1,SetH);
EEPROM.write(2,SetVent1);
EEPROM.write(3,SetVent2);
EEPROM.write(4,SetTimer1);
EEPROM.write(5,SetTimer2);
}else{
SetT=(EEPROM.read(0)+256);
SetT=SetT/10;
SetH=EEPROM.read(1);
SetVent1=EEPROM.read(2);
SetVent2=EEPROM.read(3);
SetTimer1=EEPROM.read(4);
SetTimer2=EEPROM.read(5);
}
delay(2000);
}
}