Greenhouse automation

Hi all!

I’ve got a project that I’m working on and wondered if the people of this forum could shed some light.

I basically want to open the vent on a greenhouse if the temperature reaches a set point. This will drive a bi directional motor. There will be two limit switches to ensure that the vent is completly open.

When the temperature drops back below another set point I would like the motor to drive in the opposite direction closing the vent untill both limit switches are in the oppose state.

I’ve attached a basic schematic of the system. Any help, guidance or information would be greatly apreciated.

can be done relative easily

a starter how to set things up, some functions are incomplete that need still to be re written. (check tutorial section)

int highLimit = 25;
int lowLimit = 23;

int switchTop = 4;  // pin
int switchBottom = 5; // pin

void setup()
{
  Serial.begin(115200);   // for some feedback
  Serial.println("greenhouse 0.1");
}

void loop()
{
  int val = getTemperature();

  if (val > highLimit ) 
  {
    do
    {
      motorUP(1); // run motor for one second
    }
    while ( digitalRead(switchTop) == LOW);
  }

  if (val < lowLimit)
  {
    do
    {
      motorDown(1); // run motor down for one second
    }
    while ( digitalRead(switchBottom) == LOW);  // assume HIGH when at the end
  }
}

int getTemperature()
{
  return 10;
}

void motorUP(int t)
{
   delay(t*1000UL);
}

void motorDown(int t)
{
   delay(t*1000UL);
}

Thats brilliant. Thanks very much.

All of that can be done with an Uno board?

easily.

take care that the motor(s) need a separate power supply (connect GNDs for common reference)
and the motors need a diode against induction…

Yeah cheers. Pretty apt with the electronics. Im an instrumentation technician by trade and did an electrical/electronic apprenticeship.

For testing purposes could I not just get a small voltage DC motor that can be supplied via the Arduino?

Hi all. Just thought I would give a quick update on this project.

I have myself an Uno and a few components. For the temperature sensor I decided to go with a AD22100STZ. Its quite user friendly, it does all the linearisation on the chip so all I have to use is an equation given by the manufacturer on the data-sheet. I get about 0.2 DegC sensitivity due to the -50 to 150 and 10bit ADC ranges. I have here a quite precise stand alone temperature probe that I am going to carry out some comparison tests with which I will post when I have the results. I may be able to tweak the equation to get better accuracy.

The code is coming along nicely with some variable integer and floats. I am communicating and printing through the serial port. I have some if statements based on my required temperature setpoints which are currently just controlling a digital output which I will soon change to a PWM output to my servomotor which I just need to sort a power supply out for.

//temperature readout code

int outputpin = 13;
int inputpin = 1;
int inputmemory = 0; //use for the serial read
float tempout = 0;  //use for temperature out
float setpointhigh = 26.00; //high temperature setpoint
float setpointlow = 25.00; //low temperature setpoint

void setup()
{
  Serial.begin(9600);
  pinMode(outputpin, OUTPUT);
}

void loop()

{
  inputmemory = analogRead(inputpin); //read analogue pin on pin 1
  
  tempout = ((inputmemory*(5.0 / 1024))- 1.375) / 0.0225;
  
  Serial.print ("Temperature: ");
  Serial.println(tempout); //print temperature value to serial
 
  Serial.print ("ADC value: ");
  Serial.println(inputmemory); //print ADC value to serial
  
  if (tempout >= setpointhigh) digitalWrite(outputpin, HIGH); //high setpoint
  
  if (tempout <= setpointlow) digitalWrite(outputpin, LOW); //low setpoint
  
  delay(1000); //delay 1 second before next read

}

The forum is rubbish for uploading pictures so I will also be doing a blog over at http://partecsolutions.blogspot.co.uk/ if you want to check that out.

Any constructive criticism would be cool so just drop a message on here!

Looking for some advice.

I’m using a standard mechanical limit switch. When the switches state is changed I have it written into the code that a servomotor is stopped. I’m finding that there is too much delay between the limit switch being pressed and the stopping of the motor.

Would this be down to potentially the bouncing of the switch or is it because I have a lack of an interrupt in the code.

Here is the code (I also understand that the code isn’t completely ‘proper’ so any pointers on this would also be a help):

//temperature readout code
#include <Servo.h> // Servo library

Servo windowservo; //name of servo
int outputpin = 13;
int inputpin = 1;
int inputmemory = 0; //use for the serial read
float tempout = 0;  //use for temperature out
float setpointhigh = 23.00; //high temperature setpoint
float setpointlow = 22.00; //low temperature setpoint
int limitswitchpin = 2; //pin for limit switch
int limitswitchvalue = 0; //value for limit switch

void setup()
{
  Serial.begin(9600);
  pinMode(outputpin, OUTPUT);
  pinMode(limitswitchpin, INPUT);
  windowservo.attach(3);
  windowservo.write(90);
}

void loop()

{
  inputmemory = analogRead(inputpin); //read analogue pin on pin 1
  
  tempout = ((inputmemory*(5.0 / 1024))- 1.375) / 0.0225; //temperature calculation given from data sheet
  
  limitswitchvalue = digitalRead(limitswitchpin);
  
  Serial.print ("Limitswitch: ");
  Serial.println(limitswitchvalue); //print limit switch value
  
  Serial.print ("Temperature: ");
  Serial.println(tempout); //print temperature value to serial
 
  Serial.print ("ADC value: ");
  Serial.println(inputmemory); //print ADC value to serial
  
  if (tempout >= setpointhigh && limitswitchvalue == 0) windowservo.write(94); //high setpoint
  
  if (tempout >= setpointhigh && limitswitchvalue == 1) windowservo.write(90); //high setpoint reaching limit switch
  
  if (tempout <= setpointlow) windowservo.write(86); //low setpoint
  
  if (tempout > setpointlow && tempout < setpointhigh) windowservo.write (90); //stop servo if between set points

delay (500);

}

Here's your problem:

delay (500);

Get rid of it. Now, only your serial output will slow things down - try increasing the baud rate.

Thanks. I did briefly get rid of the delay at the end of the program but it seemed to make the servomotor respond sporadically. Ill remove it again and have a go at increasing the baud rate. Thanks again

Just removed the delay and it works much better. If I change the serial speed from 9600 the serial monitor through the arduino software prints back a load of jargon:

~vetת¡««µ b½Äv×è±%!éjÑíz?

Any help for the reason for this?

You need to change the speed on the IDE's serial monitor too.

You should think of adding hysterisis for your temperature sensors. Because near the limit of the temperature your vent could open/close, all the time.