Hi!
I'm new, so I'll be sorry for any mistake I'll do.
I'm working on a lamp that has to turn on when there's no sun light (I used a LDR).
But after an hour the lamp begin hot and I need to turn off the lamp because it's made of paper.
So I used a Thermoresistor.
I did the sketch, but I don't know how to turn off the bulb for 10 minutes if the temperature arrives at 50 degrees. I only know how to turn off the bulb at 50 degrees, but as soon as arrived at 49° it will be on. And after a moment off....all so.
I want to let it go till a low temperature when it arrives to 50°.
This is the sketch I'd like to correct:
int LDRPin = 0; //LDR's pin
int TempPin = 4; //Thermoresistor's pin
int interruttore = 3; //relay's pin
int base;
int soglia = 100; //max light
int soglia1 = 50; //max heat
void setup() {
Serial.begin (115200);
pinMode (LDRPin, INPUT);
pinMode (interruttore, OUTPUT);
base = analogRead(LDRPin);
}
//float volts()
//{
// float raw = analogRead(ImPin);
// float percent = raw/1023.0;
// float volts = percent*5.0;
// return volts;
//}
float tempC()
{
float raw = analogRead (TempPin);
float percent = raw/1023.0;
float volts = percent*5.0;
return 100.0*(volts-0.5);
}
void loop() {
int v = analogRead(LDRPin);
Serial.print("TEMPERATURE");
Serial.print(tempC());
Serial.print(" \260C; ");
Serial.println();
if ((base - v) < soglia && (tempC() < soglia1)) {
digitalWrite(interruttore, HIGH);
} else {
digitalWrite(interruttore, LOW);
}
}
Can you help me? Thanks a lot.
Riccardo