GARDENS Code
Skip to end of metadata
Go to start of metadata

We had originally planned on not posting our code to this Wiki. 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. 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.

GROW Code

SECANT Code

**IMPORTANT**

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 ( http://www.sparkfun.com/products/8702 ) 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!).

********************

**NOTICE**

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 (http://www.ladyada.net/learn/sensors/tmp36.html).

*******************

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.

Labels
  • No labels