You are on page 1of 26

COCC Physics 213

Fall Term 2012


Final Report
Alexander Hogen
James Preston
Tracie Emick


1 | P a g e

Table of Contents
Introduction .................................................................................................................................... 2
Section 1: Project Goals & Design .................................................................................................. 2
Project Goals ................................................................................................................................. 2
Part 1: Data Acquisition ................................................................................................................. 2
Part 2: Website Integration ............................................................................................................ 2
Part 3: Control of External Systems ................................................................................................. 3
General System Overview ............................................................................................................... 3
Voltage Divider .............................................................................................................................. 3
RC Circuit ....................................................................................................................................... 5
Additional Information ................................................................................................................... 6
Sources ......................................................................................................................................... 6
Section 2: Building the System ...................................................................................................... 7
The Big Picture ............................................................................................................................... 7
Host computer ............................................................................................................................... 8
Website ......................................................................................................................................... 8
Sensors .......................................................................................................................................... 9
CO
2
and Temperature .................................................................................................................... 9
Light ......................................................................................................................................... 10
Soil Humidity ............................................................................................................................. 10
Wind Speed ............................................................................................................................... 11
Microcontrollers .......................................................................................................................... 12
Prototype .................................................................................................................................... 12
Major Setbacks ............................................................................................................................ 13
Section 3: Looking to the Future .................................................................................................. 14
Webcam ...................................................................................................................................... 14
Website ....................................................................................................................................... 14
Control of External Systems .......................................................................................................... 15
Weather Station .......................................................................................................................... 15
wViewWeather ............................................................................................................................ 15
Other Ideas .................................................................................................................................. 15
Conclusion ................................................................................................................................... 16
Appendix A - Programming Code ................................................................................................ 17
Appendix B - Computer Information ........................................................................................... 22
Appendix C - Sensors and Parts ................................................................................................... 23
Appendix D - Voltage Divider Maple Worksheet ........................................................................ 25




2 | P a g e

Introduction
For the Fall term of 2012, the COCC Physics 213 class was assigned a term-long project
that turned out to be quite interesting and engaging. The project centered on COCCs
greenhouse, and our portion was to come up with a way to automate many of the functions
within the greenhouse. The idea was to gather sensor data from the interior and possibly
around the exterior of the greenhouse, and then have systems act on that data. As an example,
if the greenhouse interior is too warm, windows would automatically open up to create a cross-
flow of air, or possibly the HVAC system would turn on to actively cool the interior. Another
example would be to measure soil moisture and have an irrigation system turn on if the soil is
too dry. With todays technology all of this is possible, even when limited by budget
constraints.

Section 1: Project Goals & Design
Project Goals
Part 1: Data Acquisition
Our primary goal was to implement a system that will monitor and log different
environmental variables within the greenhouse environment. A list of the potential
sensors that could be included follows. The reader should be aware that at this point
we were just brainstorming and the reasoning behind wanting some of these may not
be obvious. We felt that it was better to start with too many and eliminate those that
we determined would not be needed.
Interior room temperature
Exterior temperature
Interior humidity level
Soil humidity/moisture level
Oxygen level
Methane level
Carbon dioxide level
Wind speed monitor
Light level sensor
IR counter at door (counts the number of visitors coming/going)
Part 2: Website Integration
The second part was to take the data acquired in Part 1 and display it on a
website for all to view. Our wish was to incorporate this project within COCCs existing
website.


3 | P a g e

Part 3: Control of External Systems
Our last goal was to provide a means by which the data provided in Part 1 of the
project can be used to actually control different external systems, such as heating,
cooling, and irrigation. For example, if the data coming from the humidity sensor reads
too low (data acquisition), then it would trigger the sprinkler system to come on for a
set amount of time (control). This has almost unlimited potential.
From the outset, we have gone forward with the intent of trying to reach the goals of
Parts 1 and 2 in terms of a fully functional system. However, our goal for Part 3 was that of
building a system that is capable of controlling external systems in the future, with no intention
of actually controlling any systems at this time. We knew from the beginning that we would
likely not have enough time to give Part 3 an honest try, and because of that, we leave it for
future groups to ponder.

General System Overview
An overview of the system would begin with sensors in the greenhouse that monitor
environmental conditions. These sensors would be connected to and read by a microcontroller
that then sends the data to a computer for it to be logged, plotted and then displayed on a
website. In order to construct the system, we would need to acquire a computer, a
microcontroller, and either construct or acquire the sensors. We would also need to obtain
software that could communicate with the microcontroller, as well as figure out how to display
the data on a website.

Voltage Divider
Most microcontrollers have a few analog
pins which can read and store voltage levels
produced by a sensor circuit. Most of the sensors
we picked out change their resistance as
conditions change. We can easily extract data
from these sensors by constructing a voltage
divider circuit and connecting the analog pin of
the microcontroller to the dividing point.
If we subject the sensor to the extreme high and extreme low expected conditions, we
can measure the high and low resistance values of the sensor with a multi-meter. We will
already know the initial voltage at the power source. With that information, we can determine
the voltage at the divide point by using the equation V=I*R.



4 | P a g e

To find the voltage at the divide, we would first determine the current draw of the
circuit, given by

. The R
total
value, in this case, is the total resistance of the circuit
(R1+R2). We would already know the voltage of our power source, so we calculate the current
draw of the circuit, which we will call I
C
. Knowing the current draw of the entire circuit allows us
to calculate the voltage drop at any point. The only interesting point in this circuit is where
we would connect the analog pin of the microcontroller. The potential before R1 (to the left) is
the same as the voltage source and the potential after R2 (to the right) is always at 0. In
between, the voltage is given by the equation V
drop
=I
C
*R1. Using all of the above equations, we
can come up with a formula for V
drop
in terms of the resistance values like this.




At this point, we would place the sensor in some situation, while measuring the
resistance using a multi-meter. We measured the resistance of a photoresistor with a
household light on and then placed a finger over it and measured again. Under normal light the
resistance was 8.58 K and covered it was 46.3 K. During this test, R2 = 1 K. Since we know
that the PICAXE has a 5 V output supply, we can calculate a voltage output at the analog pin
connecting point using the equation we just derived above.



We have a range of 4.5 V 4.9 V at the drop point under these circumstances. When the
PICAXE reads a value from its analog pin (ADC pin) the value it returns is relative to the
reference voltage which, in this case, is 5 V. So, when the voltage at the drop point is closer to 5
V, the ADC pin reads a small value. When the voltage drop is farther from the reference
voltage, the ADC pin reads a larger value. When we ran our experiment in the room, the PICAXE
returned 100 for bright light and 16 for dim light.
We plan to use this method to read data from our light and temperature sensors.
Additionally, we wrote a Maple worksheet to aid in calculating the voltage drop values so that
we could easily check to see if the output voltage would be too high for the microcontrollers or


5 | P a g e

not. This worksheet is included in the project files in Appendix D. It should be noted that with a
higher value for R2, the rage of values at the drop point will be greater. This could be useful to
obtain a higher degree of sensitivity, if the situation required it.

RC Circuit
For other sensors, we can use an RC (resistor and capacitor) circuit, with one of the
components being variable and the other constant. Here are the two possible circuits.
We notice that we can use the capacitive time constant equation ( =RC ) to determine
the value of the unknown/changing element if we know at least two of the variables. We
already know the value of one of the components. If we can find a suitable value for , we can
plug numbers into the equation and solve for the unknown/changing element. First, well need
to understand some basic ideas about microcontrollers.
A digital pin on an average microcontroller is capable of four different operating
conditions. In output mode, it is capable of being in either high or low position (on or
off). In input mode, it can read either a one or a zero (on or off). There is a threshold
voltage level, which differs from microcontroller to microcontroller, that determines whether
the microcontroller will read a one or a zero. As an example, lets say that this threshold level
on our PICAXE is about 2.5 V (which it isnt). Below this voltage, the PICAXE will read a 0.
Above 2.5 V, it will read a 1.
To determine the value of the variable element in the circuit above, the microcontroller
first charges the capacitor by setting the pin to output and then turns it on ("high"). The RC
circuit now has potential energy due to the charged capacitor. After a short period of time, the
microcontroller will set the pin to input/low. Since both ground and the input pin now have the
same potential, the energy has nowhere to flow. The capacitor can only discharge through the
resistor, which is connected in parallel across its terminals. The microcontroller instantly starts
a timer and counts how many units of time go by before the capacitor has discharged enough
energy through the resistor that the RC circuit potential drops below the PICAXEs threshold
and the microcontroller reads a 0 on that pin.
Using the time value the microcontroller just calculated and the value of the fixed
component in the circuit, we can use the capacitive time constant equation and solve for the
unknown component. In our case, the unknown component could be the air humidity sensor,
the soil humidity sensor, the light sensors, or almost any of the other sensors we are using.
However, we will use this concept only with the air humidity sensor.




6 | P a g e

Additional Information
Obviously when starting any project there is a tendency to think that you know what
you will need. In our case, we made decisions about the hardware (specifically the
microcontroller) based on the number of sensors that we thought that we would need. In
hindsight, buying a larger Arduino would probably have been a better choice from the outset
versus buying a smaller Arduino and adding the PICAXE. Future-proofing can be a difficult issue,
especially when budget constraints play a role.

Sources
Megunolink: http://www.blueleafsoftware.com/Resources/EmbeddedSand/MegunoLink
Arduino: http://www.arduino.cc/
GardenBot Project: http://gardenbot.org/about/
Picaxe: http://www.picaxe.com/
Linux (Ubuntu): http://www.ubuntu.com/
wView: http://www.wviewweather.com/







7 | P a g e

Section 2: Building the System

The Big Picture
Sensors: The pieces of hardware that will take environmental readings (temperature,
humidity, light...). These represent the most basic part of the design. Most are essentially some
type of resistor that reacts to the change in the environment. For example, a heat sensor
changes resistance as the heat changes.
External Devices: Hardware that will control the environment (HVAC, Solar Angle ).
These devices are what control the environment of the greenhouse and could be managed by
the microcontroller.


8 | P a g e

Microcontroller: A small processor that can read (sensors) and control (External
Devices) direct hardware. The microcontroller is kind of the half-brain of our system. Our
microcontroller will take sensor readings and could potentially control the environment of the
greenhouse.
With this setup, we can control the environmental devices and get data from our
sensors. Once on the computer, the collected data can be published to a website as well as be
used to monitor and control the environment in the greenhouse.

Host computer
One of the difficulties with this project comes with the communication between the
microcontroller and host computer. There are very few programs that have been written with
the goal of communicating with the Arduino and logging the data that it captures, with most
successful systems having been written from scratch by amateur programmers for their
personal use. Our original plan involved using a program called wViewWeather that requires a
Linux operating system, but prior to acquiring the host computer, we found a Windows-based
program called Megunolink that can communicate directly with and log data from the Arduino.
To be sure that all bases were covered, we decided to dual-boot the computer with Linux just in
case it did not work out. It would be prudent for future groups to investigate alternative
options that may be available to them that do not exist at this point in time. A listing of our
current hardware and software specifications is contained within Appendix B at the end of this
report.

Website
We had thought that the website would be the easiest part of this project. While that
may still be the case, it turned out to be much trickier than we first thought. In recent years,
COCC has had what can only be accurately described as massive intrusions into its website and
databases. Because of that, COCCs ITS department has greatly hardened its security around
these resources and does not open them for anyone, at least not for a group of physics
students. So we needed another plan. What COCC could provide was a static page that would
display images linked from another website. And so the question became how do we take that
raw data and turn it into an image of a plot?
We examined a number of options, including writing a script that would dump the data
into a SQL database, then using some other tool or possibly writing another script that would
plot the data. This would not be a simple approach by any definition. After much searching, we
found a Windows-based program called Megunolink. This program could talk directly to the
Arduino, log its data, export it to a text file, plot the data, and export the plot into an image file.



9 | P a g e

Megunolink does exactly what we need it to do but there is one drawback. There is no
automatic export function, so the data plot would need to be manually exported to be viewed
on the website. We found a workaround for this using software called AutoIt. It is a scripting
program used for automating the Windows GUI. With this software we will be able to save the
plot to a networked folder and be able to display it on the web page.
For the website itself, we decided against trying to integrate with COCC and instead
chose to utilize Google Sites. It has many limitations, but in the end allowed us to get a
functional website up quickly and easily. We set up the host computer with both Google Drive
and Picasa, which run automatically after logging in. Both programs sync files from the PH213
Greenhouse Project folder, which is located on a separate partition on the host computers
hard drive. Picasa allows us to sync pictures in a certain folder up into a web album. This web
album is easily embedded in other web pages. Google Drive allows us to keep a local copy of all
project files on the computer, as well as backed up in the cloud.

Sensors
When we were brainstorming about possible sensors, we had
many ideas which were mentioned in Section 1 of this report. We
narrowed these options down by creating and sending a survey to the
rest of the class to assess the needs of the other greenhouse groups. We
would have liked to have more feedback than what we received, but we
used what information we did receive and narrowed the list down to light level, indoor/outdoor
temperature, indoor air humidity, soil humidity, carbon dioxide, and outdoor wind speed. With
this list, we searched for the parts required and created a budget. We minimized the cost as
much as we could by making many of the sensors ourselves. The final total came just under
$94. The exact list is summarized in Appendix C.
CO
2
and Temperature
When our parts came in, we started assembling the sensors. The carbon dioxide,
air humidity, and thermometer sensors are fairly easy components to use. However,
because of some programming difficulties described
later, we were unable to get the air humidity sensor
working. With a couple basic components (i.e.
resistors/capacitors/wires), we had the carbon dioxide
sensor hooked up to the Arduino and the three
thermometer sensors connected to the PICAXE. Both of
these sensors send basic analog data so by connecting
them to the analog pins on the microcontrollers, we were
Air Humidity Sensor
Carbon Dioxide Gas Sensor


10 | P a g e

able to receive sensor values fairly quickly.
Light
The other sensors required some assembly. For the light
sensors, we thought about using a photoresistor (sometimes called a
light dependant resistor or LDR) and a capacitor connected in parallel.
By using the RC Circuit method, described in Section I, we would be
able to read the resistance. However, we found it would be much
simpler to wire the LDR in series with a resistor and use the Voltage
Divider method, also described in Section I.
Soil Humidity
Both the wind speed sensor and the soil humidity sensors we built ourselves. We
did some research and found that sensing soil humidity is as simple as sticking two wires
in the ground and measuring the resistance across the exposed ends at the bottom. This
works because water conducts electricity, so when there is more water, the resistance
drops and vise versa. We again used the Voltage Drop method by connecting the two
probes in series with resistor, the probes being first in the series. The probes were
constructed out of standard 14 gauge copper wire used in residential electrical wiring
with the last couple centimeters of insulation
stripped off. We stuck these probes in a block of
foam in order to keep them equally spaced from
one another. If the leads are at an angle from one
another in the soil, then it will skew the readings.
After soldering some smaller wires to the probes,
we stuck the sensor in a freshly-watered potted
plant, wired up the circuit and used a BASIC
Stamp 2 microcontroller to read data over a
couple hours.
For the test, we actually used the RC Time
idea, instead of the Voltage Divider method we
plan on using for the actual setup, so the
numbers will turn out different. However, the
graph below shows how the soil dried out and
demonstrates that the sensor actually works.
Photoresistor
DIY Soil Moisture Sensor


11 | P a g e


We planned to test the sensor to find ranges of values and assign a category to
that range, as these sensors dont need to be precise. This is a hypothetical example but
describes the concept we intended on implementing.
Microcontroller Value

Moisture Category
400-500 Fairly Wet
300-400 Adequately Wet
200-300 Moist
100-200 Dry
Wind Speed
The last sensor we were going to construct
ourselves was the wind speed sensor. We based
our ideas off of a project posted on Hackers
Bench
1
. The underlying sensor is a hall-effect
sensor, which senses significant changes in
magnetic fields. This device is used in automotive
camshaft sensing and other similar settings to
measure rotational speeds. A magnet is fixed on
the rotating structure and is positioned so that it

1
http://www.hackersbench.com/Projects/anemometer/
Hall-effect Sensor


12 | P a g e

passes by the hall-effect sensor as it spins. The hall-effect sensor will then output values
to a microcontroller. In our setup, the magnet would most likely be glued to the shaft of
the structure, which would be spun by the wind driving the metal ladles around.
However, we were unable to build or test this device.

Microcontrollers
We chose to use two different microcontrollers: the Arduino and PICAXE. The Arduino
serves as the brain while the PICAXE collects the data.
They communicate through a serial data connection. For this link there is only one data
line required for one-way communication. The PICAXE takes sensor readings and sends them
over the serial bus while the Arduino just listens for the data. The data is formatted as follows:
SensorType, SensorValue. These values are sent in an ASCII character format. Once the Arduino
receives a complete set for any sensor, it then reformats the sequence to be useable by
Megunolink. That format is: {SensorType, T, SensorValue}. In the future, the Arduino will need
to control external devices, in which case there will also need to be a protocol in the code for
sending the Arduino commands. This format could closely follow the current receive protocol.
The code for both Arduino and PICAXE can be found in Appendix A.

Prototype
Our current prototype consists of the Arduino
and PICAXE microcontrollers linked together. The
PICAXE takes care of all the sensor data and then
sends it to the Arduino. Below are the PICAXE pin-out
diagram and a chart showing where to connect each
sensor:
T = Temperature
L = Light
SH = Soil Humidity
AH = Air Humidity


ID PIN SENSOR

ID PIN SENSOR
- +V -

- 0V -
- C.5 RX

- B.0 TX
1 C.4 SH 1

6 B.1 T 1
2 C.3 SH 2

7 B.2 T 2
3 C.2 SH 3

8 B.3 T 3
4 C.1 SH 4

9 B.4 L 1
5 C.0 AH 1

10 B.5 L 2


13 | P a g e

Once all the sensors have been wired onto the PICAXE it is time to connect the Arduino.
Only 2 pins are needed for the communication from the PICAXE to the Arduino (Arduino to
PICAXE would require 1 more pin). These two pins are ground (GND) and digital pin 2 (Used as
RX line). The connection is simple:
1. Connect the Arduino ground pin (GND) to the PICAXE ground pin (0V or #14).
2. Connect Arduino digital pin 2 to PICAXE pin B.0 (pin 13).
If everything was done correctly, you should have successful one-way communication
from the PICAXE to the Arduino. The next step is to load the software onto the
microcontrollers. A tutorial on how to do this can be found on the Arduino and PICAXE
websites:
http://arduino.cc/en/Guide/HomePage
http://www.picaxe.com/Getting-Started/PICAXE-Manuals/
The PICAXE (.bas) file and the Arduino (.ino) file can be found on the Google drive for
this project. These files can be downloaded to their respective microcontrollers after the
programming interface software is installed on the PC. Later on it might be necessary to add
sensors and or external devices. There are many pins available on the Arduino for any external
control devices but these devices must be integrated into the current serial protocol. First we
will discuss how the sensor data is sent to the Arduino from the PICAXE. The data is encoded
into two fields: SensorType, SensorValue. These are sent as ASCII characters in the following
format:
SensorType, SensorValue,
For example if you received 2, 100, this would mean that soil humidity 1 sensor shows
a value of 100. This data is interpreted by the Arduino and then reformatted to be sent to the
computer. The format for the Arduino to computer is similar but slightly different:
{SensorType, T, SensorValue}
This format was chosen solely to work with Megunolink. In the future this could be
changed to work with other monitoring programs or a self-built one. At this point in the project
this works well since Megunolink can create plots which are great for data collection.

Major Setbacks
We had a few major setbacks in this project, and would likely have made some different
choices were we to do this again. The first challenge involved the hardware that we chose to
use; specifically the microcontrollers. The Arduino is a widely-used open source microcontroller
with many built in libraries and functions. The PICAXE is a more basic microcontroller that


14 | P a g e

requires much more work to implement certain tasks. Our major problem was the link between
the two and the fact that they were not designed to work together. They are coded in different
languages and work differently, which posed a problem when trying to talk back and forth
between the two. With enough time, we were able to eventually get the communication
working but in hindsight probably should have done things differently. Instead we should have
either used two Arduinos or a higher performance Arduino, eliminating the need of any
controller to controller communication.
A second setback involved the link between the microcontrollers and the website. We
researched heavily on this subject and found a way to overcome this issue. Using Megunolink in
combination with AutoIt we can get data plots published but a better method should be
implemented in the future. Optimally we would like the data to be imported into a SQL
database. This would make the data much more accessible to the world and portable if the
website needed changing, and it could possibly make the data easier to extract when using it
for control of external devices. Therefore it is our recommendation that future groups address
this issue as one of their primary goals.

Section 3: Looking to the Future
As much as we wanted to, we could not accomplish all of our goals within the scope of a
single COCC term. But we have put together a few ideas that will hopefully give future groups
some thought in terms of what direction that they may want to take this project.

Webcam
The idea of a webcam in the greenhouse was there from the beginning, but because of
budget constraints it was moved into the future ideas category at a very early point. It is
something that, while not necessary to any control over the functionality of the greenhouse,
could prove to be a valuable addition since a person can get a visual idea of what might be
happening.

Website
One of the bigger difficulties with this project actually became integration with COCCs
website. While we wanted this to become part of COCCs site for obvious reasons, using
Google Sites proved to be a much easier solution for the short term. For the long term
however, a more robust solution would be recommended. Utilizing a SQL database along with
PHP scripting would be one popular current way to do this. This would open up so many
avenues and possibilities in terms of how the data can be displayed and what tools can be used
to do it. We realize that there are cost issues around hosting and domain name acquisition, but


15 | P a g e

we are all confident that overcoming those obstacles will not prove to be too difficult for future
groups.

Control of External Systems
As mentioned earlier, we envisioned that we would leave this system ready for others to
start building the tools that would control external systems. One suggestion that we make is to
utilize a second microcontroller to control external systems such as irrigation or HVAC. A
second software application would likely be needed that would be capable of taking the data
logged by Megunolink. External systems include (but are not limited to):
HVAC - heating & cooling
Irrigation
Lighting
Solar panel angle

Weather Station
Early on we looked closely at using a weather station instead of the Arduino to capture
and log data. This would still be on the table, if the group wanted to use the existing Arduino
card for control. The advantage to using a weather station is that it potentially opens up a lot
of capability on the software side in terms of what can be logged and how the data can be used.
There are many good models, and in our research it looked like the Davis brand was particularly
well-thought-of. There is a lot of software out there built for use with weather stations (such as
wViewWeather among others), but not so much for the Arduino. So this could be a viable
solution for a group looking to move into the control portion of the project. There is a
document in the Google Drive (Appendix B) that lists our research surrounding this idea.

wViewWeather
The original software that we considered is called wViewWeather. It is Linux-based and
while it is a weather program, many, many people are using it to monitor greenhouses. While it
could be potentially difficult to set up and does require Linux, it looks like it has the potential to
be quite powerful for our purposes, and future groups may want to consider it. The reader
should note that the host computer was set up as a dual-boot system with Linux (Ubuntu)
installed, so outside of potentially needing updates it is ready to go in that sense.

Other Ideas
In trying to plan for the future, we came across a lot of ideas for how this project could
evolve and be an asset to COCC. One such idea is that this project could branch into an actual
weather station for the college. And while we could not think of any community-based project


16 | P a g e

that could come of any of this, it stands to reason that getting the community at large involved
could lead to some interesting ideas.

Conclusion
In conclusion, this project will be of tremendous value to COCC. Going forward, it can
obviously be used as a great teaching tool for many other disciplines outside of physics and
could inspire more community involvement in the greenhouse itself. The culinary department
is very interested in what is happening with the greenhouse, and there has also been interest
expressed from the CIS department in terms of getting involved with some of the programming
aspects.
Overall, the three of us really enjoyed this experience. While it was frustrating at times,
that is part of the programming experience, which is about problem solving. Getting the two
microcontrollers to talk to each other or spending what seemed like weeks looking for software
that we could use to get the host computer to talk with the Arduino as well as provide the
other needed functions, were both examples of things that really frustrated all of us. But as any
programmer knows, when you actually solve the problem and get things working, it is an
incredibly gratifying experience.






17 | P a g e

Appendix A - Programming Code

Arduino Code
Receive and Display Data

Receives data sent by the PICAXE and passes it on to the computer to be processed/stored.

#include <SoftwareSerial.h>

//Setup the software serial port on pins 2 and 3
//Used for communicating with PICAXE
SoftwareSerial mySerial(2, 3); //Rx, Tx
String data[2]; //Array to hold the sensor type and value
String serialDataIn; //String to hold the received data
int counter; //Used to index data[]
char inbyte; //Current character received by serial

String sensorValues[2][10]; //Array of all our sensor readings

void setup()
{
// set the data rate for the serial port
Serial.begin(9600);
// set the data rate for the SoftwareSerial port
mySerial.begin(9600);
counter = 0; //Zero the counter
serialDataIn = String("");
}

void loop() // run over and over
{
//Check if the counter has reached 2
if(counter > 1){
counter = 0; //Reset it
}
//If this is true the PICAXE is sending data
if(mySerial.available()){
inbyte = mySerial.read(); //Read character from PICAXE

//If the character is an integer...
if(inbyte >= '0' & inbyte <= '9'){
serialDataIn += inbyte; //Add that character to the current string
}
//If the character is a ';' the current number has been received
if(inbyte == ','){
//Set the received string to the current index of data[]


18 | P a g e

data[counter] = String(serialDataIn);
counter += 1; //Index the counter
//If the counter > 1 we have received a complete reading
if((counter > 1) & (data[0].length() <= 2)){
/* This if block checks what sensor was received and prints
the reading to the computer */
Serial.print("{");
Serial.print(data[0]);
Serial.print(",T,");
Serial.print(data[1]);
Serial.println("}");

}
serialDataIn = String("");

}

if(inbyte == '\r'){
//Serial.println("End");
}
}
}

CO2 Sensor

Reads analog data from the GE Telaire 6004 CO2 module
/*
Analog Input
Demonstrates analog input by reading an analog sensor on analog pin 0 and
turning on and off a light emitting diode(LED) connected to digital pin 13.
The amount of time the LED will be on and off depends on
the value obtained by analogRead().


int sensorPin = A0; // select the input pin for the potentiometer
int sensorValue = 0; // variable to store the value coming from the sensor

void setup() {
}

void loop() {
// read the value from the sensor:
sensorValue = analogRead(sensorPin);
// sensorValue is the variable that stores what the CO2 reading is
// Send the value back to the computer
Serial.println(sensorValue);
}



19 | P a g e


PICAXE-14M2 Code
NOTE: All PICAXE code for this project should begin with the following statement:

setfreq m16

This is because the PICAXE will default to running at 4 MHz, whereas the Arduino operates at 16
MHz. By using this command, we overclock the PICAXE to run at 16 MHz. With both
microcontrollers running at the same clock speed, it is much easier to communicate between
the two.

Temperature Sensor

'Temperature Sensor - Read and Display.bas

#picaxe 14m2
setfreq m16

symbol TX = C.1
symbol ID = b0
symbol value = w1
symbol T1 = b.1
symbol LED = b.5 'LED has positive lead on pin "b.5" and is
'connected to resistor running to ground.
'This simply indicates when the PICAXE is
'sending data, for debugging purposes.

let ID = 1 'The ID value of the first temp sensor is "1"
let value = 0 'Initialize the variable to store the sensor value


low T1 'Make sure the temp sensor pin isn't sending
'a voltage output.


main:

readadc10 T1,value 'Read the value from ADC pin
value=value-158 'Adjust by calibration number
'That calibration number is determined by testing
'the output value and comparing it to the real
'temperature in the environment.
'CalVal = Value - RealTemp

ID = 6


20 | P a g e

goto send 'Send to computer, one reading per line

pause 100

goto main 'Go get some more data! (I.E. do it again)


send:
high LED

serout TX, T9600_16,(#ID, ",", #value, ",") 'Send "ID" and "value"
'formatted as an ASCII value
'on TX pin at a 9600 baud
rate

'Comment the following line out if using pin B.0 as the TX pin. This
'is used only if the PICAXE is connected to the computer for debugging
'purposes.

sertxd (#ID, ",", #value, ",", cr, lf) 'Since the PICAXE is running
at
'16 MHz, this data is sent to
'the computer at a baud rate
of
'19200

low LED

pause 1000

goto main

Light Sensor

This code is the programming platform for all the sensors that are read using a voltage divider
concept. The list of sensors that use a voltage dividing circuit can be found in Appendix C.

'Light Sensor - Read and Display.bas

setfreq m16
#picaxe 14m2 'Restrict PICAXE Type
#terminal 19200 'Open terminal with selected baud rate


'LDR (photoresistor) and 220 ohm resistor in series across
'+V and ground. L1 pin connected at voltage divider.


21 | P a g e


Symbol L1=B.4
Symbol TX=C.1
Symbol ID=b0
Symbol value = w0

let ID = 9

main:

'The circuit described above is a voltage divider. Analog pin C.0
'is connected to the junction between the LDR and the resistor.

readadc10 L1,value 'Read the value

serout TX, T9600_16,(#ID, ",", #value, ",") 'Send "ID" and "value"
'formatted as an ASCII value
'on TX pin at a 9600 baud
rate

'Comment the following line out if using pin B.0 as the TX pin. This code
'is used only if the PICAXE is connected to the computer for debugging
'purposes.

sertxd (#ID, ",", #value, ",", cr, lf) 'Since the PICAXE is running at
'16 MHz, this data is sent to
'the computer at a baud rate of
'19200

goto main 'Go get some more data! (I.E. do it again)













22 | P a g e

Appendix B - Computer Information
Computer Specifications

Hardware
System: Dell Optiplex 745
CPU: Intel Core 2 6300 @ 1.86 Ghz
Hard Drive: Western Digital WD800 80 Gb
RAM: 2 Gb DDR2 PC-5300 / 333Mhz (2 sticks)
Video: Radeon X1300 400 Mhz / 256 Mb
Wireless: Linksys WMP54G PCI v4.1
Optical drive: DVD-RW
Software (dual booted Windows Vista & Linux)
OS: Windows Vista Home Basic SP2 32 bit
OS key: MDRM9-RMHQ7-23G93-6DXYR-V4M44
Megunolink: <http://tinyurl.com/b6dnltm>
Picaxe software: <http://tinyurl.com/7zkf9xh>
Arduino software: <http://tinyurl.com/85e6cj>
Linux: Ubuntu v12.04 LTS (username: Dell Computer, password:
password)
Greenhouse IT Accounts

We set up a GMX email account for the group so that we wouldn't have to use any personal
email addresses for this project. With the GMX address, we were able to sign up for a Google
account, which allowed us to use Google Drive for syncing documents/folders and Picasa for
syncing pictures. Specific account information is provided below.

GMX Email (https://www.gmx.com)

Address/Username: it.coccgreenhouse@gmx.com
Password: 1027Trenton
Security question: What city were you born in?
Answer: Bend
Contact email (if locked out of account): Ralph Tadday <rtadday@cocc.edu>
Google/Picasa

Username: it.coccgreenhouse@gmail.com
Password: 1027Trenton


23 | P a g e

Appendix C - Sensors and Parts

Organizational Schematic
Devices Used

Name
Number
Used
# of pins
on device
Circuit
type
Used
with
Arduino UNO 1
Dig I/O - 14
Alg In - 6

PICAXE-14M2 1 10 I/O
CO2 | GE Telaire T6004 1 12 Analog In Arduino
LM34 Thermometer 3 3 Analog In PICAXE
HS1101 Air Humidity 1 2 RC Time -
Hall Effect - Melexis 90217
(rotor speed)
1 3 Analog In Arduino
Photoresistor 2 2
Voltage
Drop
PICAXE
Soil Probes 3 2
Voltage
Drop
PICAXE


24 | P a g e

Device Datasheets

Arduino UNO
<http://arduino.cc/en/Main/ArduinoBoardUno>
PICAXE-14M2
<http://www.picaxe.com/docs/picaxe_manual1.pdf>
CO2 | GE Telaire T6004
<http://www.allelectronics.com/mas_assets//spec/CDS-1.pdf>
LM34 Thermometer
<http://www.parallax.com/Portals/0/Downloads/docs/prod/datast/LM34_Datasheet.pdf>
HS1101 Air Humidity
< http://www.parallax.com/Portals/0/Downloads/docs/prod/sens/27920_HS1101-
Datasheet.pdf >
Melexis 90117 Hall Effect Sensor
<http://www.parallax.com/Portals/0/Downloads/docs/prod/compshop/MLX90217.pdf>

Budget
Sensor Distributor Obtained Count
Price
ea.
Shipping Subtotal

Thermometer EBay X 4 $2.25 $0.00 $9.00

Humidity EBay X 1 $3.98 $0.00 $3.98
Carbon Dioxide
All
Electronics
X 1 $10.00 $7.00 $17.00

Photoresistor COCC X 4 $0.00

$0.00
200-300 Ohm Resistor COCC X 4 $0.00

$0.00

Stainless Ladle Dollar Tree X 4 $1.00 $0.00 $4.00
Hall Effect Sensor EBay X 1 $1.63 $2.00 $3.63

Arduino UNO Amazon X 1 $19.99 $0.00 $19.99

PICAXE -14M2 Cana Kit Inc. X 1 $4.95 $6.50 $11.45
PICAXE-14 Project Board EBay X 1 $3.41 $6.34 $9.75
PICAXE Programming
Cable
Cana Kit Inc. X 1 $7.95 $6.50 $14.45


Total: $93.25


25 | P a g e

Appendix D - Voltage Divider Maple Worksheet:
>

Voltage at the power source
>

Resistance of R1 at min (a) and max (b) values IN OHMS.
NOTE: Include a decimal point in these two numbers. Maple will then
calculate decimal numbers instead of leaving everything as a fractions.
>
>

Value of R2 IN OHMS
>

Calculate the current draw for the high and low resistance circuit.
>
>

Calculate the voltage drop for the high and low resistance circuit.
>
>

You might also like