The
Brain

The
brain is where all the other modules come together. Physically the
brain is mostly a couple of little boards and a lot of wires.
Structurally, the brain has two parts to it. There is the
microcontroller, and there is the local circuit.
The microcontroller we are using in this project is an
Arduino board. The
microcontroller is essentially a little computer with a lot of places
to plug things in (like sensors, etc.).
The local circuit is actually the back end for each of the other
modules. Each module has a local circuit component. So the
actual layout for the local circuit in your own GardenBot will be
specific to your particular installation. To see what the local circuit
is for each module, you will have to go to the page for that specific
module.
The main idea is that you
have a board where you can put the "local circuit" part of each module.
This will make it easy for you to plug each module into the brain (and
even rearrange or add new modules later if you need to).
Supplies:
(see the parts page)
- Arduino board
- USB cable
- jumper wires / lead wires
- bread-board / proto-board
- all parts for the local circuit for each of the modules
- the GardenBot software package
The hardware side of the brain
Creating the local circuit board
Here you will be creating a circuit board where you can mount the
local circuit portion of each of the other modules. You will probably
want to have a couple of breadboards side by side to create one giant
breadboard to work out this portion of the brain.
Let's take a look at a potential setup with an Arduino board and a couple of breadboards.
We
start off by running the two power wires -- ground (0v) shown in black,
and source (5v) shown in red. This way our bread-board has power
for easy access during development.
From here you can build the
local circuit for a particular module, and then use jumper wires to
connect that circuit to the Arduino board. If you are not familiar with
reading circuit diagrams, you will need to study up on that -- I do not
tutorials on that specifically. There are many good resources online
for learning how to read circuit diagrams.
For the specific circuit diagram relating to a particular module, you will need to visit the page for that module.
Isolated power supply option
Alternately,
you can isolate the power supply, leaving only the ground connected to
the Arduino board. This will allow you to shield your sensor readings
from any noisy devices such as a motor, or and LCD.
We use a
standard 5v regulator (looks like a transistor) which will allow us to
use any wall-wart with the appropriate specs (see
power supplies)
-- so you can buy a plug from a thrift-store and use it to power
projects. The red LED is an indicator light to tell you the power is on.
Moving to a proto-board
Eventually,
if when you find that the local circuit board is not changing much, you
will want to migrate it to a proto-board -- it will make all the
connections permanent, and you get your bread-boards back (see
bread-boards/proto-boards).
The software side of the brain
Things are very rough still
So, the local circuit board is one part of the brain, and the Arduino is the
other. Since the Arduino is a little computer, everything on the
Arduino side is done with code.
There
is a software package that will give you a working base, BUT it is very
rough. I am a self-taught programmer, and GardenBot is one of the first
Arduino projects I built. My appologies.
The next version of GardenBot will be built upon AutoTalk and will be much more flexible and easy to modify. Go to the
AutoTalk project page for more info.
If you would like to use the current version, download the GardenBot software package from the
parts page.
All
info below pertains to the current software package. Per above warning,
be aware that this software package is not very well developed.
Plugging it in
To
begin, you will need to plug the Arduino board into your computer so
that you can upload the code, or even just provide power.
You
will need to install a couple of things on your computer to allow you
to work with the Arduino platform. If you are not familiar with
Arduino, please start by looking at the information on the
parts page. You can then upload the GardenBot code to your Arduino board.
Getting into the code
Once you unzip the GardenBot software package (see the
parts page),
you will need to open the script called "GardenBot_Arduino" (in a
folder of the same name). This is the script that runs the brain
module, and you will be uploading it to your Arduino board.
As
for my pledge to keep everything simple and clean... I must confess that this is where it
all falls down. I've been told I write code "like an artist". I have made the best
effort to keep the code well commented and clean. Apologies beforehand.
Let's
start by looking at the general (simple) things you can change in the
code (if you don't have much coding experience). Then we'll move on to
talking about everything the code does, and how you can modify it.
Pin declarations
At
the top of the code are the variables that define the pins. This means
that here you can define which pin on the Arduino board you will use to
plug in that particular module. Remember that the Arduino has two
different kinds of pins, analog and digital -- notice that they are
separated in the code for clarity.
// -------------------------
// >> pin definitions
// -------------------------
// this is where you define what pins you'll be using to hook up the various modules
// analog pins
const int SM1sensorPin = 0; // soil moisture 1
const int TP1sensorPin = 1; // soil temperature 1
const int LI1sensorPin = 2; // light level 1
const int SM2sensorPin = 3; // soil moisture 2
// digital pins
const int waterIsOnPin = 6; // if the water is on
const int WS1powerPin = 7; // power to the AC module that turns the water on
const int SM1powerPin = 9; // used to power the sensor intermitantly
// -------------------------
// << pin definitions
// -------------------------
Timers
There
are several different functions on GardenBot that happen at regular
intervals, but the clock-speed of the Arduino board is way too fast for
most of the functions we need to run. To solve this, we have a standard
way of creating timers -- so you can make things happen at the rate you
want them to (like every 15 minutes for example).
Here is the
block of code that functions as a timer. It is placed within the
standard Arduino loop() function. For all timers, you will need to keep
track of the current time (timerCurrentTime). Then, each timer will get
an if() statement that will trigger if the time set by the rate
(timerRateX) has passed. To know if the time has passed, we need to
record the last time the timer was triggered (timerLastX).
void loop(){
// for all timers
timerCurrentTime = millis();
// -------------------------
// >> standard timer structure
// -------------------------
if ( abs(timerCurrentTime - timerLastX) >= timerRateX) {
timerLastX = timerCurrentTime;
// do stuff here
}
// -------------------------
// << standard timer structure
// -------------------------
}
If you need something to happen at a regular rate and each cycle is the
same amount of time, then this simple structure is fine. But what if
you need something to happen at an asymmetrical rate -- like 5 min,
then 30 secons, then 15 minutes, repeat. This is where we will be using
a stepped processing timer.

A
stepped processing timer is a timer that can have each step (timer
cycle) be a different length. This means that each step in the process
can be unique, so you can set up fairly complex actions. This is really
helpful for our cheap soil moisture sensor.
The main reason for doing this was that the cheap soil moisture sensor
we are using will wear out more quickly if it is used constantly (see
electro-etching).
And since soil moisture changes slowly, we can read it intermitantly.
Also, by serializing the events, we assure they will never happen too
close together. This is important because the voltage change during a
sensor can cause noise in the reading of another. By spacing the events
out, you can control for these kinds of problems.
More info to come in future updates
My humble apologies, but we are still in Beta.
The rest of the code is currently not documented.
Explore at your own risk.