I need help with millis

Hi,

I have problem with my thermostat. I just have bought arduino, and im not so good with codes (yet) so i am asking for little help here for it. Okay, so problem is this: My led (for example) should go on when temp is over 40 celsius, and should be on for next 15 minutes, unless temperature goes under 30 celsius. so i have to do that with millis, becouse arduino need to calculate temperature all the time, oh and yes, i use LM35 temperature sensor. I hope my bad english isn't problem, and thanks if someone can help!

#include <LiquidCrystal.h> //LCD näytön kirjasto
int reading = 0;
int sensorPin = A0; //LM35 sensorin pinni
int rele =8; //Pinni, joka ohjaa fettiä, joka taas puolestansa ohjaa relettä
int led1 =9; //Ledi palaa: puhallin on päällä
int led2 =10; //Ledi palaa: Puhallin ei ole päällä

LiquidCrystal lcd(7, 6, 5, 4, 3, 2); //LCD näytön ohjauspinnit
 
void setup() {
	
	lcd.begin(16, 2); //LCD:n Rivien ja merkkien määrät
	pinMode(rele,OUTPUT); //määrittää pinnin outputiksi
        pinMode(led1, OUTPUT); //määrittää pinnin outputiksi
        pinMode(led2, OUTPUT); //määrittää pinnin outputiksi
}
 
void loop() {
	reading = analogRead(sensorPin);
	int celsius = reading/2;
	lcd.setCursor(0, 0);
	lcd.print("L");
        lcd.write(0b11100001);
        lcd.print("mp");
        lcd.write(0b11101111);
        lcd.print("tila: ");	
	
	lcd.print(celsius, DEC);
	lcd.print((char)223);
	lcd.print("C   ");
        lcd.setCursor(0, 1);
        lcd.print("Puhallin: ");
        lcd.setCursor(10, 1);
	if (celsius >26) 
{

   ON();           
		
}
else 
{

  OFF();
	
}
	delay(500);
	lcd.clear();
}



void ON()
{
                digitalWrite(rele,HIGH);
                digitalWrite(led1,LOW);
                digitalWrite(led2, HIGH);
                lcd.print("Pois");
}

void OFF()
{		
                digitalWrite(rele,LOW);
                digitalWrite(led1,HIGH);
                digitalWrite(led2,LOW);
                lcd.print("P");
                lcd.write(0b11100001);
                lcd.write(0b11100001);
                lcd.print("ll");
                lcd.write(0b11100001);
}

The demo several things at a time shows how to use millis() to manage time.

I suggest you make a short program without any LCD stuff to explore the use of the timing. And reduce the time intervals to a few seconds while you are exploring. When you can manage the time as you want you can add in the LCD stuff.

The Thread planning and implementing a program may have some useful ideas.

...R

Sounds like you are in the same class as:
http://forum.arduino.cc/index.php?topic=278415.0