Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
by
Kristian Doherty
Jevon Weisensel
Zhixuan Feng
Khanh Huynh
Braden Cross
Final report submitted in partial satisfaction of the requirements for the degree of
Bachelor of Science
in
Electrical and Computer Engineering
in the
Faculty of Engineering
of the
University of Manitoba
Winter 2016
© Kristian Doherty, Jevon Weisensel, Zhixuan Feng, Khanh Huynh, Braden Cross
Abstract
The Buller greenhouse was built in the 1960’s to house a variety of plants used for teaching and
research purposes. Originally intended to be a temporary structure, all of the buildings temperature
control systems are operated manually; while temperature and humidity is monitored using gauges that
are read by staff inside the greenhouse. The aim of this project was to implement a scaled prototype
monitoring and control system for one room of the greenhouse that could be accessed remotely via a web
based server.
To achieve this goal, Arduino micro controllers were chosen to be used in a master/slave
configuration. The slave controller is used to control a dc motor to open the window with provisions
made for a relay system that could be used to operate additional temperature controls such as the swamp
cooler and heater. It is also used to obtain readings from the temperature, humidity and light intensity
sensors. These readings are relayed to the master controller using XBee wireless transceivers and then
uploaded to the web server through an Ethernet shield. An automated control system was developed using
the inputs from monitoring system to decide when to operate the temperature controls.
A prototype system was successfully developed that met the design constraints set out in the
project proposal. This system logs temperature, humidity and light intensity readings to the web server
every ten seconds. Through testing it was demonstrated that dc motor is capable of opening the windows
in the greenhouse and that control signals could be sent remotely to operate the greenhouses temperature
control systems. The secondary goal of developing software that utilizes the monitoring system data to
operate the temperature controls was also achieved.
i
Contributions
Kristian Doherty
Jevon Weisensel
Khanh Huynh
Zhixuan Feng
Braden Cross
Monitoring System ○ ○
Control System ○ ○
Hardware Testing ○ ○
Hardware Integration ○
Final Presentation
ii
Acknowledgements
Throughout the course of our project we received advice and assistance from many members of
staff at the University of Manitoba. We would like to thank and acknowledge the following people for
their guidance:
Our academic supervisor, Dr. Robert McLeod, for his continual support throughout the school
year. Significantly his help with the mechanical installation of the project saved us many frustrated hours.
Our Co-Advisor, Dr. Ahmed Byagowi, for proposing the project and giving technical advice on
our design.
Our industry supervisor, Dr. Carla Zelmer, for allowing us to take over a room in her greenhouse
and assisting us however she could.
The ECE Chief Technician, Glen Kolanksy, for helping us with budgeting and creating a
realizable project scope. Always being available and ready to answer any questions we had through the
year. His expertise was invaluable towards the completion of our project.
Electric Shop Technician, Sinisa Janjic, for helping us with part ordering and sourcing. Going out
of his way to find the right place for the right part.
The Machine Shop Technicians, Cory Smit and Zoran Trajkoski, for helping make our project
enclosure. We would’ve been at a loss without their assistance and the skills they provided.
Finally we would like to thank Dr. Derek Oliver, Aidan Topping, and Dan Card for providing
expertise and guidance all year long. Providing valuable feedback allowing us to progress and improve
our written and oral communication skills.
iii
Table of Contents
Abstract .......................................................................................................................................................... i
Contributions................................................................................................................................................. ii
Acknowledgements ...................................................................................................................................... iii
Table of Contents ......................................................................................................................................... iv
List of Figures ............................................................................................................................................. vii
List of Tables ............................................................................................................................................. viii
Nomenclature ............................................................................................................................................... ix
1 Introduction ....................................................................................................................................... 1
1.1 Motivation ................................................................................................................................. 1
1.2 Design Approach....................................................................................................................... 1
1.3 System Overview ...................................................................................................................... 2
2 Monitoring System............................................................................................................................ 4
2.1 Hardware ................................................................................................................................... 4
2.1.1 Arduino UNO.................................................................................................................... 4
2.1.2 DHT11 Temperature and Humidity Sensor ...................................................................... 5
2.1.3 DFRobot Light Sensor ...................................................................................................... 6
2.1.4 DS18B20 Temperature Sensor.......................................................................................... 7
2.1.5 Liquid Crystal Display ...................................................................................................... 8
2.2 Software .................................................................................................................................... 9
2.2.1 DHT11 Temperature and Humidity Sensor ...................................................................... 9
2.2.2 DFRobot Light Sensor .................................................................................................... 10
2.2.3 DS18B20 Digital Temperature Sensor............................................................................ 10
2.3 Integration ............................................................................................................................... 10
3 Control System................................................................................................................................ 12
3.1 Hardware ................................................................................................................................. 12
3.1.1 MD10C Motor Driver ..................................................................................................... 12
3.1.2 Sun Founder 2 channel Relay ......................................................................................... 13
3.1.3 8507840 Linear Actuator ................................................................................................ 13
3.1.4 Denso 730557 7030 L Rotational Motor ........................................................................ 14
3.1.5 Feedback Switches .......................................................................................................... 14
iv
3.2 Software .................................................................................................................................. 15
3.2.1 Manual Control Mode ..................................................................................................... 15
3.2.2 Automated Control Logic ............................................................................................... 16
3.3 Integration ............................................................................................................................... 17
4 Wireless Communication System ................................................................................................... 19
4.1 Hardware ................................................................................................................................. 19
4.1.1 Xbee S2 ........................................................................................................................... 21
4.1.2 XBee USB adaptor .......................................................................................................... 22
4.1.3 XBee Shield .................................................................................................................... 22
4.2 XTCU Software ...................................................................................................................... 23
4.3 Arduino Software .................................................................................................................... 24
5 Web Server...................................................................................................................................... 26
5.1 Hardware ................................................................................................................................. 26
5.1.1 Arduino Mega ................................................................................................................. 26
5.2 Software .................................................................................................................................. 27
5.2.1 Initialization .................................................................................................................... 27
5.2.2 Polling ............................................................................................................................. 27
6 Web Interface .................................................................................................................................. 30
6.1 JavaScript Libraries................................................................................................................. 30
6.2 Login Page .............................................................................................................................. 31
6.3 Interface Page.......................................................................................................................... 32
6.4 Data Logging .......................................................................................................................... 34
7 Design Changes .............................................................................................................................. 35
7.1 Window Position ..................................................................................................................... 35
7.1.1 Ultrasonic Sensor ............................................................................................................ 35
7.1.2 Reed Switch .................................................................................................................... 35
7.1.3 Contact Switches ............................................................................................................. 36
7.2 Window Operation .................................................................................................................. 36
7.2.1 Rotational Motor ............................................................................................................. 36
7.3 Web Server Connection .......................................................................................................... 36
8 Conclusion ...................................................................................................................................... 37
8.1 Future Considerations ............................................................................................................. 37
References ................................................................................................................................................... 38
Appendix A - Slave Arduino Code ............................................................................................................. 40
Appendix B - Master Arduino Code ........................................................................................................... 50
v
Appendix C – Web Interface Code ............................................................................................................. 61
Appendix D – Website Login Code ............................................................................................................ 66
Appendix E - XBee Parameter Configuration ............................................................................................ 67
Appendix F - Budget ................................................................................................................................... 68
Curriculum Vitae ........................................................................................................................................ 69
vi
List of Figures
vii
List of Tables
viii
Nomenclature
Arduino – Open source microcontroller
IP – Internet Protocol
PC – Personal Computer
RH – Relative Humidity
Shield – peripheral boards that are designed to easily interface with Arduino microcontrollers
ix
Chapter 1
1 Introduction
1.1 Motivation
The Buller greenhouse (seen in Figure 1-1) was built in the 1960’s to house a variety of plants
used for teaching and research purposes. The building itself comprises of nine rooms that each have their
own unique climate conditions. This allows some very unique plants to be kept in the greenhouse from a
wide range of locations. The main concern for each of these rooms is that they stay within a proper
temperature range. In the summer months this is primarily done by manually opening and closing
windows. This requires staff to come in on the weekends if the outside temperature gets too high. The
goal was to implement a system that allows remote monitoring and control to help reduce the amount of
time staff needs to be present in the greenhouse.
The scope of the project was to produce a working prototype monitoring and control system for
one room of the Buller greenhouse. This system can be accessed remotely using a web server on any
internet connected device. This project could be easily expanded for use in all of the rooms in the
greenhouse so that each room could be automated. This report will demonstrate that a fully automated
greenhouse could be realized using our design and an expanded budget.
1
1.3 System Overview
This project utilizes two Arduino microcontrollers in a master/slave configuration to obtain
sensor readings and operate the greenhouse temperature controls. For the master controller an Arduino
Mega 2560 was chosen. The master controller contains the code for the web server which is uploaded
through an Ethernet shield. Additionally this controller transmits control signals and receives sensor data
from the slave controller through a pair of XBee transceivers. For the slave controller an Arduino UNO
R3 was chosen which is responsible for collecting and transmitting data. This includes temperature,
humidity and light intensity readings as well as receiving and relaying control signal input by the user to
the motor controller. The slave controller is also connected to an LCD screen which displays the readings
from the monitoring system locally. A visualization of the system overview can be seen in Figure 1-2.
2
Figure 1-2: System overview.
3
Chapter 2
2 Monitoring System
The main purpose of the monitoring system is to obtain temperature readings from the greenhouse to
be relayed to a remote user. Additionally the system has been expanded to include humidity and light
intensity monitoring as desired parameters. These parameters are fed back into our control system to
allow for automated control. Currently the control system only has the ability to control temperature due
to the limitations of the existing hardware in the greenhouse, but in future projects automated humidity
and lighting control could be readily implemented. The design components of the monitoring system are
broken down into two main sections: hardware and software.
2.1 Hardware
The monitoring system consists of four sensors that interface with the slave Arduino UNO
microcontroller. These sensors include: a temperature sensor, humidity sensor, light intensity sensor and
two contact switches that determine if the window is open or closed. Sensor data is relayed wirelessly to
the Arduino Mega where it is logged and uploaded to the web server.
4
Table 2-1: Arduino UNO specifications.
Microcontroller Atmega328P
Operating Voltage 5V
Supply Voltage 7-12V
DC Cuurent per I/O Pin 20 mA
Flash Memory 32 KB
Clock Speed 16 MHz
5
Figure 2-1: Humidity sensor connections.
6
Figure 2-2: Light sensor connections.
7
Table 2-4: Technical specification of the temperature sensor.
8
the Arduino. Other features include a 4-line 20-character LCD module that has a contrast control nob and
a backlight. The LCD is being used to display our temperature sensor, humidity sensor and our light
sensor directly in the greenhouse room. LCD configuration with the Arduino UNO is shown below.
2.2 Software
The monitoring software is written in the Arduino language and is implemented on the slave
Arduino UNO. The three sensors are polled every 5 seconds and then the values are sent to the master
Arduino Mega via Xbee as well as the LCD. The monitoring software can be found in Appendix A.
9
2.2.2 DFRobot Light Sensor
When the Arduino receives the light sensor value from analog pin 2 it is translated from 0-1024 to
0-100%. This gives the user a comprehensible number that can be used to judge the light intensity in the
room. This value is displayed both on the LCD and Web server.
2.3 Integration
All the sensors are connected to the Arduino UNO via a solder-able prototyping board. In the future
this could be changed to a PCB. The Arduino UNO and the prototyping board are held within a
221x150x60 mm plastic enclosure. The LCD is mounted to the front of the enclosure to give the user
easy access to the greenhouse room conditions. The monitoring system is powered by a 9V 1A power
adapter that plugs into a standard 120V wall outlet. A photo of the enclosure setup can be seen in Figure
2-5.
10
Figure 2-5: Monitoring system enclosure.
11
Chapter 3
3 Control System
The current method for temperature control in the greenhouse involves manually opening and
closing the windows. The main purpose of the control system is to allow the windows to be controlled
remotely using an electric motor to turn the existing manual crank. The secondary purpose is to automate
this process where the windows are opened or closed without human interaction. This is achieved by
using the temperature readings obtained by the monitoring system to determine which control mode is
selected. The automated control mode can be overridden by user commands sent from the user via the
web server.
3.1 Hardware
The control system consists of two major components that interface with the Arduino UNO
microcontroller. These components are: the dc motor used to open and close the greenhouse windows,
and the dc motor controller used to control it. Additionally a 250V ac relay that uses 5V control signals
from the Arduino has been included which could be used to control additional temperature control
devices such as swamp coolers or heaters.
12
Table 3-1: Motor controller logic table.
PWM DIR
LOW X None
The DIR pin controls the direction the motor spins and the PWM pin allows for speed control of the
motor by taking input values from 0-255 from the microcontroller. The logic table can be seen above in
Table 3-1.
13
3.1.4 Denso 730557 7030 L Rotational Motor
The rotational motor was chosen as the replacement for the linear actuator. It is mounted to the
greenhouse wall just underneath the existing manual window crank. The motor is connected to the
existing manual window control by a belt and pulley which turns the crank that opens and closes the
window. The 730557 7030 L Motor can be operated at different speeds which are set by the power
supplied to it. The biggest advantage of a rotational motor over the linear actuator is that the existing
manual control system can still be operated without having to remove the motor. The installed motor
system can be seen below.
14
signals, it sends a control signal to the motor controller to cut power to motor that opens and closes the
window. The contact switches require pull-down resistors to prevent the digital input from floating.
Figure 3-2: Feedback Switches. (a) Window open switch. (b) Close window switch.
3.2 Software
The control system software has two modes of operation: manual and automatic. In manual mode
the control system takes user commands from the web server which are used to operate the temperature
control devices. The automatic mode uses temperature input from the monitoring system to operate the
temperature control devices when the temperature in the greenhouse falls into certain ranges. The control
system code can be seen in Appendix A.
15
operate the temperature controls while off-site. The commands are sent from the master controller to the
slave controller via XBee transceivers.
R1 Closed On Off
R4 Open Off On
By reducing the number of possible operating modes to just four allowed for more efficient code
development. The automatic control mode utilizes a polling method to continuously check which
temperature range the greenhouse falls into. This is done using fall through switch case statements that
are switched by using the current temperature reading obtained from the monitoring system. The logic
structure for the automatic control mode can be seen in the flowchart in Figure 3-3.
16
Figure 3-3: Automated control flowchart.
After the temperature value is updated the program checks to see which range the temperature
falls into. The window status is then checked by reading the feedback switches before any control actions
are taken. Once the window is moved to the proper position, the motor controller is turned off by setting
the parameter winControl LOW which is connected to the PWM pin of the motor controller; this ensures
that the motor is disengaged. Finally the heater and fan controls signals are sent to the 2 channel relay by
setting the parameters fanControl and heatControl to HIGH or LOW.
3.3 Integration
The DC motor controller is enclosed in a167x107x53 mm plastic enclosure. The feedback
switches and DC motor controller signal wires are connected to a solder-able prototyping board also
contained in the plastic enclosure. These wires are connected to the monitoring system enclosure by a
wire harness. The DC motor controller and motor are powered by a 12V 5A power adapter than can plug
into a standard 120V wall outlet. Below is a photo of the control system enclosure setup in Figure 3-4.
17
Figure 3-4: Control system enclosure.
18
Chapter 4
4.1 Hardware
To implement wireless communication between the master and slave controllers XBee
transceivers were chosen. XBees are easy to interface with Arduino due to the availability of Arduino
shields which allow for the transceivers to be directly mounted to the Arduino boards. XBee also meets
the range requirements of the project because a mesh network of XBees can be created where
intermediary points act as routers between the Coordinator XBee and End Point XBee.
The coordinator XBee connects to the Mega Arduino master board through a USB Adaptor. The
USB Adaptor utilizes the TX1 and RX1 pins for serial communication since TX0 and RX0 pins are used
for Ethernet shield communication. This setup is shown below in Figure 4-1. The router XBee
communicates with the Arduino UNO through an XBee shield. The shield connects with RX and TX pins
of the Arduino UNO. The slave setup can be seen below in Figure 4-2. Currently the system does not
have an end point XBee as only a single room is being monitored however this could easily be added to
expand the capabilities of the system.
19
Figure 4-1: Connection between the master controller and XBee USB adaptor
The TX1pin on the Arduino connects to the XBee USB Adaptor RX (Data in)
The RX1pin on the Arduino connects to the XBee USB Adaptor TX (Data out)
The 5V, GND and Reset pins of the Arduino are connected to the 5V, GND and Reset of the USB
Adaptor respectively.
20
4.1.1 Xbee S2
Two XBees are required to meet the needs of the project. The first XBee acts as a coordinator
which receives data and sends control commands to the second XBee. This second XBee functions as a
router which communicates with other end points or routers. Based on the size of the greenhouse, XBee
S2’s were chosen for wireless communication as they have a larger operating range than the lower power
XBee model.
21
4.1.2 XBee USB adaptor
The XBee adaptor is required for two functions, the first being as an adaptor for the configuration
of the XBee parameters. This is done through the XCTU software explained in Section 4.2. The second
function is connecting the coordinator XBee to the Arduino Mega. Using an adaptor instead of a shield
for the coordinator XBee allows the XBee to connect to the TX1 and RX1 pins of the Arduino Mega. This
prevents interference with the XBee and Arduino when compiling code onto the Arduino. Below in
Figure 4-4 is a photo of the Arduino Mega and adaptor setup.
22
4.2 XTCU Software
XCTU software is used to configure the XBee. The USB adaptor is required in order to connect
the XBee to a computer for configuration with the XTCU software. The XCTU software is required to
configure multiple XBees to communicate with each other in a mesh network system. These XBees are
set up to communicate using serial pins on Arduino boards. The parameter configurations can be found in
Appendix E. The configuration setup and software can be seen below in Figure 4-5 and Figure 4-6,
respectively [10].
23
Figure 4-6: XTCU software interface.
24
Table 4-2: Serial data look up table.
In the future, when there are more XBees in the system, our code will need to be modified to
recognize the high and low source address of data being transferred to the master Arduino.
25
Chapter 5
5 Web Server
The web server is hosted on the Arduino Mega. It can be accessed by any internet connected device
such as smart phones or PCs by using the server’s IP address as the URL. The web server is responsible
for sending the received greenhouse sensor values as well as the web interface to the connected users’
browsers. It also receives commands from the users and responses accordingly.
5.1 Hardware
An Ethernet shield is used on the Arduino Mega to enable internet connectivity [11]. An 8GB
micro SD card is plugged in the shield’s on-board SD card slot which is utilized for storing the html web
page file. Ethernet was chosen over Wi-Fi because the University of Manitoba campus uses WPA2-
Enterprise security protocols which are not supported by most Wi-Fi shields. Additionally, Ethernet
provides a more reliable connection, and the existing Ethernet connection in the greenhouse uses wide
area network IP address, which means users can access the IP address from any location on or off
campus.
26
Table 5-1: Arduino Mega specifications.
Microcontroller Atmega1280
Operating Voltage 5V
Supply Voltage 7-12V
DC Cuurent per I/O Pin 40 mA
Flash Memory 128 KB
Clock Speed 16 MHz
5.2 Software
The web server is contained in the Arduino Mega program code. It utilizes the Ethernet library
for connectivity as well as the SD library for accessing the SD card [13]. Once the program is initialized,
it starts to monitor and process client connections continuously. The code for the web server can be found
in Appendix B.
5.2.1 Initialization
The program first ensures that the html files and the password file can be found as the server
cannot function without these files. The program then attempts to establish a connection to the campus
network. Since the campus is using Dynamic Host Configuration Protocol (DHCP), the MAC address is
the only information needed to connect. The Ethernet shield does not have a fixed MAC address. To
establish a connection its MAC address must be set to one that is permitted to connect to the campus’s
network. Finally, the program loads the password file and stores the password in memory for later use.
5.2.2 Polling
Polling method is used to listen to client connections. During each loop, the program tests
whether or not there is a connection request. If a request is found, the program reads its header line and
uses string processing methods on the line to find out the purpose of the request. The server only accepts
certain requests and all other requests will be ignored. Descriptions of valid requests, their header lines
and the corresponding server responses are listed in Table 5-2.
27
Table 5-2: Valid requests look up table.
The flow chart of the web server program is shown below in Figure 5-1. The left part represents
the setup phase and the right part represents the polling phase.
28
Figure 5-1: Web server flow chart.
29
Chapter 6 Web Interface
6 Web Interface
The GUI is located on a web page hosted by the master Arduino which allows users to view and
adjust the greenhouse environment on their browsers. The main advantage of using a web page based user
interface is that it is compatible with most devices compared to an application based interface where
different versions of the application must be created for different platforms (e.g. iOS, Android, etc.).
Another advantage of using a web page based interface is that there is no installation required and the
same piece of code performs the same function the same on different browsers and devices. The URL of
the web interface is the IP address of the master Arduino. Upon accessing the web site the user is
prompted to enter the correct password before they can access the interface page. The main web interface
code can be found in Appendix C.
30
6.2 Login Page
Figure 6-1: The login page on different platforms. (a) Google Chrome running on a PC. (b) Safari running
on an iPhone.
A login page is necessary security feature to ensure the interface can only be accessed by
authorized persons. This is important because improper use of the interface (such as opening a window in
the winter) could result in damage to the plants. When a user connects to the web server, a pop up
window appears prompting the user to enter a password to continue. If the entered password is correct,
the user will be redirected to the user interface. The password is stored inside “password.txt” file in the
SD card on the server-side. The password can be set by the administrator by simply changing the
“password.txt” file. The login page code can be found in Appendix D. The login page is shown on
different interfaces above in Figure 6-1.
31
6.3 Interface Page
Figure 6-2: The interface page on different platforms. (a) Internet Explorer running on a PC.
(b) Google Chrome running on an iPhone
The interface page is where users can view and control the greenhouse environment. The page is
programmed so that in every 5 seconds, the page sends a GET /para request to the web server, the web
server responds by sending back a string containing the temperature, humidity and light intensity values
as well as the control mode, window, fan and heat status. The interface page then extracts and displays
the values. Buttons are used to input user commands including the control mode setting as well as the
window, fan and heat controls. Each time a button is pressed, a block of program code is executed and a
corresponding HTTP GET request is sent to the server. The request headers are shown in Table 5-2. The
program flow can be visualized below in Figure 6-3.
32
Start
Password Y
Enter password Load interface page
correct?
5 seconds
passed
At the bottom half of the interface page, a weather widget provided by accuweather.com is
included. It would be convenient because when the user is using window control to adjust room
temperature, the user might want to know the weather outside the greenhouse. This widget also shows
the weather in the next two days and the next five hours which the user might be interested in.
accuweather.com is one of the best websites that provides free reliable and accurate weather widget.
Figure 7-3: The weather widget immediately below Figure 7-2 (a)
33
6.4 Data Logging
Every 5 seconds data is pulled from the sensor variables and converted to strings. These strings are
concatenated into CSV format and written to a text file on the 8GB micro SD card. The user can then
remove the SD card and easily transfer the data to be viewed in Excel. Every five seconds approximately
25 characters are written to the text file which is equivalent to 25 bytes of data. At this rate you could save
50 years of data before filling the SD card capacity.
34
Chapter 7
7 Design Changes
Throughout the course of the project there were many changes made to both the hardware and
software in order to achieve a fully functional design. These changes were made in response to problems
discovered in the design, prototyping, integration and testing phases.
35
7.1.3 Contact Switches
In the final design two contract switches are used to determine if the window is fully open or fully closed.
These switches were easily mounted near the rotating bar and tripped when a tab attached to that is
attached to the existing manual window controls. This removed the need to have any sensors outside the
building where they would be exposed to the elements. By using these switches the possibility in error of
detecting the window position that could arise from using the other methods was greatly reduced. This
reduced the risk of damaging the greenhouse windows by opening them too far.
36
Chapter 8
8 Conclusion
The purpose of this project was to design and build a working prototype monitoring and control
system for one room of the Buller greenhouse. This system allows a user to obtain temperature, humidity
and light intensity readings as well as send temperature control commands remotely. This was achieved
using Arduino microcontrollers and XBee wireless transceivers. The processes of hardware design,
software design, integration, and testing of the prototype system have been described in this report. The
project was broken down into four main sections: monitoring, control, wireless communication and the
web server/GUI. Each individual section was unit tested before it was integrated into the final design. A
fully integrated prototype was built and bench tested to ensure proper functionality before installation into
the greenhouse. The system performed as designed and was able to remotely monitor and control the
greenhouses temperature. Through the successful testing of the prototype it has been demonstrated that
this system could be expanded to cover all rooms in the greenhouse.
37
References
[1] (2016) Arduino, “Arduino Uno & Arduino Genuino”. [Online]. Available:
https://www.arduino.cc/en/Main/ArduinoBoardUno
[5](2016) Cytron Technologies, “MD10C Enhanced 10Amp DC Motor Driver”. [Online]. Available:
http://www.robotshop.com/media/files/PDF/user-manual-md10c-v2.pdf
[7](2016) Princess Auto, “12V DC Linear Actuator Instruction Manual”. [Online]. Available:
http://images11.palcdn.com/hlr-system/Documents/85/850/8507/8507840_Manual.pdf
[10]XCTU Configuration & Test Utility Software User Guide. [Online]. Available:
https://docs.digi.com/display/XCTU/Download+and+install+XCTU [Accessed: March 1, 2016].
38
[14] JQuery. Ajax API Documentation [Online]. Available: http://api.jquery.com/jquery.ajax/ [March 1
2016]
39
Appendix A - Slave Arduino Code
//**Libraries
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
//LCD
#define Rs_pin 0
#define Rw_pin 1
#define En_pin 2
#define BACKLIGHT_PIN 3
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
40
#define D7_pin 7
LiquidCrystal_I2C lcd(I2C_ADDR, En_pin, Rw_pin, Rs_pin, D4_pin, D5_pin, D6_pin, D7_pin); //LCD setup
//This section of code maps the temperature ranges for the switch case statements and temp alarm
int manualOverride = LOW ; //signal coming from web server when user wants to operate controls manually
//variables
int mode = 0;
int winCommand = 0;
int lightSensor = 0;
41
int type = 0;
int windows = 0;
void setup() {
Serial.begin(9600);
pinMode(winControl, OUTPUT);
pinMode(dirControl, OUTPUT);
pinMode(fanControl, OUTPUT);
pinMode(heatControl, OUTPUT);
pinMode(winSensorOpenSwitch, INPUT);
pinMode(winSensorClosedSwitch, INPUT);
digitalWrite(fanControl, HIGH);
digitalWrite(heatControl, HIGH);
pinMode(tempAlarm, OUTPUT);
dht.begin();
// LCD Backlight ON
lcd.setBacklightPin(BACKLIGHT_PIN, POSITIVE);
lcd.setBacklight(HIGH);
lcd.print("Greenhouse");
42
//********OPEN WINDOW FUNCTION**************
digitalWrite(winControl, HIGH);
break;
digitalWrite(winControl, LOW);
digitalWrite(winControl, HIGH);
Serial.println("Window Closing");
break;
Serial.println("WIndow is closed");
digitalWrite(winControl, LOW);
range = 0;
range = 1;
43
range = 2;
range = 3;
switch (range) {
digitalWrite(tempAlarm, HIGH);
else {
digitalWrite(tempAlarm, LOW);
closeWindow(winSensorClosed);
digitalWrite(winControl, LOW);
digitalWrite(fanControl, HIGH);
digitalWrite(heatControl, LOW);
break;
closeWindow(winSensorClosed);
digitalWrite(winControl, LOW);
digitalWrite(fanControl, HIGH);
digitalWrite(heatControl, HIGH);
break;
44
case 2: //too warm
openWindow(winSensorOpen);
digitalWrite(winControl, LOW);
//digitalWrite(winControl,LOW);
digitalWrite(fanControl, LOW);
digitalWrite(heatControl, HIGH);
break;
openWindow(winSensorOpen);
digitalWrite(winControl, LOW);
digitalWrite(fanControl, LOW);
digitalWrite(heatControl, HIGH);
break;
if (heatButton == HIGH) {
digitalWrite(heatControl, HIGH);
if (fanButton == HIGH) {
digitalWrite(fanControl, HIGH);
if (openWindowButton == HIGH) {
openWindow(winSensorOpen);
45
}
if (closeWindowButton == HIGH) {
closeWindow(winSensorClosed);
float getTemp() {
byte data[12];
byte addr[8];
if ( !ds.search(addr)) {
ds.reset_search();
return -1000;
return -1000;
return -1000;
ds.reset();
ds.select(addr);
ds.select(addr);
data[i] = ds.read();
46
ds.reset_search();
return TemperatureSum;
void loop() {
lightSensor = analogRead(LIGHTPIN);
temp = tempDS;
winSensorOpen = digitalRead(winSensorOpenSwitch);
winSensorClosed = digitalRead(winSensorClosedSwitch);
Serial.println(lightSensor);
Serial.println("101");
Serial.println(tempDS);
Serial.println("102");
Serial.println(hum);
Serial.println("103");
Serial.println(lightMapped);
Serial.println("104");
if (winSensorOpen == true) {
else {
47
Serial.println(3); //window is moving
Serial.println("105");
if (mode == 1) {
else if (mode == 0) {
if (Serial.available()) {
type = Serial.parseInt();
winCommand = 1;
Serial.println("Window open");
winCommand = 0;
Serial.println("Window close");
if (type == 106) {
if (type == 107) {
if (mode == 1) {
manualOverride = HIGH;
Serial.println("Manual Mode");
if (mode == 0) {
manualOverride = LOW;
Serial.println("Auto Mode");
48
}
if (winCommand == 1) {
closeWindowButton = LOW;
if (winCommand == 0) {
openWindowButton = LOW;
//LCD Printing
prevMillis = curMillis;
lcd.print("Temp: ");
lcd.print(temp);
lcd.print(" C");
lcd.print("Humidity: ");
lcd.print(hum);
lcd.print(" %");
lcd.setCursor(0, 3);
lcd.print("Light: ");
lcd.print(lightMapped);
lcd.print(" %");
if (manualOverride == HIGH) {
manualControl(winSensorOpen, winSensorClosed);
autoControl(winSensorOpen, winSensorClosed);
49
Appendix B - Master Arduino Code
#include <SPI.h>
#include <Ethernet.h>
#include <SD.h>
#include <Client.h>
#define REQ_BUF_SZ 25
#define __USE_DHCP__
EthernetServer server(80);
File webFile;
char HTTP_req[REQ_BUF_SZ] = {0}; // buffered HTTP request stored as null terminated string
float temp = 0;
float humi = 0;
int window = 0;
50
int fan = 0; //0 - off, 1 - on
int type;
int winstatus = 0;
float light = 0;
//Delay variables
/************************************************
* setup *
************************************************/
void setup() {
Serial.begin(9600);
Serial1.begin(9600);
Serial.println("Initializing SD card...");
if (!SD.begin(4)) {
if (!SD.exists("pass.htm")) {
if (!SD.exists("password.txt")) {
51
}
if (!SD.exists("index.htm")) {
Ethernet.begin(mac);
#else
#endif
server.begin();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
ip = Ethernet.localIP();
#endif
int i = 0;
while (passFile.available()) {
password[i] = passFile.read();
i++;
webFile.close();
Serial.println(password);
52
/************************************************
* loop *
************************************************/
void loop() {
//datalogging variables
unsigned long currentMillis = millis(); //used for delays throughout the code
int sensors[3]; //array that holds the sensor data received from the xbee
String currentTime = "1/15/2016 10:51,"; //temporary place holder for current time, will be later pulled from NTP
if (Serial1.available())
type = (Serial1.parseInt());
if (type == 101) {
temp = (Serial1.parseFloat());
if (type == 102) {
humi = (Serial1.parseFloat());
} if (type == 103) {
light = (Serial1.parseFloat());
if (type == 104) {
if (type == 105) {
if (winstatus == 1) {
Serial1.println(104); //Open
if (winstatus == 0) {
Serial1.println(105); //Close
if (mode == 1) {
53
}
if (mode == 0) {
sensors[0] = (int)light;
sensors[1] = (int)humi;
sensors[2] = (int)temp;
previousMillis = currentMillis;
sdWrite(dataString);
if (client) {
//Serial.println("new client");
while (client.connected())
54
if (req_index < (REQ_BUF_SZ - 1)) {
req_index++;
//Serial.print(c);
Serial.println(HTTP_req);
client.println("Content-Type: text/html");
client.println("Connnection: close");
client.println();
client.println("interface");
else {
client.println("");
client.println("Content-Type: text/html");
client.println("Connnection: close");
client.println();
55
if (!(humi < 100) && (humi > 0)) humi = -99;
sendHeader_text(client);
String paraString = String(temp) + " " + String(humi) + " " + String(light) + " " + String(mode) + " " + String(winstatus) +
" " + String(fan) + " " + String(heat);
client.println(paraString);
mode = 0;
Serial.println("Auto mode");
if (client.connected())
sendHeader_text(client);
client.println(mode);
mode = 1;
Serial.println("Manual mode");
if (client.connected())
sendHeader_text(client);
client.println(mode);
winstatus = 1;
Serial.println("Window open");
if (client.connected())
sendHeader_text(client);
client.println(window);
winstatus = 0;
56
Serial.println("Window close");
if (client.connected())
sendHeader_text(client);
client.println(window);
if (client.connected())
sendHeader_text(client);
client.println(fan);
if (client.connected())
sendHeader_text(client);
client.println(fan);
if (client.connected())
sendHeader_text(client);
client.println(heat);
if (client.connected())
sendHeader_text(client);
client.println(heat);
57
if (webFile) {
while (webFile.available()) {
webFile.close();
client.stop();
req_index = 0;
StrClear(HTTP_req, REQ_BUF_SZ);
break;
// every line of text received from the client ends with \r\n
if (c == '\n') {
currentLineIsBlank = true;
else if (c != '\r') {
currentLineIsBlank = false;
} // end if (client.available())
client.stop();
//Serial.println("client disconnected");
client.println("text/plain; charset=us-ascii");
58
client.println("Connnection: close");
client.println();
/************************************************
************************************************/
str[i] = 0;
char found = 0;
char len;
len = strlen(str);
return 0;
if (str[index] == sfind[found]) {
found++;
if (strlen(sfind) == found) {
return 1;
else {
59
found = 0;
index++;
return 0;
//Write to SD Card
// Write Function
if (dataFile) {
dataFile.println();
dataFile.print(inputString);
dataFile.close();
else {
dString += String(sensor);
if (i < 2) {
dString += ",";
return dString;
60
Appendix C – Web Interface Code
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
</head>
<body>
<div id="chart_div"></div>
61
<script>
var time = 0;
var humi = 0;
var light = 0;
setInterval(function() {
if (data.localeCompare("updating") == 0) {
else {
if (parseInt(para[3]) == 0) {
document.getElementById("controlModeButton").firstChild.data = "Switch to
Manual";
else if (parseInt(para[3]) == 1) {
document.getElementById("controlModeButton").firstChild.data = "Switch to
Auto";
if (parseInt(para[4]) == 0) {
document.getElementById("windowStat").innerHTML = "window
status:closed";
62
document.getElementById("windowButton").firstChild.data = "open window";
else if (parseInt(para[4]) == 1) {
document.getElementById("windowStat").innerHTML = "window
status:open";
if (parseInt(para[5]) == 0) {
else if (parseInt(para[5]) == 1) {
if (parseInt(para[6]) == 0) {
else if (parseInt(para[6]) == 1) {
array.push([time, temp]);
array.shift();
drawBasic(array);
time += timeInterval;
$('#my_div').sendRq("para", setStatus);
}, timeInterval*1000);
(function( $ ){
63
$.ajax(rq).done(function( data ) {func(data);}).fail(function() {func("updating");});
return this;
};
})( jQuery );
function reservedForLater(data) {
function controlModeButtonClicked() {
if (document.getElementById("controlModeButton").firstChild.data.localeCompare("Switch to Auto") == 0)
{
$('#my_div').sendRq("Auto", reservedForLater(1));
else {
$('#my_div').sendRq("Manual", reservedForLater(1));
function windowButtonClicked() {
if (document.getElementById("windowButton").firstChild.data.localeCompare("press to open") == 0) {
$('#my_div').sendRq("windowOpen", reservedForLater(1));
else {
$('#my_div').sendRq("windowClose", reservedForLater(1));
function fanButtonClicked() {
if (document.getElementById("fanButton").firstChild.data.localeCompare("turn on") == 0) {
$('#my_div').sendRq("fanOn", reservedForLater(1));
else {
$('#my_div').sendRq("fanOff", reservedForLater(1));
function heatButtonClicked() {
if (document.getElementById("heatButton").firstChild.data.localeCompare("turn on") == 0) {
$('#my_div').sendRq("heatOn", reservedForLater(1));
64
}
else {
$('#my_div').sendRq("heatOff", reservedForLater(1));
function drawBasic() {
data.addColumn('number', 'seconds');
data.addColumn('number', '°C');
data.addRows(array);
var options = {
hAxis: {
title: 'Time'
},
vAxis: {
title: 'Temperature'
};
chart.draw(data, options);
</script>
</body>
</html>
65
Appendix D – Website Login Code
<!DOCTYPE html>
<html>
<body onload="passPrompt()">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquerymobile/1.4.5/jquery.mobile.min.js"></script>
<script>
function passPrompt() {
var pass = prompt("To access greenhouse web interface, please enter password and press OK:");
if (pass != null) {
$('#my_div').sendRq("password_" + pass);
(function( $ ){
$.fn.sendRq = function(rq) {
$.ajax(rq).done(function(data){location.replace(data);});
return this;
};
})( jQuery );
</script>
</body>
</html>
66
Appendix E - XBee Parameter Configuration
ID PAN ID:1234
ID PAN ID:1234
67
Appendix F - Budget
68