Greenhouse Hardware Controller

    Since I seem to have less and less time to visit my parents and check on my aquaponics system I wanted to automate some things so that I could remote into my greenhouse and check on the aquaponics system. Using an old desktop PC I rebuilt a computer system into a Tupperware box that could control humidity, temperature, and water level sensors. Using these sensors I developed code to control fans, the water heater, and an auto-feeder. 

    Through serial communication with an Arduino micro-controller I can control all my sensors and hardware, such as my fans and water heater. Using this $6 waterproof container from Home Depot I built this control box to contain my simple control circuit. 

Had to dremel away part of the top to allow the 4-channel relay to sit flush.
At the top left is the 4-channel relay, bottom left is the hp-webcam, top right is an Arduino uno, bottom right is a breadboard with simple circuit for the sensors.
Closed and wrapped up to avoid being a cat toy.

  

    This Arduino is setup to control a 4-Channel relay, read the temperature from 4 different thermisors, control a servo used for moving an auger in my auto-feeder, and lastly for reading data from a DHT11 (humidity and temperature) sensor. I left plenty of wires through the case for future upgrades if needed and each wire hole was just sealed up with some hot glue. 

Added wires to control a servo for my auto-feeder and added some spares in case I needed them for a future component.
Most recent picture of how everything in the inside is setup.

 

    The 4-channel relay allows me to control the activation of a switch on a separate circuit from the Arduino. This allows easy control of my 12v fans, my 120vac box fan, and water heater. 

Here is a video of the fan control being tested:

    My code was initially setup to read the humidity value from the DHT11 sensor and if it was above 75% relative humidity it would activate the solenoid in the 4-channel relay to switch 'on' the fans. This seemed to work well enough to at least keep water from sitting on the leaves of the plants and to dry areas of the rocks that would otherwise sprout algae. It was very difficult to actually reduce the humidity of the air because there is really no where for the air to go so it just re-circulates around inside the greenhouse. Using the DHT11 sensor I was able to find a dew point temperature so a future project is to make a condensing unit to recycle some of that water and reduce the humidity. A very primitive idea was to run a PVC tube outside the greenhouse that I could circulate air through with long bolts running through the PVC. The bolts would theoretically act as heat sinks that could condense some water out of the greenhouse air, though I doubt it would be substantial and I haven't done any calculations. 

    

    And here is a picture of its output in the serial monitor built into the Arduino IDE:

  

And here is the code that I used to visually display the temperature and humidity values:

 

/* 

______________________________________________________________________________________________ Relay 4 is pin 10 red/white Relay 1 is pin 11 blue/white Relay 2 is pin 12 green/white Relay 3 is pin 9 yellow/white  Yellow/white is temp 2 on a1 Green/black is temp 1 on a0 Blue is temp 3 on a2 Temp 4 is the dht11 sensor _____________________________________________________________________________________________  * Inputs ADC Value from Thermistor and outputs  *            Temperature in Celsius * *  requires: include <math.h> * *Utilizes the Steinhart-Hart Thermistor Equation: *    Temperature in Kelvin = 1 / {A + B[ln(R)] + C[ln(R)]3} *    where A = 0.001129148, B = 0.000234125 and C = 8.76741E-08 * * These coefficients seem to work fairly universally, which  is a bit of a surprise.  * * Schematic: *   [Ground] -- [10k-pad-resistor] -- | -- [thermistor] --[Vcc (5 or 3.3v)] *                                     | *                                Analog Pin 0 * * In case it isn't obvious (as it wasn't to me until I thought about it), the analog ports measure the voltage

     between 0v -> Vc c which for an Arduino is a nominal 5v, but for (say) a JeeNode, is a nominal 3.3v. * * The resistance calculation uses the ratio of the two resistors, so the voltage specified above is really only required for 

    the  debugging that  is commented out below * * Resistance = (1024 * PadResistance/ADC) - PadResistor  * *//******************************************************************************************* */

/******************************************************************************************* */

/******************************************************************************************* */

#include <math.h>#define ThermistorPIN0 0                 // Analog Pin 0#define ThermistorPIN1 1#define ThermistorPIN2 2#define ThermistorPIN3 3float vcc = 4.91; // only used for display purposes, if used set to the measured Vcc.

float pad = 9850; // balance/pad resistor value, set this to the measured resistance of  your pad resistor

float thermr = 10000;        //thermistor nominal resistance/******************************************************************************************* */

/******************************************************************************************* */

/******************************************************************************************* */

#include <DHT11.h> //library found online, only slightly modifiedint DHT11pin = 2; //Digital pin for comunicationsint DHT11intNumber = 0; //Interupt #vo dht11_wrapper();   // must be declared before the library initialization

DHT11 DHT11(DHT11pin,DHT11intNumber,dht11_wrapper);  // Library instantiate

/******************************************************************************************* */

/******************************************************************************************* */

/******************************************************************************************* */   float Thermistor(int RawADC) {   long Resistance;     float Temp;  // Dual-Purpose variable to save space.    Resistance=((1024 * pad / RawADC) - pad);    Temp = log(Resistance); // Saving the Log(resistance)    Temp = 1 / (0.001129148 + (0.000234125 * Temp)                  + (0.0000000876741 * Temp * Temp * Temp));   Temp = Temp - 273.15;  // Convert Kelvin to Celsius                          //temp = (Temp * 9.0)/ 5.0 + 32.0;         // Convert to F   return Temp;                     // Return the Temperature}

/******************************************************************************************* */

/******************************************************************************************* */

/******************************************************************************************* */

vo setup() {   Serial.begin(9600);}/******************************************************************************************* *//******************************************************************************************* */

/******************************************************************************************* */

// This wrapper is in charge of calling vo dht11_wrapper() {   // must be defined like this for the library to work   DHT11.isrCallback();}/******************************************************************************************* */

/******************************************************************************************* */

/******************************************************************************************* */

vo loop() {   float temp0;   temp0=Thermistor(analogRead(ThermistorPIN0));       // read ADC and  convert it to Celsius      float temp1;   temp1=Thermistor(analogRead(ThermistorPIN1));       float temp2;   temp2=Thermistor(analogRead(ThermistorPIN2));       float temp3;   temp3=Thermistor(analogRead(ThermistorPIN3));    /******************************************************************************************* */

DHT11.acquire();   while (DHT11.acquiring())     ;   int result = DHT11.getStatus();   switch (result)   {   case DHTLIB_OK:      //Serial.println("OK");      break;   case DHTLIB_ERROR_CHECKSUM:      Serial.println("Error\n\r\tChecksum error");      break;   case DHTLIB_ERROR_ISR_TIMEOUT:      Serial.println("Error\n\r\tISR Time out error");      break;   case DHTLIB_ERROR_RESPONSE_TIMEOUT:      Serial.println("Error\n\r\tResponse time out error");      break;   case DHTLIB_ERROR_DATA_TIMEOUT:      Serial.println("Error\n\r\tData time out error");      break;   case DHTLIB_ERROR_ACQUIRING:      Serial.println("Error\n\r\tAcquiring");      break;   case DHTLIB_ERROR_DELTA:      Serial.println("Error\n\r\tDelta time to small");      break;   case DHTLIB_ERROR_NOTSTARTED:      Serial.println("Error\n\r\tNot started");      break;   default:      Serial.println("Unknown error");      break;   }/******************************************************************************************* */

/******************************************************************************************* */

/******************************************************************************************* */

//print temperatures here   delay(500);   Serial.print("|==-==-==-==-==-==-==-==-==-==-==-==|");   Serial.println("");   Serial.println("");//print first temp, convert to Fahrenheit   temp0 = (temp0 * 9.0)/ 5.0 + 32.0;                     Serial.print("Temperature: ");    Serial.print(temp0,1);                               //print second temp, convert to Fahrenheit   temp1 = (temp1 * 9.0)/ 5.0 + 32.0;      Serial.print("  ");    Serial.print(temp1,1);                             //print third temp, convert to Fahrenheit    temp2 = (temp2 * 9.0)/ 5.0 + 32.0;      Serial.print("  ");    Serial.print(temp2,1);                              //print fourth temp actually found from DHT11 sensor   Serial.print("  ");   Serial.print(DHT11.getFahrenheit(), 2);   Serial.println("");//print humity   Serial.print("Humity: ");   Serial.print(DHT11.getHumity(), 2);    Serial.println(" %");//print dew point    Serial.print("Dew Point: ");    Serial.println(DHT11.getDewPointSlowF());   Serial.println("");    delay(500);                                         /******************************************************************************************* */

/******************************************************************************************* */

/******************************************************************************************* */  

}