This is a proof of concept system used to automate a greenhouse consisting of one plant. While this is the case it would not be difficult to scale this project up in size. I wrote this code for a class project for my intro to computer architecture course. This is written for the mbed platform but can easily be ported to the Arduino using a few modifications.
There are two sensors connected to analog inputs that the microcontroller is constantly checking to see if they fall below or above certian thresholds. The two sensors I use are a TMP36 sensor for monitoring the temperature of the system and a soil moisture sensor to moniture the moisture of the soil. The if the temperature gets too cold, the microcontroller will turn on two 60 watt light bulbs to produce heat. The way I achieved this was using a relay rated for 220v, since the lightbulbs run on 120v (http://www.onallcylinders.com/2015/01/02/relay-case-whys-hows-using-relays-automotive-wiring/). Please note to use precaution when working with high voltage. If the temperature gets too cold, the system turns on a 12v fan using an h-bridge. Note that the fan can be connected in any configuration and you can use either input to the h-bridge (https://en.wikipedia.org/wiki/H_bridge). If the moisture content falls below a defined threshold, a 12v water pump will turn on for a short period of time. Note, unlike the fan, the pump must be wired so positive goes to positive and ground goes to ground otherwise the pump will not work.
Additionally you can use four buttons to manual enable all of these devices. The first button is used to toggle the manual state, while the other three are for the fan, lights, and pump. Note that when the manual mode is enabled, the microcontroller will not turn on the devices based on the enviromental conditions.
The polling time and all of the thresholds for the devices can be changed using the command line interface using a serial connection.
While the project works, many improvements can be made. First of all, the fan I used for this system is way too small. I accidently order a 30mm by 30mm fan which essentially does nothing. Second, adding a real time clock and data logging would be a useful feature. While I did have a SD card reader, my lack of a real time clock made useful data logging difficult. Additionally, one could design a lux meter, using a photoresister. To do this you need an actual lux meter and a multimeter. Then in various, lighting conditions you can measure the lux and the resistance accross the photoresister. You can then fit the data points you get with an exponential curve. Lastly, a worthwhile improvement to make would be scheduling regular waterings using the real time clock.