I am now using a TMP36 on my solar furnace to close the flap with no sun.. and I have it so it closes! Now I just need help to loop it to start over when the sun comes out again... sketch so far:
...begin sketch...
float tempC; // create variable to store the temperature in.
int tempPin = 0; // Attach vout to analog pin 0.
int fan1 = 5; // attach base of transistor to digital pin 5.
void setup() // Will execute once at the start of the code.
{
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
pinMode (fan1, OUTPUT); // sets the fan1 pin 5 up as an output.
}
void loop() // code here will continue to replay until powered off.
{
tempC = analogRead(tempPin); // read the analog value from the lm35 sensor.
tempC = (5.0 * tempC * 100.0)/1024.0; // convert the analog input to temperature in centigrade.
Serial.print((byte)tempC); // send the data to the computer.
if (tempC < 69) // creates bool expression for analyzation. if it evaluates to true,
{ // the body of the if statement will execute.
digitalWrite (fan1, HIGH); // turns on fan1.
delay(1000);
digitalWrite (fan1, LOW); // turns off fan1.
}
else // if the if equation evaluates to false the else statement will execute.
{
digitalWrite (fan1, LOW); // turns off fan1.
}
}
....end of sketch....
I am assuming now I have to use a... if (tempC > 69) loop to start it all over, but don't know how to do it.
wildatnite:
I am assuming now I have to use a... if (tempC > 69) loop to start it all over, but don't know how to do it.
The "else" part of the "if else" takes care of whatever doesn't satisfy the "if (tempC < 69)" criteria.
After all, that's probably the main reason "if else" is called what it's called.
One question, though. Why is your "flap" called "fan"?
Also, you should realize that once the tempC gets below 69, the code will probably execute the
digitalWrite (fan1, HIGH); // turns on fan1.[color=#222222][/color]
delay(1000);[color=#222222][/color]
digitalWrite (fan1, LOW); // turns off fan1.
part multiple times. If it really is a flap and not a fan (and has a restricted movement range), the motor that opens and closes the flap will try to close the flap even if it is already closed.
You should put in a flag (a variable that stores the state of the flap) and close the flap only when it is opened.
Shpaget:
The "else" part of the "if else" takes care of whatever doesn't satisfy the "if (tempC < 69)" criteria.
After all, that's probably the main reason "if else" is called what it's called.
One question, though. Why is your "flap" called "fan"?
Also, you should realize that once the tempC gets below 69, the code will probably execute the
digitalWrite (fan1, HIGH); // turns on fan1.[color=#222222][/color]
delay(1000);
digitalWrite (fan1, LOW); // turns off fan1.
part multiple times. If it really is a flap and not a fan (and has a restricted movement range), the motor that opens and closes the flap will try to close the flap even if it is already closed.
You should put in a flag (a variable that stores the state of the flap) and close the flap only when it is opened.
Yes, thats the thing, I don't want it to repeat until it gets opened again, otherwise it will burn out the motor, hence the "> 69" part of the equation. I copied the script from something else and didn't change "fan" to "flap" smile..