Go Down

Topic: add hours and days on timecounter (Read 916 times) previous topic - next topic

PaulS

When you are stuck at the beginning, the thing to do is to define what you want to do, with no thought as to how you would do it (whatever it is). So, what is it you want to do?

dalai

#6
Apr 06, 2011, 09:09 pm Last Edit: Apr 06, 2011, 09:25 pm by dalai Reason: 1
My project is an egg hatcher.Its a project that involves  all basic electronics (sensors ,timers, moters, buttons etc) so i thote that is a good start for learning.
Until now my code ,reads temperature and huminity.Then makes a desition for opening airflow  heaters boilers etc.
The method is that 2 temperature sensors reads temp and by the method of wet bumb i get huminity.

My next step is to insert time in project. The reason is that chickens  egg  need to be at 37 C / 80 humidity  for 18 days  and then  for the last 3 days needs 36 C/ 90 humidity and no moving .
There is some problems in that idea. First I think that I want to avoid external timer.I want by a button choice ,a timer of days start up.
In that point by an internal timer I think that I solved that problem. But if power lost ,program will start from day 1.
So I want by a press of button to correct time counter (1 button for hours , one for days)

Later I will try to backup time elapsed to eeprom every 1 hour but for now I need to be able to correct time counter ....

A litle dificult for newbie ,but I needed motivation :)

Here is the code I copied/write  until now

Code: [Select]

// include the library code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);


int pin0 = 0; // analog pin 0
int pin1 = 1; // analog pin 1
int heater = 13;
int cooler = 10;
float tempF = 0,tempC=0,wetF=0,wetC=0,etemp=0,ewet=0,eall=0,humidity=0 ; // temperature variables
float samples[8]; // variables to make a better precision (dry sensor)
float wetsamples[8]; // variables to make a better precision (wet sensor)
int i;

void setup()
{
  Serial.begin(9600); // start serial communication
  lcd.begin(16, 4);  // set up the LCD's number of columns and rows
  pinMode(cooler, OUTPUT);
  pinMode(heater, OUTPUT);
}

void loop()
{


for(i = 0;i<=7;i++){ // gets 8 samples of temperature

  samples[i] = ( 5.0 * analogRead(pin0) * 100.0) / 1024.0;
  wetsamples[i] = ( 5.0 * analogRead(pin1) * 100.0) / 1024.0;
  tempF = tempF + samples[i];
  wetF = wetF + wetsamples[i];
  delay(100);

}

tempF = tempF/8.0; // better precision
wetF = wetF/8.0;

tempC = (tempF - 32.0)/ 1.8 ; // converts to celsius
wetC = (wetF - 32)/ 1.8 ; //converts to celsius

//follows up code to calculate humidity from 2 temp sensor and wet bumb method. Air presure preset to 1013 .
etemp=(17.67*tempC)/(tempC+243.50) ; //
etemp=exp(etemp); //log
etemp=6.112*etemp;
ewet=(17.67*wetC)/(wetC+243.50) ; //
ewet=exp(ewet); //log
ewet=6.112 * ewet ;
eall= ewet - ((1013.25*(tempC-wetC)) * (0.00066*(1+(0.00115*wetC))));
humidity=(eall/etemp)*100; //humidity



// cooling and heating examples
if (tempC <= 37.6) {digitalWrite(heater, HIGH);}
else {digitalWrite(heater,LOW);}
if (tempC>= 38.2 ){digitalWrite(cooler,HIGH);  }
else {digitalWrite(cooler,LOW);}




//data on LCD or serial

Serial.print(tempC);
Serial.print(" Celsius, ");
lcd.setCursor(0, 0);
lcd.print(" Celsius, ");
lcd.print(tempC);

Serial.print(wetC);
Serial.print(" wetC -> ");
lcd.setCursor(0, 1);
lcd.print(" wetC -> ");
lcd.print(wetC);

Serial.print(humidity);
Serial.print(" humidity -> ");
lcd.setCursor(0, 3);
lcd.print(" humidity -> ");
lcd.print(humidity);

tempF = 0; //reset variables
wetF=0;


}

dalai

Is it possible to see how datetime.h is made so I can manipulate it ?

Go Up