# Problem Whit Greenhouse Help!!

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);
}

void loop(){

temp = temp * 0.48828125;
Serial.print(“TEMPRATURE = “);
Serial.print(temp);
Serial.print(”*C”);
Serial.println();
delay(1000);

if (temp <= tempReferencia +3){
digitalWrite(Aire, LOW);
}else if(temp >= tempReferencia-3){
digitalWrite(Aire, HIGH);
}
if (temp >= tempReferencia -3){
digitalWrite(Calenton, LOW);
}else if(temp <= tempReferencia +3){
digitalWrite(Calenton,HIGH);
}
if (temp == tempReferencia){
digitalWrite(Aire, LOW);
digitalWrite(Calenton, LOW);
}
}

describe: HOW is it ment to work?

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

…I’m afraid I din’t understand that…
…and this:

``````if (temp <= tempReferencia +3){
digitalWrite(Aire, LOW);
}else if(temp >= tempReferencia-3){
digitalWrite(Aire, HIGH);
``````

in words: if temp less than 21 → turn fan off
and… if temp more than 15 → turn on
…look at your logic… Something here may not be right

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

Hablas espanol ?

asi es bro que paso?

``````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);
}

void loop(){

temp = temp * 0.48828125;
Serial.print("TEMPRATURE = ");
Serial.print(temp);
Serial.print("*C");
Serial.println();
delay(1000);

if (temp <= tempReferencia +3){
digitalWrite(Aire, LOW);
}else if(temp >= tempReferencia-3){
digitalWrite(Aire, HIGH);
}
if (temp >= tempReferencia -3){
digitalWrite(Calenton, LOW);
}else if(temp <= tempReferencia +3){
digitalWrite(Calenton,HIGH);
}
if (temp == tempReferencia){
digitalWrite(Aire, LOW);
digitalWrite(Calenton, LOW);
}
}
``````

Cuando pontes tu codico en la forum, por favor, usas la tecla “#” para crear uno vendana como asi.
Necitamos uno schematica de tu circuito.

este es el esquema

For everyone else : Corriente = power tierra =ground senal=signal

Donde compraste las circuitos relay ? Necitamos la pagina donde los compraste para las detaillas. (datasheet /pinout)

Is this closer?

``````float temp;
int tempPin = 0;
int Aire = 8;
int Calenton = 7 ;
int airePin = 12;
int aguaPin = 4;
const int tempReferencia = 18;
#define upper 20
#define lower 15
void setup(){
pinMode(airePin, OUTPUT); // Bomba Agua
pinMode(aguaPin, OUTPUT); // Bomba Aire
pinMode(Aire,OUTPUT); //Aire
pinMode(Calenton,OUTPUT); //Agua
Serial.begin (9600);
}

void loop(){

temp = temp * 0.48828125;
Serial.print("TEMPRATURE = ");
Serial.print(temp);
Serial.print("*C");
Serial.println();
delay(1000);

if (temp >= upper)   digitalWrite(Aire,1) ;  else  digitalWrite(Aire,0);
if (temp <= lower)   digitalWrite(Calenton, 1); else  digitalWrite(Calenton,0);
//OR
digitalWrite(Aire,temp>=upper);
digitalWrite(Calenton,temp<=lower);
}
``````

Is CALENTON a heater ? Is that the brand name ?

Es calenton un calentador? Es que el nombre de la marca?

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
}
``````

raschemmel:
Hablas espanol ?

gosh, for a moment I was thinking you were hijacking this thread by asking a whole different question

ha ha. No , the OP speaks spanish.