Greenhouse Automation Project

This project was originally done for my mechatronics class. The original documentation can be found at UCO’s Department of Engineering Wiki Site. I changed a few things from what is presently on the wiki and what you see below (mainly just contact information since I have graduated from UCO).

Greenhouse Automation and Relay Device for Expansionary Nodal Systems (G.A.R.D.E.N.S.) was developed by my friend, and teammate, Willy and myself. The goal of this project is to develop a system which can monitor greenhouse conditions and act accordingly. This, used in conjunction with typical greenhouse upkeep by the user, will help improve plant performance and encourage users to produce their own consumable food products. This system is also designed to aid the handicap in caring for their plants. There are several “key” parts of the system:

G.R.O.W. (Greenhouse Robustness and Operations Workstation)

  • Main interface device for the user to program the “zones” (more below)
  • Graphic LCD screen also displays current conditions along with any troubleshooting information
  • Speaker lets the users know if a function was successful or a failure
  • Front panel of the system is smooth, to allow easy cleaning of the keypad and screen
  • Provides power to the rest of the “zones”
  • Can be removed and taken into the house to be plugged into the computer for easier programming

S.E.C.A.N.T (Sensor Enabled Controller and Automation Node Transceiver)

  • Utilizes different sensors to observe the conditions within the greenhouse and activate the appropriate controllers
  • Controlled via I2C communications protocol
  • Acts as an independent unit along the chain of communication
  • Can be set to any address (via software) within the valid I2C defined address space
  • Has the ability to be taken out of the communication chain and worked on
  • Receives power from interconnect wire
  • Can only talk with the G.R.O.W. module

R.A.C. (Relay Activation Controller)

  • Houses all relays, keeping mains 120V power away from lower voltage system and limiting the possibility of dangerous electrical wiring faults
  • Used to turn on and off water valves with the possibility of expansion to HVAC and Humidifier/Dehumidifier controllers.


The development of this system was inspired by friends who grew their own vegetables in a garden, who are also tech savvy, and wanted something they could integrate into their current garden that would aid them in their plant’s production of consumable goods. The current system is not 100% complete but the pieces that are complete are 100% functional. With the limited budget and man hours only one zone was created with its water supply relay attached directly to the SECANT unit. The system was designed with the intentions of being expandable up to 127 zones. The current code that is written for the SECANT units can handle this expansion, but the code for the GROW unit will need to be slightly modified to be able to handle more than one zone.

System Schematic

Figure 5: System Schematic

Figure 5 shows the connection schematic for the single node system. The power connections were left out because it will clutter the schematic, and the boards are marked with their power pins. One important note to mention is that the two microcontrollers MUST have at least ONE common ground for the I2C link to work properly. Also, the Vcc on the microcontrollers, unlike other units used for other projects (such as BS2SX) is NOT for unregulated voltage! It must be 3.3V! If you need to power the board from a higher potential, you must use the RAW voltage input on the arudino pro mini boards, which is then fed into a 3.3V regulator on the Pro Mini. I used this method and ran 5V rail to the unit so that I could power the relay and servo from the 5V rail but run at 3.3V logic (which is compatible for transmitting from a 3.3V to a 5V system, but the servo and relay need 5 V to their power sources to operate).

The GROW unit is connected to the LCD screen via the TX serial connection on the Pro Mini. The keypad IRQ line, which is used to indicate when a pad has changed state (pressed or depressed), is connected to Digital Input 2. The SDA and SCL lines are used for I2C communications. SDA stands for Serial DAta, and SCL stands for Serial CLock. These are the lifeline of the system and connect everything together. Although the keypad is connected to the bus lines, only the GROW unit utilizes its functions. R1, R2, and R3 are acting as pull up resistors on the bus lines, since I2C is defined as an open drain protocol (and the IRQ line on the keypad operates in the same manner). The next thing we see, reading the schematic from left to right, is S1. This switch is used to put the SECANT mode into independent monitor mode. If this switch is closed and the chip is powered up, the chip will enter this mode and allow a USB connection to the FT232RL chip which converts the USB data into TTL data, for the chip to understand. Under this mode a user can troubleshoot the unit, change variables, or view the analog data from the temperature and moisture sensors. If this pin is low (which by default it is) then the chip, on power up, will run its internal program normally. Finally we get to the SECANT, where all of the processing really takes place! The SECANT is connected to a TMP36 (datasheet can be found online) analog temperature sensor, a Vegetronix moisture sensor, a relay which controls a 120V 15A socket, and a small RC servo to open and close the roof hatch (in the demonstration that I put together). The temperature sensor and moisture sensor are connected to the Analog ports 0 and 1. The Arduino pro mini has a built in analog to digital converter which can take this analog voltage input and convert it, with 10-bit resolution, to a digital signal for the microcontroller to process.

The part of this project that took the most amount of time was the code. This project could have been done on a passive level with voltage comparators to turn on and off values, but the trade off is that it would not be programmable and each unit would have to be fine tuned to its specific area and application. The GROW and SECANT are running somewhat similar codes (for the I2C bus communications) but after that point the code each of them runs is totally different. Added together there is roughly 830 lines of code! Although this is quite a lot for this process, most of the code on the GROW unit is for formatting the customized menu system and being able to handle the input from the keypad. On the SECANT unit most of the code is for the serial terminal when the unit is put into independent mode. The purpose of putting so much work into the code along is to provide for a simple user interface that would allow any kind of user, no matter what technical skill they have, to be able to operate this system. Even if the end user needed to recompile the code and reprogram the controllers, it is very simple. To program the microcontrollers all that has to be done is copying the code into the Arduino IDE software, which is free, and simply hit the program button after an FTDI cable has been attached to the headers onboard the Pro Mini PCB. The code for these units is quite extensive, and is mostly code that was custom written for this application. On the Arduino Forums website, bits of code were found about and pieced together, mainly to act as a setting or configuration process for the MPR121 chip. The original code for using the MPR121 keypad was provided by SparkFun Electronics, but I ended up using another code set (link can be found in the code comments).

Even though this project was initially developed from a tehcno savvy friend, we quickly discovered its many uses, such as someone who has special needs yet wants to be able to garden and produce food for themselves. This unit would help them accomplish this goal by assisting them in day to day upkeep of their garden. Even though this design is a closed system, there was some thought into a system which was wireless and could link several greenhouses together, making a giant mesh network of GROW and SECANTs. The GROW’s main purpose is to provide an easy interface to someone who wants to use the system. This is also why the SECANT can operate in independent mode, where a computer can directly talk to the unit, if that is deemed necessary.


This project started out as a fun learning experience, and I believe it has now evolved into a process that could be mass marketed.

Code of Ethics

This project was produced under the IEEE code of ethics. It does not pose a safety hazard to the public, their property, reputation, or employment by any means. It also was not built under any form of bribery. No discrimination took place while building this project and I also assisted my colleagues in building and developing their projects, while still maintaining honor to the IEEE code of ethics. There was no conflict of interest while developing this process. Safety was and always will be a top priority in any design I am responsible for or work on. My education of certain technological advances grew as I learned how to write code for custom menu systems, which is something I’ve wanted to learn how to do for awhile. All considerations for this project were given thought and no idea was immediately tabled from the design platform. Although there wasn’t any point during this project that I needed outside assistance, from the beginning I would have asked for help in the event that a problem arose that needed assistance. The IEEE code of ethics is extremely important to follow, not only because it helps ensure safety of the public, but also provides a positive work environment to the professional.

Steps needed to further complete the project

The GROW code needs to be modified so that when you enter the menu you are given an option to select the appropriate SECANT address (for a multi node system). This extra step would not be hard to add into the system, just a matter of putting in the LCD formatting and inserting it before a call to the original menu function! Since I coded the software to be an general as possible, you can simply call to the functions that check for keypad entry!

Full System Layout

Figure 7: Full System Layout

Also, different versions of the SECANT code would be nice to have for things like you see in Figure 7 where one of the units has a photo-sensor on board and can turn on or off the lights. Ideally you would also have a Real Time Clock (RTC) inside the GROW unit so you could tell the system when to not activate during certain time periods. I would also want this project to be certified by ETL or some other major certification body before heading to market, mainly to provide assurance that this project can withstand conditions that might cause a failure and personal injury.

So you want to replicate this project, huh?

I am happy that I got you interested! Make sure to read ALL of the information on this page, along with taking a look at all the figures on this page.

Parts Cost and Budget

Figure 6: Parts Cost and Budget

Figure 6 shows the budgets costs, which also can be used as the Bill Of Materials list. Here I will go over this to help clarify any questions you might have…

  1. First on the list is the temperature sensor. This sensor has an analog output which is fed directly into the Pro Mini analog input pin. I talk more about this sensor on the GARDENS Code page.
  2. Serial Graphic LCD from Sparkfun is used to show the user a custom menu. I picked the serial LCD because it only requires a single data connection from the Pro Mini, and its much simpler to program for using the Serial Graphic Library I found (which you can also look into by looking at the comments on the SECANT code)
  3. Obliviously we have the Arduino Pro Minis
  4. The MPR121 capacitive touch keypad was chosen because we initially had an idea to make a front panel (which we never go to) that would be completely smooth, with the keypad and LCD recessed on the other side. The only way would would be able to get a keypad to work like this was it had to be capacitive touch.
  5. The Relay control PCB and Assorted Parts came from Sparkfun as a kit. I built this up and then integrated it with the GFCI outlet that I purchased at Home Depot.
  6. The extension cord was cut up about 5 minutes after I bought it so I could wire the GFCI outlet through the Relay board and finally to a 120V 15A wall socket (its always fun to play with wall voltage… SAFELY!)
  7. The pond pump was just to throw into the buckets of water, as seen in Figure 7
  8. Although I put a 9V 1A power supply I found this wasn’t enough for the circuit, so last minute I found a 12V 2A power supply lying around and used it instead. (Didn’t have enough time to update the budget, but I know I would still be under)
  9. The FTDI Friend and USB cable, both from Adafruit, are used to program the Pro Minis. I really REALLY like the FTDI friend because it allowed me to change the Vcc pin to 3.3V instead of the FTDI cables that you can purchase that, as I found out the hard way, have 5V on the Vcc pin EVEN THOUGH its a 3.3V logic level cable (who had THAT smart idea?!?)
  10. The Micro Servo was put into the red box (one of Sparkfun’s boxes) to simulate the roof hatch
  11. Various other components, like the wires, pull up resistors, etc!
  12. The Vegetronix Moisture probe I talk more about on the GARDENS Code page
  13. The Adjustable breadboard power supply takes the 12V 2A down to a 5V that I can pass into the RAW port of the Pro Minis
  14. Finally we have the full sized and tiny breadboards that everything was stuck onto.



We had originally planned on not posting our code. We saw the potential of this project, and had thought of possibly taking it another step further and eventually attempting to market it. This idea stuck with us for most of the semester, but finally we decided on posting the code. This code was developed from open source code, along with our own written code, and we believe that its our duty to give back to the open source community.

GROW Code Flowchart

Figure 2: GROW Code Flowchart

SECANT code Flowchart

Figure 3: SECANT code Flowchart

I2C Communication Code Flowchart

Figure 4: I2C Communication Code Flowchart

Figures 2,3, and 4 show the flowcharts of this code and how they interact with each other. Its written for the Arduino Pro Mini and therefore is intended for the Arduino IDE to compile.




If you plan on replicating this system, when you program the GROW, you MUST disconnect the LCD communication line. Since the Arduino software utilizes its bootloader to allow programming via the UART port, which is also used to connect to the LCD, and since the LCD serial backpack has a microcontroller on it, if you program the board while the LCD is still connected there is a chance (from my experience around 70%) that you will somehow put the serial backpack chip into a state that you cannot recover it from via its serial port, and will require you to use an ICSP (in circuit serial programmer) to reprogram its firmware!!! IN THE EVENT THAT THIS HAPPENS I would suggest either looking at the link where I got my firmware, or going to Sparkfun’s website and finding their original firmware for the unit and use AVRDUDE (free, of course!) to reprogram it! I’ve used and tested a STK500v2 ICSP from sparkfun ( ) to do this, and its also handy to have around in the event that you mess up one of the Pro Minis and need to reburn its bootloader (which I have also done in testing the code!).



I received the Vegetronix moisture sensor the night before I needed to present this project to our class. Since that didn’t leave me any time to do the calibration, and I was determined to utilize this sensor in my project, I decided to not perform a calibration on the sensor like Vegetronix recommends, and instead assume a linear voltage response to the moisture level (which a graph on their website shows the response and its some what linear). Doing this allowed me to quickly put the compensator code into the SECANT code which converts the ADC reading into a value that represents the percent of the moisture level in the soil. I did this by first taking a voltage reading of the senor in air, which read around 5mV, then dunked the sensor in a cup of water, fully submerged, and got a reading of around 2.723V. Taking the slope of that line gave me the percentage per V, which was about 36.724%. Then, using dimensional analysis, and knowing the ADC on the Pro Mini was 10-bit resolution (1024 bits for total voltage range) I was able to finally get down to percentage per read bit, which came out to be 0.11834%/bit. Having his compensator number, I then simply multiplied the reading of the analog port which the sensor was connected to by 0.11834 and that would give me the representation of the percentage of moisture around the sensor. If I had more time I would go back and do a full calibration so that I could get a much more accurate reading, but for purposes of demonstration, this worked for me.

The TMP36 was given to me by our awesome lab tech, Richard. I included the price in my budget for one, even though it wasn’t actually purchased. I utilized Ladyada’s (Limor Fried) tutorial on this sensor in order to implement it on my design (


The files are .c extensions because the code was actually written in the EditPad Pro software. I HIGHLY suggest you use this software (there is a free trial, which is what we use) because it will break down each function and also color code the syntax (the arduino IDE does this too, but the EditPad Pro does a much better job). If you don’t want to bother with EditPad Pro, open the files in a text editor (e.g. Notepad in Windows) and then copy and paste the code into the Arduino IDE to compile and download to the microcontroller.

Also, since the Arduino Pro Minis do not have a TTL to USB convertor on board, you’ll need additional hardware to do this for you. We used Adafruit’s FTDI Friend since it supports 3.3V devices (which is what the Pro Minis run at). Since this is arduino code, you could always just use an Arduino UNO or other board that has a built in USB to TTL converter and download just like you would with the Pro Minis.

Why did we pick the Arduino? I think of the Arduino as a movement to open source hardware and software for creators around the world. There is an abundance of information from everything you could imagine the Arduino doing, and the way the code works it looks very similar to C, and with all the included functions a kid could even program one! Having said that, there are many many other functions that are developed outside of the IDE that can be utilized, like I did with the MPR121 code in the GROW unit and also the SerialGLCD code.

The other big factor in choosing these units was the price. They are much cheaper than other similar microcontroller units that are made for projects like this (because its all open source the market that produces these units are at the mercy of other competitors prices and users are after the higher quality product). These units can do everything the BS2SX unit can, plus it has a built in 10-bit analog to digital converter.


© 2014 - Brain Overload. All Rights Reserved. Powered by Wordpress and Design by We Create Web Designs