Hello I have a problem with my automatic greenhouse
I have 1 fan and heater, but I can not make it work alternately as when the air temperature and the air turns reaches an average temperature begins to cool and turn the heater on but the air does not go this is the code
float temp;
int tempPin = 0;
int Aire = 8;
int Calenton = 7 ;
int airePin = 12;
int aguaPin = 4;
const int tempReferencia = 18;
void setup(){
pinMode(airePin, OUTPUT); // Bomba Agua
pinMode(aguaPin, OUTPUT); // Bomba Aire
pinMode(Aire,OUTPUT); //Aire
pinMode(Calenton,OUTPUT); //Agua
Serial.begin (9600);
}
I have a temperature sensor LM35 makes reading the temperature and it works under the fan or the heater space heater running at 15 degrees Celsius temperature and when it reaches 18 degrees Celsius stops the calenton j when the temperature begins to increase and reaches 20 degrees Celsius the fan turns on to lower the temperature
what I want is that 15 to 20 Celsius not turn any actuator that is what I can do in that case you appreciate that I could help with the programming I'm new at this
I think the +3 and -3 is meant to implement hysteresis, but you've got the logic back to front.
I think something like this would make more sense:
if(temp > tempReferencia +3)
{
// much too hot, apply cooling and turn off heating
}
else if(temp > tempReferencia)
{
// a little too hot, turn off heating
}
else if(temp > tempReferencia-3)
{
// a little too cold, turn off cooling
}
else
{
// much too cold, start heating and turn off cooling
}