HELP grenhouse problem

Hi guys,

I’m doing a small greenhouse with arduino. I want the cover is closed depending on the temperature. I use a sensor TPM36, I also used a motor shield and a TinkerKit LCD module. I want the cover is closed if the temperature exceeds a value, and open if less of that value, but I also want to stop the engine by reaching a limit.

I don’t know how to properly connect the limit switches. When I connect the LCD gives problems. Besides the LCD doesn’t perform properly.

Any ideas?

#include <matrix_lcd_commands.h>
#include <TKLCD.h>
#include <LiquidCrystal.h>
#include <Wire.h>
//LiquidCrystal lcd(14,11,5,4,3,2);


const int buttonPinAbierto = 2;
const int buttonPinCerrado = 3;
float temperatura = 0; 
int motorPin=12; 
int buttonStateAbierto=0;
int buttonStateCerrado=0;

void setup(){
 Serial.begin (9600); 
 //lcd.begin(16,2);
 Serial.println (temperatura);
 
 pinMode(12,OUTPUT); //Iniciar Motor  (salida)
 pinMode(9,OUTPUT);
 pinMode(buttonPinAbierto, INPUT);
 pinMode(buttonPinCerrado, INPUT);  
}
 
void loop(){
  
  
  temperatura = (5.0 * analogRead(0)*100.0)/1023.0;
  
  Serial.println (temperatura); 
  delay (3000);

  
  buttonStateAbierto=digitalRead(buttonStateAbierto);
  buttonStateCerrado=digitalRead(buttonStateCerrado);
  
  /
   if ((temperatura > 26)&&(buttonStateAbierto==HIGH))
     digitalWrite(12,HIGH); 
     digitalWrite(9, LOW); 
     analogWrite(3,255); 

     delay (5000); 
     digitalWrite(9, HIGH); 
  }

    
  if ((temperatura <= 22)&&(buttonStateCerrado==HIGH))
     digitalWrite(12,LOW); 
     digitalWrite(9, LOW); 
     analogWrite(3,255); 

     delay (5000); 
     digitalWrite(9, HIGH); 
  }
  }

(deleted)

Ok, that's wrong. I put the pins of example. But they are obviously wrong.
analogWrite (3,255); It is for engine speed in the shield

I want the cover to move depending on the temperature but I also want that the engine stops at touch a limit switch. I don't know if the sketch is well