Download as pdf or txt
Download as pdf or txt
You are on page 1of 126

DESIGN AND FABRICATION OF A GREENHOUSE MONITORING AND

CONTROL SYSTEM BASED ON GLOBAL SYSTEM FOR MOBILE


COMMUNICATION AND BLUETOOTH

NYAGA STEPHEN GITONGA (B.Ed (Sc))

I56/CE/28340/2013

A THESIS SUBMITTED IN PARTIAL FULFILLMENT OF THE

REQUIREMENTS FOR THE AWARD OF THE DEGREE OF MASTERS OF

SCIENCE (ELECTRONICS AND INSTRUMENTATION) IN THE SCHOOL

OF PURE AND APPLIED SCIENCES OF KENYATTA UNIVERSITY

JANUARY 2020
i

DECLARATION

This Thesis is my original work and has not been presented at other awards of degree

at any other University or for any award.

Nyaga Stephen Gitonga Signature………………….. Date…………………

I56/CE/28340/2013

Department of Physics

Kenyatta University

This thesis has been submitted with our approval as University supervisors:

Dr. Mathew Munji Signature………….………... Date………………….

Department of Physics

Kenyatta University

Dr. Raphael Nyenge Signature………….………... Date…………………..

Department of Physics

Kenyatta University
ii

DEDICATION

This study is wholeheartedly dedicated to my wife Weyanga, my daughter Mwende,

my friend Nyongesa, my mum, Margret Marigu and my late dad, Alison Peter Nyaga.
iii

ACKNOWLEDGEMENTS

Praise to Almighty God for guiding and protecting me throughout this work. I am

grateful to my supervisors Dr. Mathew Munji and Dr. Raphael Nyenge for their valued

mentorship and advice throughout this study. Thanks to all technical staff within the

department of Physics, particularly Mr. Fred Mudimba, the chief laboratory technician,

for all of their help. A deep thank to my colleague Mr. Moses Irungu for his wonderful

support and academic mentoring during my research. I fully thank all the persons who

have been involved in this thesis. Thanks a million to my family for their

encouragement throughout the studies.


iv

TABLE OF CONTENTS

DECLARATION ............................................................................................................I

DEDICATION .............................................................................................................. II

ACKNOWLEDGEMENTS ......................................................................................... III

LIST OF FIGURES .....................................................................................................IX

LIST OF TABLES ..................................................................................................... XII

ABBREVIATIONS AND ACRONYMS ................................................................. XIII

ABSTRACT............................................................................................................... XV

CHAPTER ONE .......................................................................................................... 1

INTRODUCTION ....................................................................................................... 1

1.1 Background to the Study.......................................................................................... 1

1.2 Statement of the Problem ......................................................................................... 3

1.3 Research Objectives ................................................................................................. 3

1.3.1 General Objective .............................................................................................. 3

1.4 Rationale for the Research ....................................................................................... 4

CHAPTER TWO ......................................................................................................... 5

LITERATURE REVIEW ........................................................................................... 5

2.1 INTRODUCTION ................................................................................................... 5

2.2 Greenhouse Technology .......................................................................................... 5

2.3 Technologies for Greenhouse Automation Processes.............................................. 6

2.3.1 Bluetooth ........................................................................................................... 6

2.3.2 Wi-Fi ................................................................................................................. 7

2.3.3 ZigBee ............................................................................................................... 7

2.4 Existing Greenhouse Electronic Management Systems .......................................... 8


v

CHAPTER THREE ................................................................................................... 14

RESEARCH METHODOLOGY ............................................................................. 14

3.1 Introduction ............................................................................................................ 14

3.2 Hardware Design ................................................................................................... 14

3.3 Sensing Unit ........................................................................................................... 15

3.3.1 DHT11 Sensor Module ................................................................................... 16

3.3.1.1 Functioning Theory of the Humidity Sensor ............................................ 18

3.3.1.2 Functioning Theory of the Temperature Sensor ....................................... 19

3.3.2 LDR Sensor ..................................................................................................... 21

3.3.2.1 Functioning Theory of the LDR Sensor ................................................... 22

3.3.2.2 Features of the LDR Sensor...................................................................... 22

3.4 Processing Unit ...................................................................................................... 24

3.4.1 ATmega328 Microcontroller Chip .................................................................. 24

3.4.2 Internal Architecture of the ATmega328 Microcontroller .............................. 26

3.5 Arduino Microcontroller Board ............................................................................. 28

3.6 Wireless Communication Unit............................................................................... 32

3.6.1 Phone System .................................................................................................. 32

3.6.2 Structure of the Phone Cellular Network ........................................................ 32

3.6.3 GSM SIM800L Module .................................................................................. 34

3.6.4 HC05 Bluetooth Module ................................................................................. 36

3.7 Displaying and Indicating Unit .............................................................................. 37

3.7.1 HD44780U LCD Module ................................................................................ 37

3.8 Actuation Unit ........................................................................................................ 38

3.8.1 Relay Module .................................................................................................. 38

3.8.2 Actuators ......................................................................................................... 40


vi

3.9 Prototype Greenhouse Schematic Design .............................................................. 41

3.9.1 Interfacing ATmega328 Microcontroller with LCD Module ......................... 42

3.9.2 GSM SIM800L Interface to ATmega328 Microcontroller ............................. 43

3.9.3 HC05 Bluetooth Module Interface to ATmega328 Microcontroller .............. 44

3.9.4 DHT11 Sensor Interface to ATmega328 Microcontroller .............................. 44

3.9.5 LDR Sensor Interface to ATmega328 Microcontroller .................................. 45

3.9.6 Relay Module Interface to ATmega328 Microcontroller ............................... 46

3.10 Printed Circuit Board ........................................................................................... 47

3.11 Software Design ................................................................................................... 48

3.11.1 Introduction ................................................................................................... 48

3.11.2 System Program ............................................................................................ 49

3.11.3 Program Development................................................................................... 50

3.11.4 Software Structure ......................................................................................... 51

3.11.5 AT Commands .............................................................................................. 54

CHAPTER FOUR...................................................................................................... 55

RESULTS AND DISCUSSIONS .............................................................................. 55

4.1 Introduction ............................................................................................................ 55

4.2 Experiments and Results ........................................................................................ 55

4.2.1 Testing the LDR Sensor .................................................................................. 55

4.2.2 Testing the DHT11 Sensor .............................................................................. 58

4.2.3 Testing the HD44780U LCD Module ............................................................. 62

4.2.4 Testing the GSM SIM800L Module ............................................................... 63

4.2.5 Testing the HC05 Bluetooth ............................................................................ 65

4.2.6 Testing the 4 Channel 5 V Relay Module ....................................................... 65

4.2.7 Testing the LM2596 Power Regulator ............................................................ 66


vii

4.3 Program Test .......................................................................................................... 68

4.4 Testing the Designed Prototype Greenhouse ......................................................... 69

4.4.1 Testing Transmission of the GSM SIM800L .................................................. 69

4.4.2 Testing Range the HC05 Bluetooth ................................................................ 70

4.4.3.1 Performance Parameters of the Prototype Greenhouse ............................ 71

4.4.3.2 Monitoring and Control Experiments ....................................................... 74

CHAPTER FIVE ....................................................................................................... 81

CONCLUSIONS AND RECOMMENDATIONS................................................... 81

5.1 Conclusions ............................................................................................................ 81

5.2 Recommendations .................................................................................................. 81

5.3 Recommendations for further research .................................................................. 82

REFERENCES........................................................................................................... 83

APPENDICES ............................................................................................................ 85

APPENDIX A: Flow Chart of the Prototype Greenhouse Program ........................ 85

APPENDIX B: ATmega328 Pins Configuration ..................................................... 87

APPENDIX C: Code Listing 1 ................................................................................ 88

APPENDIX D: Code Listing 2 ................................................................................ 89

APPENDIX E: Code Listing 3 ................................................................................. 90

APPENDIX F: Code Listing 4 ................................................................................. 91

APPENDIX G: Code Listing 4 ................................................................................ 92

APPENDIX H: Code Listing 5 ................................................................................ 93

APPENDIX I: Code Listing 6 .................................................................................. 94

APPENDIX J: Code Listing 7 .................................................................................. 95

APPENDIX K: Entire Prototype Greenhouse Program ........................................... 96

APPENDIX L: Internal Architecture of the ATmega328 Microcontroller ............ 103


viii

APPENDIX M: SIM800L GSM Module Data Sheet ............................................ 104

APPENDIX N: ATmega328 Microcontroller Data Sheet ..................................... 105

APPENDIX O: LM2596 Power Regulator Data Sheet .......................................... 107

APPENDIX P: Schematic of the Prototype Greenhouse System .......................... 108

APPENDIX Q: Light Dependent Resistor Data Sheet .......................................... 109


ix

LIST OF FIGURES

Figure 3.1: The Prototype Greenhouse Block Diagram............................................... 15

Figure 3.2: DHT11 Sensor ........................................................................................... 17

Figure 3.3: Components of DHT11 Sensor ................................................................. 18

Figure 3.4: Humidity Sensing Component .................................................................. 18

Figure 3.5: Temperature Sensing Component ............................................................. 19

Figure 3.6: Thermistor Configuration .......................................................................... 20

Figure 3.7: LDR Sensor ............................................................................................... 21

Figure 3.8: Structure LDR Sensor ............................................................................... 23

Figure 3.9: LDR Sensor Configuration ........................................................................ 23

Figure 3.10: ATmega 328 Microcontroller Pins .......................................................... 25

Figure 3.11: ATmega328 CPU Harvard Architecture ................................................. 26

Figure 3.12: Arduino Uno Board ................................................................................. 29

Figure 3.13: Arduino Uno Board Schematic ............................................................... 31

Figure 3.14: GSM Network Structure .......................................................................... 33

Figure 3.15: SIM800L Module .................................................................................... 34

Figure 3.16: LM2596 Voltage Regulator..................................................................... 35

Figure 3.17: LM2596 Voltage Regulator Schematic ................................................... 35

Figure 3.18: HC05 Bluetooth Module Pins ................................................................. 36

Figure 3.19: HD44780U LCD Module ........................................................................ 37

Figure 3.20: LCD Module Architecture....................................................................... 38

Figure 3.21: 5 Volt 4 Channel Relay Module .............................................................. 39

Figure 3.22: Relay Module Schematic......................................................................... 40

Figure 3.23: LCD Interface to ATmega328 Microcontroller ...................................... 42

Figure 3.24: GSM SIM800L Interface to ATmega328 Microcontroller ..................... 43


x

Figure 3.25: Bluetooth Interface to ATmega328 Microcontroller............................... 44

Figure 3.26: DHT11 Sensor Interface to ATmega328 Microcontroller ...................... 45

Figure 3.27: Pin Configuration for DHT11 Sensor ..................................................... 45

Figure 3.28: LDR Sensor Interface to ATmega328 Microcontroller .......................... 46

Figure 3.29: Relays Interface to ATmega328 Microcontroller ................................... 46

Figure 3.30: PCB Circuit Maker .................................................................................. 47

Figure 3.31: Arduino Environment .............................................................................. 50

Figure 3.32: Arduino Software Flowchart ................................................................... 51

Figure 4.1: Interfacing the LDR to Arduino ................................................................ 57

Figure 4.2: LDR Sensor Output on Arduino Serial Monitor ....................................... 57

Figure 4.3: Interfacing the DHT11 to Arduino ............................................................ 58

Figure 4.4: DHT11 Data Output on Arduino Monitor ................................................. 58

Figure 4.5: Comparisons of Humidity and Temperature inside Laboratory ................ 60

Figure 4.6: Comparisons of Humidity and Temperature outside Laboratory .............. 61

Figure 4.7: Comparisons of Humidity and Temperature inside Box ........................... 62

Figure 4.8: Interfacing the LCD to Arduino ................................................................ 62

Figure 4.9: Sensors and LCD Module during Test ...................................................... 63

Figure 4.10: GSM SIM800L SIM Card ....................................................................... 63

Figure 4.11: Interfacing the GSM SIM800L to Arduino ............................................. 64

Figure 4.12: Testing GSM SIM800L output on Arduino IDE .................................... 64

Figure 4.13: Interfacing the HC05 Bluetooth to Arduino ............................................ 65

Figure 4.14: Interfacing the Relay Module to Arduino ............................................... 65

Figure 4.15: Designed Greenhouse System on the PCB.............................................. 67

Figure 4.16: Complete Designed Prototype Greenhouse minus Cover ....................... 68

Figure 4.17: Configuring the Arduino Ports ................................................................ 69


xi

Figure 4.18: Relay Condition for Prototype Greenhouse Temperature ....................... 75

Figure 4.19: Prototype Greenhouse Temperature Graphs ........................................... 76

Figure 4.20: Prototype Greenhouse Humidity Graphs ................................................ 78

Figure 4.21: Relay Condition for Prototype Greenhouse Humidity ............................ 78

Figure 4.22: Prototype Greenhouse Light Intensity Graphs ........................................ 80


xii

LIST OF TABLES

Table 3.1: Technical Specification of the LDR Sensor ............................................... 21

Table 3.2: Arduino Analog Pins .................................................................................. 30

Table 3.3: Arduino Digital Pins ................................................................................... 31

Table 3.4: Key Characteristics of the GSM SIM800L ................................................ 35

Table 3.5: LCD/ATmega328 Pin Mapping ................................................................. 43

Table 3.6: SMS AT Commands ................................................................................... 54

Table 4.1: Light Intensity From Different Sources ...................................................... 56

Table 4.2: Humidity and Temperature Data inside the Laboratory ............................. 59

Table 4.3: Humidity and Temperature Data outside Laboratory ................................. 60

Table 4.4: Humidity and Temperature Data inside Box .............................................. 61

Table 4.5: LM2596 Regulator Output Voltage versus Resistances ............................. 66

Table 4.6: Comparisons of the LCD and GSM Readings ............................................ 70

Table 4.7: HC05 Bluetooth Range ............................................................................... 71

Table 4.8: Temperature and Humidity According to Sensor Positions ....................... 73

Table 4.9: Performance Parameters of the Prototype Greenhouse .............................. 74

Table 4.10: Prototype Greenhouse Data for Temperature ........................................... 75

Table 4.11: Prototype Greenhouse Data for Humidity ................................................ 77

Table 4.12: Prototype Greenhouse Data for Light Intensity ........................................ 79


xiii

ABBREVIATIONS AND ACRONYMS

ADC Analogue to Digital Converter

ALU Arithmetic and Logic Unit

API Android Platform Includes

AVR Advanced Virtual RISC

CPU Central Processing Unit

DIN Data In

EEPROM Electrically Erasable Programmable Read Only Memory

GEC Greenhouse Environmental Controller

GSM Global System for Mobile Communication

IDE Integrated Development Environment

IEEE Institute of Electrical and Electronics Engineers

ISM Industrial, Scientific and Medical

LabVIEW Laboratory Virtual Instrumentation Engineering Workbench

LCD Liquid Crystal Display

LDR Light Dependent Resistor

MISO Master Input Slave Output

MOSI Master Output Slave Input

PWM Pulse Width Modulation

RF Radio Frequency

RISC Reduced Instruction Set Computer

RTC Real Time Clock

RX Receiver

SHF Super High Frequency

SIM Subscriber Identity Module


xiv

SMS Short Message Service

SRAM Static Random Access Memory

SPI Serial Peripheral Interface

TX Transmitter

Wi-Fi Wireless Fidelity

WLAN Wireless Local Area Network

UHF Ultra High Frequency

USART Universal Synchronous Asynchronous Receiver/Transmitter


xv

ABSTRACT

Greenhouse technology should be embraced as a way of minimizing food insecurity in


Kenya. The insecurity is brought about by climate uncertainties. Greenhouses have
attempted to solve this problem by enclosing crops in a climatically controlled
environment. Each greenhouse has distinct parameters. Data on these parameters need
to be collected at regular intervals. Depending on the type of crop, these parameters
need to be controlled within the specified limits to achieve the maximum efficiency and
yields. In the past, greenhouses utilized electromechanical devices such as thermostats
to monitor and control the environment. Mechanical systems lack the flexibility and
precision required for greenhouse control. Some modern greenhouses use computers to
control the environment. Computers based controllers are station based, bulky and
costly. In this study a wireless prototype greenhouse monitoring and control system that
is flexible, cheap, easy to maintain and easy to assemble was developed and
implemented. The general objective of this research work was to design, fabricate and
implement a microcontroller-based prototype to monitor and control greenhouse
parameters using sensors, SMS technology and Bluetooth signals. The hardware
consisted of ATmega328 microcontroller, Global System for Mobile communication
(GSM) SIM800L module, HC05 Bluetooth module, HD44780U Liquid Crystal Display
(LCD) module, 5 volt 4 channel relay module, Light dependent resistor (LDR) sensor
and digital humidity and temperature (DHT11) sensor. The LDR sensor was utilized to
measure light intensity while the DHT11 sensor was utilized to measure humidity and
temperature levels in the prototype greenhouse. The DHT11 and LDR sensors, the
relay, the LCD, the GSM and the Bluetooth modules were interfaced to the ATmega328
microcontroller. Through Arduino software, a program was written in C language,
developed and uploaded to the ATmega328 microcontroller to run the greenhouse
prototype. The program is designed to operate in automatic or manual mode. In
automatic mode, the microcontroller constantly monitors the digitized values from the
sensors and compares them with the optimized values and checks if any control
procedures needs to be taken. In manual mode, the system could be operated wirelessly
by use of GSM or Bluetooth module. The designed prototype greenhouse system is able
to measure temperature, humidity and illuminance levels in the prototype greenhouse
and display the values on the LCD. The system transmits the sensor measured values
to owner’s phone via Bluetooth or a GSM and keeps these parameters at optimum levels
by use of two fans, heater, bulb and a sprinkler. The GSM module is used for remotely
monitoring and controlling the devices via a smart phone by sending and receiving
Short Messaging Service via GSM network. If the user is in the vicinity of the
prototype, the Bluetooth and a software installed in the smart phone provides a wireless
link between the prototype and the cell phone. This project therefore provides a cost
effective and efficient means of monitoring and controlling greenhouse parameters. In
addition the system allows mobility during monitoring and control process. The
reliability of the designed system can be exploited to build a network of such
monitoring and control systems for several greenhouses. A website can be incorporated
in the designed system to monitor the actual greenhouse values and save the data in an
online database for future reference. The designed prototype greenhouse can be applied
in the agricultural sector in the design and implementation of greenhouses.
1

CHAPTER ONE

INTRODUCTION

This study designed and implemented a microcontroller-based system that

automatically monitors and controls greenhouse parameters and maintains them within

the predefined optimum range. The Bluetooth and GSM based remote wireless

automatic monitoring system provide mobility during the monitoring and control

process.

1.1 Background to the Study

In Kenya, over 10 million people are food insecure, with the majority of them relying

on food relief (Wanjiru et al.,2014). This is because Kenya is a rain fed country and

over 80% of her landmass falls under arid and semi-arid climate which is characterized

by droughts almost throughout the year (Huho and Kosonei, 2010). On occasions where

there is rain, floods occur. This makes Kenya prone to climate vagaries. These climate

uncertainties have led to severe food shortage and starvation. One possible solution to

achieving food security is to use greenhouses, which enable the farmer to control the

growth conditions thereby ensuring maximum crop yield throughout the year.

Greenhouses could be automated by utilizing microcontroller-based systems. These

systems would monitor and control greenhouse parameters such as pH of soil, soil

moisture, light intensity, relative humidity and temperature. The microcontroller would

keep them at optimum levels on a continuous 24-hour basis.


2

In automated greenhouses, it is possible to manipulate crop production for certain

economic advantages. For instance, a farmer may lower temperature to delay flowering.

This is so that the flowers are ready for picking on a particular day; say on a Monday

rather than having them picked over a weekend where he might pay more to the

workers. He may also plan to harvest the flowers on days where there are cheaper flights

(Plaksina and Raush, 2005).

Technology has redefined communication in many advantageous ways. Mobile

technology has led to the coining of the term “global village” which can be seen through

the fact that almost every adult nowadays owns a mobile phone and the decreasing cost

of such devices over the years. An individual can be contacted at any time by the use

of a mobile phone. Nowadays, cell phones are being used for more than making calls

and sending messages; with the technological advancement, cell phone use has changed

and various functions such as camera, radio or remote to control electrical appliances

are standard. Exploiting cell phone’s capabilities can lead to new and profitable

masterpieces.

Short Message service (SMS) is a very popular means of communication. The only

disadvantage is that delivery of messages in real time depends on the phone’s network

reception. This concept of instant messaging is what was used, in this research work, to

prototype a system that acts as a platform for receiving or sending messages. The

messages are commands sent to a microcontroller to control various greenhouse

parameters or messages sent by microcontroller showing status of greenhouse

parameters. This minimizes the needed work force and maximizes the output per

greenhouse. With the use of this prototype it is not necessary for the user to be always
3

at the greenhouse to do management practices. In this study, a prototype system based

on ATmega328 microcontroller that automatically monitors and controls temperature,

relative humidity and light luminance in a greenhouse using sensors, SMS technology

and Bluetooth signals was designed and implemented.

1.2 Statement of the Problem

Different crops need different conditions to ensure maximum yield. Left to the varying

and unpredictable natural conditions the production is very poor. The solution to this is

the use of greenhouse. The greenhouse offers controlled environment that can be

optimized for individual plants by controlling the main greenhouse parameters such as

relative humidity, heat flow and light luminance. Some major concerns about

greenhouse management methods have been cost and efficiency. The traditional

greenhouses had simple control systems such as opening windows and turning on/off

irrigation valves requiring the presence of people to operate it. A wired network has

also been used which has proven to be more expensive in terms of installation as

greenhouse sizes and number have increased over time. In this study, the

aforementioned issues were addressed by developing a microcontroller based system

that automates the greenhouse monitoring and controlling processes using sensors. This

will maximize the crop yields, minimize maintenance cost and save time.

1.3 Research Objectives

1.3.1 General Objective

The general objective of this research work was to design, fabricate and implement a

microcontroller based prototype to monitor and control greenhouse parameters using

sensors, SMS technology and Bluetooth signals.


4

1.3.2 Specific Objectives

The specific objectives were:

i. To utilize different sensors to capture data for green house parameters,

ii. To interface sensors, LCD, GSM SIM800L and HCO5 Bluetooth to the

ATmega328 microcontroller,

iii. To design, create and administer a program to control the prototype,

iv. To test working and performance of the prototype.

1.4 Rationale for the Research

The current greenhouses used in Kenya require a lot of human intervention for them to

run. This takes up a lot of time and needs a very keen person to try and physically

moderate the irrigation and aeration processes. Designing a self-operating greenhouse,

in which monitoring and control processes are automated, saves time and lowers the

operation costs. Our designed GSM and Bluetooth based remote wireless automatic

monitoring system provides mobility during the monitoring and control process.
5

CHAPTER TWO

LITERATURE REVIEW

2.1 Introduction

This chapter gives a general review on researches in the greenhouse systems that have

been implemented in the attempt to automate greenhouse management processes. It

outlines literature relevant to the project in areas of greenhouse technology,

technologies for greenhouse automation processes and existing greenhouse control and

monitoring systems.

2.2 Greenhouse Technology

Technology is a body of techniques, methods, processes and designs used to achieve

some intended purpose. It is the tool as well as the knowhow to use the tool (Dabadi,

2003). Greenhouse is a technology not only for enhancement of food security but also

for overall economic growth of any nation. It is light weighted, translucent or

transparent, enclosed structure in which plants are cultivated and is spacious enough to

enable people do routine activities inside it environment (Narasaiah, 2007).

As opposed to open land, a greenhouse has many advantages some of which are: offers

longer growing season since greenhouse retains heat hence growing of crops can extend

even in cold seasons, one can farm even in bad weathers since crops are covered, a wide

variety of crops can be grown even exotic plants that are not grown locally, plants are

protected from predators and pest since crops are enclosed, one can grow crops without

dangerous pesticide and greenhouse can be customized to ones needs, keeps inside
6

insects like ladybugs that are beneficial to crop, and ensures growing of food all year

round which allows one to enjoy lower food bills advantages.

Greenhouse technology should be embraced as a way of minimizing food insecurity in

the country as it plays a key role in shifting from rain-fed farming to greenhouse for

growing crops like vegetables and flowers under controlled environmental conditions.

These environmental conditions are not easy to control by manual methods inside a

greenhouse and hence there is need for an automatic system.

2.3 Technologies for Greenhouse Automation Processes

Greenhouse control systems have become more automated in recent times (Soto-

Zarazua et al., 2011). The means of automating the greenhouse can be broadly

classified into wired and wireless technologies. There are several existing Wireless

Technologies which are in use today. According to a survey conducted on the use of

these platforms it was found that the most utilized wireless technologies are Wi-Fi,

Bluetooth and ZigBee (Paavola, 2007).

2.3.1 Bluetooth

It is a wireless data transmission technique between fixed and mobile devices over short

distances by means of short wavelength UHF radio waves in the ISM band (2.400 -

2.485 GHz) - this builds personal area networks (PANs). It was developed to replace

RS-232 data cables. It transmits data in terms of packets with master/slave architecture

by frequency-hopping spread spectrum radio technique. A master bluetooth accessory

can link up to a maximum of seven accessories in a temporary computer networking

via bluetooth technique. The accessories can change their positions such that the slave
7

can act as master and vice versa. The only weakness of Bluetooth is that it has a short

range for wireless communication. This might limit the area of coverage.

2.3.2 Wi-Fi

It is a technique dependent on IEEE 802.11 levels that is used for WLAN of devices.

Wi-Fi uses ISM radio bands (2.4 GHz UHF and 5 GHz SHF) and can be utilized by

electronic devices like desktops, smartphones, smart TVs, printers, digital cameras etc.

Compatible electronic gadgets can link to one another over Wi-Fi via wireless access

points or connected Ethernet devices. Access point has a range of about 25 m and the

range can be more outdoor. Wi-Fi is potentially more vulnerable to attack than wired

network since anyone within the range of network with access network interface can

access. The cost of setting up a Wi-Fi network is much higher due to its area of

coverage. This may also result in wastage of resources as per the small-scale farmers’

requirements.

2.3.3 ZigBee

ZigBee is a technique designed for end points and star communications designed for its

use of wireless internet band rate (250 Kbits/s). It operates on a frequency of 2.4 GHz

in two methods: transparent data or API. In transparent method data entering into the

DIN pin is directly relayed wirelessly to the receiver while in APIs data are in packets

structure thus enabling addressing, setting and delivery feedback. When used in green

houses; Unlike Wi-Fi and bluetooth XBee/ZigBee are economical since they have low

power consumption, they can have very enormous network of about 65500 nodes which

are easy to manipulate in the network system. ZigBee has low transmission rate hence

it may experience delay hence not able to give timely reports.


8

2.4 Existing Greenhouse Electronic Management Systems

The existing greenhouse electronic management systems varies in terms of sensing

technology, monitoring technology and software design as discussed in the following

works;

Morais et al. (1996) designed and accomplished a climatic information collection

network for greenhouse based on PIC6C71 and 87C592 microcontrollers. The system

used data acquisition stations which were connected to solar panels and linked to a

central station by a radio frequency link. The solar panels powered a 6 V, 600 mAh

NiCd batteries for backup at night period. The system used LM35DS temperature

sensor, MiniCap2 air relative humidity sensors, TSL230 light sensors and soil waters

sensors. The base station main function was to control the data acquisition stations and

store data collected by them. The data acquisition stations communicated with central

station using RF links based on SIRLX-418F receiver and TXM-418F transmitter from

a radio station. The data received by central station (based on 87C592 microcontroller)

was sent to a PC through an RF link or CAN bus. Since communication was done

through by RF, the system was cheap, flexible and could be operated wirelessly. There

was no interference with normal operations in the greenhouse since no cables were used

in the network. Solar panels have a problem of power in case there is heavy cloud cover

this is challenge for this design.

Serodio et al. (1998) designed and implemented an integrated network, for greenhouse

management, that linked several communication techniques. The central personal

computer provided user interface, gave updates on control measures and availed report

on sensors and actuators. The network that interconnected all the sensors was based on
9

radio frequency technique. Each acquisition station worked as remote data collector and

used 80C592 microcontroller. The network that interconnected all the actuators was

based on radio frequency technique forming controller area network. The RF drivers

used was a 10 mW transceiver (BIM-433-F at 433.092 MHz) for data communication

to a radius of 400 m. CAN and RS-232 through cables provided an alternative to the

RF links because transceivers were affected by lightning during rainy weather due to

power surge. This system set up was expensive to set up.

Marhaento and Singh (2002) developed a programmable environment controller for the

greenhouse environment using personal computers (PCs). The input part comprised of

sensors for measuring water, temperature and humidity levels. The output comprised

of actuators namely dripper for supplying water, two fans one for inflow and the other

for out flow of air to enable ventilation of the system. Signal processing was facilitated

by multiplexers, amplifiers, ADC and interface card. Greenhouse environmental

controller (GEC) program was compiled under disc operating system. The program was

such that the working of control could be manual or automatic and parameters could be

adjusted to any desired levels. Humidity range was set as 80% to 95% while

temperature range as 30o C to 33o C otherwise relevant actuators were activated

automatically. The set ranges of parameters exceeded the set lower limits due to delay

of the response time of the controller and the sensors. For this reason the lower limits

were set a little bit higher and lower limits a little bit lower

Mizunuma et al. (2003) designed and implemented a rice seedling greenhouse structure

based on a wireless local area network. The environmental data hub comprised of two

weather sensors, four Soil sensors, three pyrheliometer, two net pyrradiometer and a
10

Camera linked by WLAN to a data logger. The actuators were pump for water supply

and motor for opening and closing windows. The main wireless LAN operated at 2.4

GHz, with signal rate of 2 Mbit/s and transmission range of a radius of 5 Km.

Obanda (2010) designed and fabricated a greenhouse electronic system Based on the

Z80 microprocessor. The hardware consisted of a Z80 CPU, two 8255 PIA‟s, a 2716

EEPROM, a 6116 RAM, an HIH-4000 humidity sensor, an LM-35 temperature sensor

and two ADC 0804 analogue to digital converters, a clock and reset circuitry and 7-

segment displays and LEDs. The software was coded in the Z80 assembly language.

This system monitored temperature, humidity and light illuminance on a continuous

basis. It measured and displayed these parameters and activated appropriate devices

whenever these variables fall outside predetermined ranges. Relative humidity was

controlled by a water sprinkler, temperature by a fan and heater and light illuminance

by a lighting system. The system had one major problem; it had no remote monitoring

station.

Quan (2011) designed and tested a C805F020 microcontroller based automatic

greenhouse prototype. The sensing unit comprised of sensors such as SHT75 for

measuring humidity and temperature, NORP12, TGS4161 for measuring CO2

THERM200 for mastering soil temperature and VG400 for measuring soil moisture.

The central unit comprised of a personal computer, USB cable and 19200 baud 2.4

GHzXStream RF modem. The central unit collected data, processed data, controlled

greenhouse climate and displayed information to the user. The coordinator unit

comprised of C805F020 microcontroller, Xbee module, 19200 baud 2.4 GHzXStream

RF modem, relay interface point and power supply provided by LM2594M power
11

regulator. The actuator unit comprised of bulbs, CO2 injector, exhaust fan, sprinkler,

heater and a thermal shade.

Rana et al., (2013) designed and implemented a wireless greenhouse management

system. The system architecture comprised of a control station and three sensor stations.

The sensor stations (nodes) comprised of XBee modules and three sensors. Each node

measured temperature, light and humidity, and periodically sent the data to the central

computer. The XBee modules supported ZigBee S2 links which were set to read sensors

analogue values and send them as packets of data. The central control station comprised

of XBee module linked to a computer via universal serial bus (USB). The sensor nodes

measured the green house parameters, converted the values to digital form, and then

relayed them wirelessly to the central control station.

Guraiah and Nagaswetha (2014) developed a GSM-based greenhouse system for

agricultural field. The controlling unit comprised of ARM7LPC2148 microcontroller.

The input comprised various wireless sensors to measure light intensity, humidity and

temperature levels. The output unit comprised of LCD, personal computer, GSM and

actuators. The measured values were displayed on the LCD and as well as GPRS

webpage on a central personal computer. The program for the system was developed in

C language using Keil software. The system lacked mobile monitoring system.

Swarna et al., (2015) fabricated a greenhouse monitoring system using on the Arduino

uno board and computer. The hardware comprised of data acquisition card, Arduino

board, personal computer and sensors. In the greenhouse multiple sensors were used to

measure the parameters. They used DHT11 sensor, soil hygrometer sensor, CO2 sensor
12

and light sensor. Graphical user interface (GUI) was used via labVIEW. The sensor

measured values were transmitted to the personal computer where by, through

labVIEW simulations, monitoring of greenhouse parameters was possible. This design

lacked actuation unit.

Suribabu and Naidu (2016) designed an intelligent greenhouse system based on

LPC2148 controller. It had two nodes each node had LPC2148 microcontroller,

MCP2515 controller and MCP2551transrecever. The first node comprised of sensors

for soil moisture, temperature and humidity. The second node interfaced LCD and

buzzer. The project was implemented using advanced CAN protocol and a

microcontroller. Different parameters were monitored in these nodes and updated.

Node 1 collected sensors values and sent them to the second node via CAN bus. The

second node controlled alarm system according to the received data. The CAN protocol

was implemented using SPI lines of ARM7.

Pushkar and Amey (2016) designed an embedded system for greenhouse management.

The hardware comprised of the controller PIC18F452, sensors, Graphical LCD,

EEPROM, Real time clock (RTC), and relays. Five sensors were used namely; LM35D

for temperature measurement, NORP-12-RS for measurement of light, FC-28-D for

measurement of soil moisture, and SY-HS-220 for measurement of humidity. RTC

provided date and time to the controller while EEPROM stored the monitored

information. For control action purpose the relays were utilized to ON and OFF the

actuators. Graphical LCD displayed real time parameters and the graphs for analysis.

Controllers’ UART transmitted data from EEPROM to a personal computer for viewing

via UART USB module. The actuators were cooling fan and heater to regulate
13

temperature, light-bulb to increase light, and small heater to raise humidity. This system

could not be monitored or controlled from a distance.

Remya et al., (2016) developed and implemented a prototype to monitor and control

greenhouse climate using wireless sensors network (WSN) and internet of things (IOT).

It consisted of the sensing unit, controlling part, monitoring part and message sending

and receiving part. In the sensing part, the sensors included were LM35 temperature

sensor, MQ-5 toxic gas sensor and fire sensor. The sensors detected various parameters

and displayed them on the LCD. The sensors were connected to P89V51RD2

microcontroller which was the controlling part. The analogue sensors were connected

through ADC. The microcontroller was then connected to a pump, buzzer and a GSM

module through MAX 232. When the moisture was less than the preset values

microcontroller would turn on the pump to sprinkle water. If fire was detected, then the

buzzer would be turned on to notify the user. A message sending part was a GSM

module which sent the values of greenhouse parameters to a predefined number. The

receiver was a smart phone with an android application that played a predefined audio

sound.

From the research works discussed in this section, it is clear that most existing

greenhouse systems lack mobility during the monitoring process. Our designed GSM

and Bluetooth based remote wireless automatic monitoring system provides mobility

during the monitoring process. The control and monitoring are instant and the system

is programmable by the user.


14

CHAPTER THREE

RESEARCH METHODOLOGY

3.1 Introduction

This chapter focuses on hardware, schematic and software designs of the automatic

greenhouse prototype. First, the chapter discusses in details the LDR sensor, the DHT11

sensor, the ATmega328 microcontroller, the LCD, the HC05 Bluetooth, the GSM

SIM800L and the 5 V 4 channel relays. Secondly, the chapter discusses in details the

prototype schematic design to demonstrate how each component was interfaced to the

microcontroller to up come with the expected prototype design. Lastly, the chapter

gives an overview on Arduino programming kit in the effort to design the system

software in C programming language.

3.2 Hardware Design

Figure 3.1 shows a flow diagram of the designed greenhouse prototype. The designed

prototype has the following units: sensing, processing and storing, displaying and

indicating, wireless communication, power supply, and actuation. The system

comprises of microcontroller chip, LCD, GSM, Bluetooth, sensors, relays and

actuators. The microcontroller was interfaced with two sensors to measure different

greenhouse parameters such as heat levels, light luminance, and relative humidity. The

analog data obtained from the light sensor was digitized via onboard ADC. The digital

data was fed to the microcontroller which made decisions and activated the relevant

actuators according to the installed program. The LCD displayed sensor readings and

the status of the actuators. The data provided by the sensors was recorded in EEPROM

which sent it to the microcontroller for analysis on request. The microcontroller


15

communicated with the GSM module by AT Commands, which were used to send and

receive short messages.

LCD
GSM
module Mobile
DHT11
Phone
Sensor
Microcontroller
LDR
Bluetooth
sensor
Module

Relay for
Relay Module Fan
Interface
Relay for
Bulb
Relay for
Sprinkler Relay for
Heater

Figure 3.1: The Prototype Greenhouse Block Diagram

3.3 Sensing Unit

According to Instrument Society of America, a sensor is a subsystem which produces

a meaningful electrical signal when subjected to a physical condition, characteristic or

quantity being measured. The role of a sensor is to react to an input mechanical property

and to change it into an electrical pulse consistent with electronic circuits (Fraden,

2010).

Sensors are of two categories; analogue sensors and digital sensors. Digital sensors

generate output in steps of 0 and 1, which translates to voltage range of the sensor.

Analogue sensors give continuous values in the range of it voltages. Its output voltage

varies depending on the sensor reading. Digital sensors give output in terms of ‘ON’

corresponding to 5 V or ‘OFF’ corresponding to 0 V. An analogue sensor is used to


16

make measurement of analogue numerical values where precision is needed, for

example speed or temperature. An analogue sensor is able to produce an infinite number

of values. The output of a sensor is interfaced to the input pin of a microcontroller and

data is changed to digital signal.

Some sensors such as digital humidity and temperature sensor (DHT11 sensor) have

onboard ADC so that their output is digital. Those sensors, for example LDR sensor,

do not have an onboard ADC, the analogue data is converted to digital form by the

microcontroller onboard ADC. After the data is digitized it can be processed by the

microcontroller (Karvinen and Karvinen, 2014). In this project, the sensors used to

measure greenhouse parameters are the DHT11 sensor and the LDR sensor.

3.3.1 DHT11 Sensor Module

To measure temperature and humidity in the prototype, this research utilized the

DHT11 sensor. Figure 3.2 shows the diagram of the DHT11 sensor module. The key

specifications the sensor has that attracted its choice for this project include: low

operating voltage of 3 to 5 V at 2.5 mA and 150 µA in standby mode, wide humidity

measurement range of 20% to 90% with an error of ±5% and temperature range of 0 to

50 οC with an error of ±2 οC. It weighs 2.7 g and has dimensions of 15.5 mm × 12 mm

× 5.5 mm hence suitable for embedded systems.

The sensor system comprises of a temperature and humidity sensors combined and

gives out a calibrated digital signal. The sensor system uses excellent digital signal

acquiring and humidity versus temperature measuring technologies, hence it is highly

reliable and very stable. The sensor has a component for measuring humidity which is
17

basically resistive material and a component for measuring temperature which is a

resistor with negative temperature coefficient (NTC). These two components are

connected to a high speed microcontroller, thus giving high standards, cheap and quick

response.

The DHT11 sensing components are calibrated in laboratories that are very accurate in

calibration of humidity (Tianlong, 2010). The calibration coefficients are kept as a

software in the memory (one time memory-OTP), which is utilized by the internal

detecting protocols of the sensor. The use of single wire interfacing makes integration

easy (Han and Zhao, 2011). In addition, the power consumption is low and signals can

be transmitted for a long distances up to a maximum length of 20 m. The DHT11

contains 4 pins in one row.

Figure 3.2: DHT11 Sensor (www.howtomechatronics.com)

In this study, the sensor was placed inside the greenhouse then connected to the

microcontroller. Any variation in temperature or humidity in the greenhouse made the

sensor to produce a digital signal that is proportional to the temperature or humidity

upon it. The output signal was fed to the microcontroller and this was used to trigger

the fans or heater in case the temperature was above or below the pre-set values and

sprinkler or fans incase humidity was above or below the pre-set value. Figure 3.3

shows the components of the DHT11 sensor. They include, a component to detect
18

humidity, a thermistor and a microcontroller to calibrate the digitized signal coming out

the sensor.

Backside

Figure 3.3: Components of DHT11 Sensor (www.howtomechatronics.com)

3.3.1.1 Functioning Theory of the Humidity Sensor

The humidity sensing component is made up of two conductors carrying a moisture

absorbing material to form a bridge as shown in figure 3.4. When there is change in

humidity, the resistance of the moisture absorbing material changes. When water vapor

is absorbed by the substrate, ions are released by the substrate which increases the

conductivity between the electrodes. The change in resistance between the two

electrodes is proportional to the relative humidity.

Figure 3.4: Humidity Sensing Component (www.howtomechatronics.com)

Higher relative humidity decreases the resistance between the electrodes while lower

relative humidity increases the resistance between the electrodes. Therefore, the sensor
19

produces a potential difference against the relative humidity (RH) change that is

proportional to the power supply. This implies that, the point at which the power supply

changes, the sensor produces a voltage in the same proportion. This variation is

detected, amplified and processed by the sensor microcontroller, which makes it

readable by the system microcontroller. It operates on the voltage range of 4 to 5 V. At

5 V and room temperature, output voltage ranges is 0.8 – 3.9 V as humidity varies from

0 % to 100 %. Sensor output voltages for humidity sensing component can be taken

into account according to Eq. 3.1 (voltage output first order curve at 25ºC):

VOUT = (VCC ){0.0062(%RH)} + 0.16 (3.1)

Where: VOUT = the sensor output voltage; VCC = the supply voltage; and %RH = the

sensor relative humidity. The constant 0.0062 is the gradient of the first order equation

and 0.16 is the out voltage at no supply voltage to the sensor.

3.3.1.2 Functioning Theory of the Temperature Sensor

The sensor utilizes a thermistor to detect temperature shown in figure 3.5. It is a resistor

whose resistance changes with variation in temperature. The sensor is made by sintering

of semiconductor substance so as to produce higher variations in the resistance with

minute changes of temperature.

Figure 3.5: Temperature Sensing Component (www.howtomechatronics.com)


20

A thermistor is a resistive subsystem, therefore current must be passed through it so

that it can output voltage that is detectable by a data acquiring system. The most

common used technique is use of a constant voltage supply (VCC ) and a fixed resistor

(R 0 ), then configuring the thermistor to form a potential divider as shown in figure 3.6.

In the set up the output voltage ( VOUT ) will be given by the Eq. 3.2:

RT
VOUT = (R ) VCC (3.2)
T +R0

Vcc

R0

VOUT

RT

Figure 3.6: Thermistor Configuration

Resistance-temperature characteristic of the thermistor can be approximated relatively

accurately with the Steinhart-Hart equation 3.3:


1
T(℃) = (3.3)
α0 + α1 ln(RT )+α2 [ln RT ]2

where: T (ºK) = temperature in degrees Kelvin; and RT = resistance of the thermistor.

The coefficients α0 , α1 and α2 can be provided by the thermistor manufacturer or

calculated from temperature coefficient curve. For the thermistor used in this research:

αo = 0.001191, α1 = 2.357x 10-4 and α2 = 9.252x 10-8


21

3.3.2 LDR Sensor

This study used the light dependent resistor (LDR) sensor, shown in figure 3.7, which

is basically a resistor whose internal resistance increases or decreases depending on the

level of light intensity impinging on the surface of the sensor. They are made up of

semiconductor materials having high resistance. Table 3.1 shows technical

specification of the LDR sensor used in this research work.

Figure 3.7: LDR Sensor (www.rathyelectronics.com)

Table 3.1: Technical Specification of the LDR Sensor

Specification Value

Voltage (AC or DC) peak 320 V

Current 75 mA

Power Dissipation at 30 °C 250 mW

Operating temperature range - 60 °C to 75 °C

In this system, the sensor was placed inside the greenhouse then connected to the

microcontroller. Any variation in light intensity in the greenhouse made the sensor

produce an electrical pulse that varies with the light upon it. The output signal was fed

to the controller and this was used to turn the bulb on or off.
22

3.3.2.1 Functioning Theory of the LDR Sensor

The LDR sensor operates on the photoconductivity theory of light. Photoconductivity

is the light property of a material whereby, when a material receives light its resistance

is decreased. The LDR is made of a semiconductor and the valence band electrons of a

semiconductor are excited to conduction band when photons fall on the device. For the

electrons to jump from valence band to conduction band, the photons of the incident

light should have greater energy than the semiconductor band gap. Hence large numbers

of electrons are dislodged from the valence band to the conduction band when light

with sufficient energy impinges the semiconductor material. This process results in high

current flow through the device in closed circuit since the resistance of the device has

been decreased.

3.3.2.2 Features of the LDR Sensor

The structure of the light dependent resistor is shown in figure 3.8. It comprises of a

light sensitive substance deposit on an insulator like ceramic. To get the needed

resistance and power, the substance is deposited in zigzag pattern. The function of the

zigzag area is to separate the metal deposit area into two parts. Then the Ohmic contacts

are made on the either sides of the area. The resistances of these contacts should be as

less as possible to make sure that the resistance changes due to the effect of light only.

The resistance of the LDR sensor is about 1012 KΩ in darkness, this resistance is

referred to as dark resistance and if the LDR sensor absorbs light, this resistance

decreases drastically. For this reason, applying a fixed voltage to the sensor, and

increase light intensity the current through it increases significantly. The most common

used technique is use of a constant voltage supply (Vin ) and a fixed resistor (R I ), and
23

configuring the LDR sensor to form a potential divider as shown in figure 3.9. In the

set up the output voltage (VOUT ) is given by the Eq. 3.4:

RL ×Vin
VOUT = (3.4)
RL +RI

Figure 3.8: Structure LDR Sensor (www.robotic.com)

Figure 3.9: LDR Sensor Configuration


24

3.4 Processing Unit

The sensing unit, the displaying and indicating unit, the communication unit and the

actuation unit require a central processing unit in order to perform various tasks such

as data acquisition and data processing. Therefore a microcontroller was integrated into

the system. Microcontroller is an integrated chip that consists of all components

including programmable peripherals, input/output ports, central processing unit, timers

and program (Augarten, 1983). This research utilized ATmega328 microcontroller to

analyse the input signals from the sensors and subsequently instructing the actuators,

the Bluetooth module and the GSM module accordingly.

3.4.1 ATmega328 Microcontroller Chip

The ATMega328 microcontroller chip (manufactured by microchip Technology

Company) consumes low voltage and has improved design of high performance. It is 8

bit microcontroller with a processor that operates on the AVR Harvard architecture.

The key parameters of ATmega328 are outlined as follows:

a. 28 pins (as illustrated on figure 3.10. The table in Appendix B describes

function(s) of each of the pin) and 23 lines of programmable input/output (I/O).

b. Three communication interface; Serial Interface, Programmable Serial USART

and Two-wire Master/Slave SPI.

c. Operating temperature range of - 40 to + 105 °C and Operating Voltage range of

+ 1.8 to + 5.5 V.

d. Six program based power save modes; Noise Reduction mode, Idle mode,

Extended Standby mode, Power-down mode, Standby mode and Power-save

mode.

e. Programmable Watchdog Timer with internal separate Oscillator.


25

f. 1 Kbytes EEPROM and 2 Kbytes Internal SRAM with CPU Speed 1 MIPS for

1 MHz. Program or Flash memory 32 Kbytes (10000 write/erase cycles).

g. 4 External Oscillator: 0 - 4 MHz at 1.8 to 5.5 V, 0-10 MHz at 2.7 to 5.5 V and 0

- 20 MHz at 4.5 to 5.5 V.

h. 8 MHz Calibrated Internal Oscillator and six PWM channels.

i. Two 8-bit counters having inbuilt Prescaler plus compare mode, One 16-bit

counter with inbuilt Prescaler plus compare and capture modes.

j. 6 channels 10-bit ADC and 1 Analog Comparator (pins 12, 13).

Figure 3.10: ATmega 328 Microcontroller Pins (www.vwlowen.co.uk)

ATmega328 was chosen for this project work because of its cost effectiveness, its

excellent features and the fact that Arduino boards are designed on this controller.

ATmega328 has many applications due to it 32 Kbytes program memory and with six

program selectable power save modes it can operates on movable electronic devices.

The watchdog timer enables the resetting of the controller in case of an error thus it can

be utilized on devices with minimum or no human involvement. The execution of the

program is quick AVR Harvard architecture. The chip has a sensor for controlling
26

temperature meaning it can be operated on extreme temperature levels. The

microcontroller is designed to operate on low voltage (Howard, 1991) and required

about 5 V which was provided by voltage regulator discussed in section 3.6.3.

3.4.2 Internal Architecture of the ATmega328 Microcontroller

Appendix L shows the structure of the internal components of the ATmega328. The

data buses, memories, analogue to digital converter, central processing unit and other

key parts are very well shown. The CPU is the “think tank” of ATmega328 chip that

controls the software implementation.

Figure 3.11: ATmega328 CPU Harvard Architecture (www.eckovation.com)

For this reason the CPU carries mathematical calculations, deals with interrupts,

reaches memories and manages peripherals. The diagram in figure 3.11 shows the

central processing unit. For maximum performance in accessing data and program,
27

ATmega328 employs Harvard architecture (the bus and memories for data and program

are distinct).

In the program memory, instructions are executed in such a way that as one instruction

is being performed, the next instruction is pre-fetched from the memory (Single level

pipelining). This implies that instruction are executed in each and every cycle. The

reprogrammable flash memory is the custodian of the program memory. The access

register has 32 general purpose working registers which have one clock cycle access

time, this enables one arithmetic and logic unit cycle operation.

In one clock cycle the ALU comprises of two operands from the register; the operation

is done and the outcome is left in the register. For effective calculation of addresses, 6

registers in the 32 registers serves as 6-bit indirect register pointer to facilitate spacing

of the data addressing. One out of the 3 address pointers monitors tables in the flash

memory hence it is an address pointer.

The ALU performs the arithmetic and logic exercises between a register and another or

between a register and a constant. Operations of one register can also be performed in

in the ALU. Status register is updated to show information on the result of the operation

after an arithmetic operation. Conditional and unconditional jumps and call for

instructions enable the program to flow smoothly. The ATmega328 has one 16-bit word

pattern instructions hence each memory of program has an instruction bit of 16/32-bit.

Program flash memory is made up of two parts; the boot part and the program

application part, both having write and read or write protection lock bits. Boot program
28

memory is the custodian of program memory that that writes the applications in the

flash memory.

The stack is the custodian of the return program counter during subroutines and

interrupt calls. Its allocation is the data memory (SRAM) and thus limited to SRAM

space and use of SRAM. The static pointer must be initialized by all programs that are

in use at any given time and can be accessed through input/output space. The data

memory can be accessed through the 5 addressing modes in the architecture of

ATmega328. The ATmega328 memory spaces are all linear with regular memory maps.

Flexible interrupts contains control registers inside input/output space and its control

register contains an extra interrupt bit. In the interrupt vector table all interrupts have a

unique interrupt vector and they are accessed according to their position. The lower the

address of the interrupt vector the higher the chance. The input/output has 64 central

processing unit addresses for peripheral functions such as serial peripheral interface,

control registers, and other input/output roles. The access to the input/output memories

can be direct, or as data space locations followed by register file. In addition

ATmega328 contains extended input/output space in the SRAM for storage of special

instructions.

3.5 Arduino Microcontroller Board

The Arduino uno microcontroller board, is a single board microcontroller board that

uses the ATmega328 microcontroller (Arduino Corporation, 2013). To program the

ATmega328 microcontroller, the microcontroller was first mounted on the board and

the board powered through power interfaces. Figure 3.12 shows how the
29

microcontroller was mounted on the board during programming while figure 3.13

shows the arduino uno board schematic diagram.

Figure 3.12: Arduino Uno Board (www. datasheet.octopart.com)

The Arduino board has three sets of pins; 14 digital I/O pins, 16 analog I/O pins and 7

power pins. The 6 out 14 digital pins can generate pulse width modulated signal

(PWM). Table 3.3 shows digital pins names and their descriptions.

For serial communication, the D0 and D1 pins were interfaced to RX and TX pins

respectively on the Atmega8U2 USB to serial chip, while for serial peripheral interface

communication, the board used the D10, D11, D12 and D13 pins. The D2 and D3 pins

provided external interrupts when configured to trigger interrupts on value change or

low value or fluctuating edge. The board inbuilt LED was operated by pin 13 hence the

LED was on when the pin value was high and vice versa. A serial library in addition to

digital pins D0 and D1 facilitated serial communication on the digital pins. To send a

pulse width modulated signal to the relays the six digital pins were used as output.

Signal from light sensor entered the board through the analogue pins.
30

Table 3.2 shows the Arduino board analog input pins and their descriptions. A4 and A5

pins supports TWI data transmission via wire library. The onboard quartz crystal

produced a 16 MHz synchronizing pulse.

Table 3.2: Arduino Analog Pins

Pin
No. Name Second Function Explanation
0 A0
1 A1
2 A2
3 A3
4 A4 SDA I2C Data Out
5 A5 SCL I2C Clock

To power the Arduino board we used the USB interface or the external power supply

jack. The grounding of all pins was done through the GND pin. The 5 V pin supplied a

voltage of 5 V from the external voltage regulator to the board while the 𝐕𝐢𝐧 pin enabled

the voltage from external source to power the Arduino board. The Arduino uno board

regulator generated 3.3 V at a maximum current of 50 mA. This voltage was accessed

through 3V3 pin. The analog input reference voltage was accessed through 𝐀 𝐑𝐄𝐅 pin

and to reset the controller RESET pin line was brought low. The range of operating

external power was 6-20 V, when powered with less than 7 V, the board was not stable

and on using power greater than 12 V, the regulator over heated hence damaging the

board. This was in agreement with manufacturers recommended range of 7 to 12 V.

Textual data was sent to and from the board via serial monitor of the Arduino software

(IDE). The D0 and D1 pins LEDs flushed when the data was in transmission process

through USB interface to the laptop the USB to serial chip. Instead of pressing

physically to the reset button prior to uploading the program, the Arduino design allows

resetting by it software via the connected laptop.


31

Table 3.3: Arduino Digital Pins

Pin
No. Name Second Function Explanation
0 D0 RX UART Receiver
1 D1 TX UART Transmitter
2 D2 INTO Interrupt
3 D3 INT1 Interrupt
4 D4
5 D5
6 D6
7 D7
8 D8
9 D9
10 D10 SS SPI SS
11 D11 MOSI SPI MOSI
12 D12 MISO SPI MISO
13 D13 SCK SPI Clock

The data-terminal-ready (DTR) of the ATmega8U2 was interfaced to ATmega328 reset

line through a 100 nF capacitor. When DTR was taken low, the reset line on the chip

fell down. This modification on the Arduino software allowed uploading of a program

by pressing the interface button on the IDE tool bar. The falling of the DTR was

coordinated to the start of the uploading process; hence boot loader timeout was shorter.

Figure 3.13: Arduino Uno Board Schematic (www.arduino.com)


32

3.6 Wireless Communication Unit

3.6.1 Phone System

A mobile phone refers to a handy telephone, which through a cell site (base station) or

transmitting tower, is in a position to make or receive calls. The transfer of signals to

and from the cell phone is by use of radio waves. Since radio frequencies are limited,

modern mobile phone network use cells. Cell sites and phone handsets vary frequency

under computer control and utilize low power transmitters in order to simultaneously

use the few numbers of radio frequencies to link huge number of callers with minimum

interference.

Mobile phone operators use a cellular network to get coverage and number of their

subscribers. To prevent line of sight loss and to facilitate a huge number of active

phones in a given area, large geographical areas are split into smaller cells. All the cell

sites are linked to the public phone network.

There are several different digital cellular techniques, including: global system for

mobile communication (GSM), general packet radio service (GPRS), enhanced data

rate for GSM evolution (EDGE), universal mobile telecommunications (UMTS), etc.

3.6.2 Structure of the Phone Cellular Network

The cellular mobile radio network comprises of; the base station subsystem, the core

circuit switched network, the packet switched network and the public switched

telephone network. Figure 3.14 shows the GSM network structure and its components.
33

The base station subsystem comprises of a network of radio base stations. The base

stations handles traffics and signals between the networks switching system (NSS) and

mobile phone. It transcodes speech, allocates radio channels to phone, transmits and

receives information through the air interface.

The handling of voice and texts is done by the core circuit switched network. This is

the GSM core network; it is responsible for mobility control and call out for roaming

mobile phones on the base station network. Traditionally the NSS comprises of the

GSM services such as SMS, voice calls and circuit switched data calls. It was later

extended to packet switch data services, the GPRS network, which enables phones to

access services like WAP, MMS and internet. The public switched telephone network

connects subscribers to the larger phone network. It comprises of telephone lines

microwave transmission links, cellular networks, communication satellites and

undersea phone cables, all linked to switching centres to allow phones to communicate

to each other.

Figure 3.14: GSM Network Structure (www.ques10.com)


34

The mobile phone cellular network is the base of GSM network system. Some of the

functions of the mobile cellular network include registration, call setting, and handover

and mobility control. Any cell phone links to the network through radio base station

(RBS) at a corresponding cell which then links to the mobile switching centre (MSC).

The MSC enables public switched data network (PSTN) connection.

3.6.3 GSM SIM800L Module

The GSM SIM800L module enables sending and receiving of SMS messages during

monitoring of the greenhouse system. Hence the greenhouse is manageable from all

over the world. The SIM800L employs surface mount technique (SMT) hence it is

highly reliable. It is quad band SIM module implying that it can work on four

frequencies, to deliver high performance on 850 MHz or 900 MHz or 1800 MHz or

1900 MHz, for voice, SMS, and data. To meet specifications of M2M uses, the module

dimensions are (15.8 × 17.8 × 2.4) mm. The SIM800L key features are illustrated in

table 3.4. To connect and manage the GSM module AT commands are used. AT

abbreviates attention and to interface and control the GSM modems AT commands

instructions are used. Each command begin with ‘AT’ which is prefix telling the

module the start of a command. For example, in ATD the command is D (dial) and in

A + CMGR the command is + CMGR (read SMS messages).

Figure 3.15: SIM800L Module (www.octopart.com)


35

Table 3.4: Key Characteristics of the GSM SIM800L

Characteristic Description
Voltage 3.4 V - 4.4 V
Current (Sleep Mode) 0.7 mA.
Frequencies(MHZ) GSM850 MHZ, EGSM900, DCS1800 and PCS1900.
CLASS 4: NGS850 MHZ, EGSM900 MHZ
Power Transmission CLASS 1: DCS1800 MHz, PCS1900 MHz
Operating : -40 0C to +850C
Temperature range Storage: -45 0C to +90 0C
SIM Support SIM card: 1.8 V,3 V
MT,MO,CB, Text and PDU mode
Messages storage: SIM card
Clock RTC
15.8 mm × 17.8 mm × 2.4 mm
Physical characteristics Mass 1.35 g
Timing AT commands

Figure 3.16: LM2596 Voltage Regulator (www.microchip.com)

Figure 3.17: LM2596 Voltage Regulator Schematic (www.microchip.com)


36

The GSM SIM800L module consumes a current of 0.7 mA during sleep mode. In this

work the GSM module used required a voltage of 4.4 V and a current of 2 A. Figure

3.16 and 3.17 show LM2596 voltage regulator used in this work and its schematic

diagram respectively.

3.6.4 HC05 Bluetooth Module

In this study, the Bluetooth module enabled monitoring and control of the greenhouse

prototype remotely via a cell Phone in case the user is in the vicinity of the greenhouse.

Figure 3.18 shows front and back parts the HC05 Bluetooth module.

Figure 3.18: HC05 Bluetooth Module Pins (www.bluetooth.com)

The range of the Bluetooth module is 8-10 meters this implies that one can operate any

electronic device within that range. The HC05 Bluetooth module has an adaptor and a

serial interface which changes serial port to Bluetooth.

It has a convenient size of 26.9mm x 13mm x 2.2 mm which make it suitable for

embedded systems. With version 2.0 enhanced data rate (EDR), it has an asynchronous

speed of 160 kbps to 2.1Mbps and synchronous speed of 1Mbps. It operates on

Gaussian Frequency Shift Keying (GFSK) modulation at 2.4 GHz on ISM band. It has

operating temperature of -20 oC to + 75 oC and operating voltage of 3.3 V at 50 mA.

Sensitivity of up to -84 dBm and emitting power of up to 4 dBm.


37

3.7 Displaying and Indicating Unit

To monitor the continually monitored values from the sensors, a liquid crystal display

was interfaced with the microcontroller. Hence the user could observe the temperature,

humidity and light intensity values.

3.7.1 HD44780U LCD Module

A LCD is a thin, flat display device made up of any number of color or monochrome

pixels arrayed infront of a light source or reflector. It is often utilized in battery-powered

electronic devices because it uses very small amounts of electric power.

Figure 3.19: HD44780U LCD Module (www.bluetooth.com)

For the purpose of this project, the HD44780U LCD module shown in Figure 3.19 was

used for simplicity and cost efficient. Figure 3.20 shows its internal architecture. The

LCD has two registers (numbers and characters) and displays character in 5x8 pixel

arrangements. It was interfaced with microcontroller to display the content of the

registers in terms of numbers and characters. When letters and digits are to be displayed

LCDs are preferred because:


38

i. They have low power consumption, thus economical.

ii. They can display both numbers and characters unlike LEDs which can only

display numerals and a few graphics.

iii. Due to their internal controller the microcontroller is saved from sending data

to display continuously.

Figure 3.20: LCD Module Architecture

3.8 Actuation Unit

3.8.1 Relay Module

A relay is a switch that by electronic or mechanical means opens and closes a circuit.

By opening and closing contacts in another circuit, relays are able to control other

electrical devices. There exists an open contact (when the relay contact is normally

open) and a closed contact (when the relay contact is normally closed) when the relay

is not powered.

This project made use of the 5 volt 4 channel relay module shown in figure 3.21, which

is an electromechanical relay. As can be seen in the relay schematic diagram in figure

3.22, the relay comprises of a coil of copper wire, movable contact and a return spring.
39

A drive circuit is incorporated between relays and the interface circuit to sense the levels

of the input and command the relays accordingly. For this reason a relay can operate

high power devices like motors and even low power devices like light bulbs.

Figure 3.21: 5 Volt 4 Channel Relay Module (www.wiki.sunfounder.cc)

The input connections of relay module comprise of Logic GND which is connected to

GND of the microcontroller, Digital Pins IN 1, IN 2, IN 3 and IN 4 which are connected

to digital pins of microcontroller or left unconnected if not in use and Logic VCC which

is connected to the 5 V pin of the microcontroller to power the relay module.

The output connections of relay module comprise of normally open (NO), common

connection (COM) and normally closed (NC). COM which is used in both NO and NC

is the center terminal of relay. NO normally open behaves like a switch. Before the

relay is activated an open connection, hence no contact between COM and NO. But

when the relay is activated, it gets connected to the COM and supplies voltage to the

load. Thus the circuit will initially be in open state until the state is triggered. NC always

remains in contact with COM and when the relay is triggered it opens the circuit. Relay

1 (K1) connect one end of the load to the COM and the other end to NO. Connections

for K2, K3 AND K4 are the same.


40

Figure 3.22: Relay Module Schematic (www.wiki.sunfounder.cc)

3.8.2 Actuators

An actuator is a machine component that moves and controls a system. It requires a

control signal and a source of energy. The control signal has low energy which may be

voltage or electric. The main source of energy is electric current, fluid pressure or

pneumatic pressure. Upon receiving a control signal an actuator converts it into

mechanical motion. The designed unit includes the following actuators:

a. Ventilation fans: Two direct current fans determined the rate of air flowing

inside and outside the greenhouse prototype hence providing ventilation.


41

b. Heat flow: Consisted of a 220 V heater positioned inside the greenhouse

prototype to provide heat when necessary.

c. Water Pump: Pump provided the means for moving water through the system

at usable working pressures for the sprinkler.

d. Lighting system: Bulb provided means of lighting the system when day light

is dim or at night.

In this study, the heater, bulb, fans, and water pump received commands from the

central processing unit via relays to control the greenhouse climatic parameters such as

temperature levels, humidity levels and light illuminance inside the greenhouse

prototype. Relative humidity was controlled by a water sprinkler and a fan, temperature

by a fan and heater and light illuminance by a lighting system (Appendix P). The

DHT11 sensor was positioned at the centre to measure temperature and humidity in the

system. Also one light sensor was placed in the same position for sensing light intensity.

A sprinkler was placed inside the greenhouse and attached to the pump from a water

source.

3.9 Prototype Greenhouse Schematic Design

To make a microcontroller an independent computer, a 10 KΩ resistor was connected

to +5 V from pin1. This prevented the microcontroller from resetting during operations.

Then pin 7 was connected to +5 V, pin 8 and pin 22 to the ground, pin 22 to +5 V

analogue reference. The Atmega 328 runs at 16 MHz clock speed. Therefore, a 16 MHz

external oscillator was added between pin 9 and 10 with two 22 pF capacitors grounded

from these pins (Appendix O).


42

3.9.1 Interfacing ATmega328 Microcontroller with LCD Module

The LCD module was interfaced in 4 bit mode as illustrated in figure 3.23. The LCD

module has 16 pin whose functions are illustrated as follows:

a. Pin 1 (VSS): supplies low voltage power (0 V) to the LCD.

b. Pin 2 (VDD): supplies high voltage power (5 V) to the LCD.

c. Pin 3 (VO): used to set the LCD contrast.

d. Pin 4 (RS): sends instructions (when set high) or data (when set low) to the LCD.

e. Pin 5 (R/W): writes to LCD (when set low) and reads from LCD (when set high).

f. Pin 6 (E): this pin sends signals to the LCD module in order to process instructions.

g. Pin 7-14 (D0…D7): its function is to send data in binary form to or from LCD.

h. Pin 15 (Anode): supplies high voltage power (5 V) to LCD backlight.

i. Pin 16 (Cathode): supplies low voltage power (0 V) to LCD backlight.

Figure 3.23: LCD Interface to ATmega328 Microcontroller

In this study there was no need of controlling the LCD backlight levels hence pin 16

was grounded through 100 Ω resistor. To adjust the LCD contrast a 10 KΩ resistor was
43

connected to pin 3 of the LCD and then grounded. Table 3.5 shows LCD pins mapping

to ATmega328 microcontroller. It shows how pins from LCD were connected to the

microcontroller to achieve the expected design.

Table 3.5: LCD/ATmega328 Pin Mapping

LCD ATmega328
Pin 4 PD6
Pin 5 PD5
Pin 6 PD4
Pin 11 PD3
Pin 12 PD2
Pin 13 PD1
Pin 14 PD0

3.9.2 GSM SIM800L Interface to ATmega328 Microcontroller

The GSM SIM 800L was directly interfaced with ATmega 328 Microcontroller through

the three lines; transmitter, receiver, and ground. Figure 3.24 shows the GSM SIM800L

interface with ATmega328 microcontroller respectively.

Figure 3.24: GSM SIM800L Interface to ATmega328 Microcontroller

Pin 2 of the microcontroller was connected to pin 4 of the GSM while pin 3 of the

microcontroller was connected to pin 3 of the GSM. Finally pin 1 of the GSM was

connected to 5 V source and pin 5 was grounded.


44

3.9.3 HC05 Bluetooth Module Interface to ATmega328 Microcontroller

Figure 3.25: Bluetooth Interface to ATmega328 Microcontroller

Figure 3.25 show circuit connections of the Bluetooth module to the ATmega328

microcontroller. Pin 5 of the microcontroller was connected to pin 2 of the bluetooth

while pin 6 of the microcontroller was connected to pin 3 of the Bluetooth. Finally pin

1 was connected to the 5 V source and pin 4 was connect to the ground.

3.9.4 DHT11 Sensor Interface to ATmega328 Microcontroller

Figure 3.26 and 3.27 shows the DHT11 interface to the ATmega328 microcontroller

and pin configuration for the DHT11, respectively. DHT11’s power supply was

provided by 5 V adapter of the system. For power filter one capacitor valued 104 nF

was interfaced at Vcc and grounded. The sensor uses serial interface communication

technique. For data transfer and synchronization process between the sensor and the

microcontroller, single wire data technique is used, this lowers the cost and increases

the length. To send data through a bus, description on the manner in which the data is

transferred (protocol) is important, this enables the transmitters and receivers to be in

harmony. The one wire line is connected via a resistor to the power source. So the line

is equal to 5 V if there is no charge. Communication pattern is in three stage: request,


45

respond, and read. A complete data flow has 40 bit, and higher data bit is sent first. The

format is, 8 bit RH + 8 bit RH + 8 bit T + 8 bit T + 8 bit SUM. If the data transmission

is correct, the sum is equal the last 8 bit of "8 bit RH + 8 bit RH + 8 bit T + 8 bit T ",

where RH and T are relative humidity and temperature respectively.

Figure 3.26: DHT11 Sensor Interface to ATmega328 Microcontroller

Figure 3.27: Pin Configuration for DHT11 Sensor (www.researchgate.net)

3.9.5 LDR Sensor Interface to ATmega328 Microcontroller

The LDR sensor has three pins (GND, VCC and OUT) and works under 5V. The LDR

sensor was interfaced to ATmega328 microcontroller as shown in figure 3.28. One pin

of the senor was interfaced to ground and the other to the analog pin 0 of the

microcontroller. A 10 KΩ resistor was also interfaced to the same pin and connected to

power source (VCC). Since the LDR gives out an analogue value it was interfaced to the
46

analog input pin on the microcontroller. The microcontroller with its ADC then

converted the analog voltage into digital value.

Figure 3.28: LDR Sensor Interface to ATmega328 Microcontroller

3.9.6 Relay Module Interface to ATmega328 Microcontroller

Figure 3.29 shows how the 5 V 4 channel relays board was interface to ATmega328

microcontroller.

Figure 3.29: Relays Interface to ATmega328 Microcontroller

The Pin 2, pin 3, pin 4 and pin 5 of the relays interface board were connect to pin 23,

pin 24, pin 25 and pin 26 of the microcontroller respectively while the Pin 1 and pin 6

were interfaced to power source and ground respectively.


47

3.10 Printed Circuit Board

The printed circuit board (PCB) mechanically supported and electrically connected the

electronic components of the project using conductive trucks, pads, and other features

etched from copper sheets laminated onto nonconductive substrate. Figure 3.30 shows

a screenshot of the project PCB design on eagle software PCB view during designing

process.

The PCB design was made by converting our schematic design diagram into PCB

layout using eagle PCB software. A laser printer was used to make a printout of the

PCB layout. A copper plate measuring 16 by 22 was cut using a cutter. The copper side

was scratched with steel wool to remove the oxide and photo resist layer, The PCB was

transferred to copper plate and the circuit ironed from the paper onto PCB plate. Then,

the PCB was dipped in warm water for 15 minutes to dissolve and removed gently.

Finally the plate was etched and cleaned. Final touches included: Drilling vias,

mounting pads and leads on the board for mounting electronic devices and soldering

the components on the PCB to prevent short circuiting them.

Figure 3.30: PCB Circuit Maker


48

3.11 Software Design

3.11.1 Introduction

In microcontrollers and computers, programming refers to writing a sequence of

directives, executable by the processor in a given order to carry out preset task. It

involves debugging, and troubleshooting instructions and instruction sequences to

ensure collect task implementation. There are certain words, grammar and rules for

programming languages.

There are three types of programming languages for microcontrollers depending on

closeness of statements in the language resemblance of the operations done by the

controller. The three levels of programming languages are: machine code, assembly

language and high level language.

In machine code instructions are written in binary form (digits 0 and 1), stored as

‘LOW’ and ‘HIGH’ voltages. It is the lowest level of programming language and

microcontrollers understand this language. The assembly language is the English

representation of the machine code – it is based on mnemonics and hexadecimals codes.

Architecture knowledge of the microcontroller is crucial in this language. The high

level language uses words and statements easily understood by human. Examples of

high level languages are BASIC, Pascal, C++ and Java. A program called compiler

enables conversion of the programs in high level language to binary form (digits 0 and

1) which can be uploaded to computer memory for execution. High level languages are

easy to work with, however, assembly languages have the following merits;

a. Their programs are faster to execute and require less memory space.

b. Enable direct exploitation of the features of microcontrollers.


49

c. Enhance direct and accurate control of microcontroller resources such as RAM,

Ports etc.

d. They have less rules and restrictions.

3.11.2 System Program

In order to develop a program to upload to the ATmega328 to operate the automatic

greenhouse prototype, the following steps was applied:

i. Start: Reset the ATmega328 ready to execute the instructions.

ii. Initialize the sensors, GSM, Bluetooth, LCD and the relays. Send SMS

‘‘Welcome. System switched on’’.

iii. Read the DHT11 and LDR sensors.

iv. If the temperature is within the optimum range, the software maintains status

quo. If the temperature is greater than the maximum set temperature, the

software checks status of the heater. If the heater is off it turns on the fans .If

heater is on it turns off the heater then turn on the fan.

v. If the temperature is less than the minimum set temperature, the software

checks the status of the fan. If the fan is off it turns on the heater. If the fan is

on it turns off the fan then turn on the heater.

vi. If the humidity is within the optimum range, the software maintains. If the

humidity is greater than the maximum set humidity, the software checks status

of the pump. If the pump is off it turns on the fans. If pump is on it turns off

the pump then turn on the fan.

vii. If the humidity is less than the minimum set humidity the software checks

status of the fan. If the fan is off it turns on the pump. If fan is on it turn off

the fan then turns on the pump.


50

viii. If light is minimum it turns on the lamp otherwise it turns off the lamp.

ix. If an error occurs during the execution process go to step ii. Otherwise, it sends

a message to the user on the greenhouse parameters and go to step iii.

x. End.

The flow chart in appendix A describes the above algorithms.

3.11.3 Program Development

The program was developed in Arduino IDE, converted to machine code and uploaded

to the ATmega328 microcontroller. Figure 3.31 shows the Arduino IDE during the

program development. This process involved the following procedure:

i. Creating new file.

ii. Designing a sketch.

iii. Compiling the sketch code.

iv. Combining of the sketch code with the Arduino libraries.

v. Uploading the sketch code.

Figure 3.31: Arduino Environment


51

3.11.4 Software Structure

In Arduino programming there are two main functions, these are; the setup() and the

loop().

START

SETUP()
YES

NO
LOOP() Powered

YES
Reset
Button

NO

END

Figure 3.32: Arduino Software Flowchart

The Setup() function is only operated once when device is booted up, it is mostly used

to perform the initiation settings. The Loop() is ran after the setup() function has

finished, the loop() function runs repeatedly until the power is put off or the reset button

is pushed (Figure 3.32). The Arduino programming is supported by a large number of

libraries.

Before writing any code it is important to begin with comment section which contain

the general description of what the code does. The second section is the variable section

which declared the variables used in the program and could be called in any of the

sections that followed.


52

#include "DHT.h"
#include <LiquidCrystal.h>
#include <SoftwareSerial.h>
#include <EEPROM.h>
#include <avr/pgmspace.h>
#include <string.h>
#define DHTPIN 6
SoftwareSerial mySerial(3,4); // RX, TX
LiquidCrystal lcd(8, 9, 10, 11, 12, 13);
const char config_delimeter[2] = "#";
char number[15] = "+254724593277";

The third section is the “void setup()” which defined which pins were input or output

and any other parameter in the program.

void setup() {

Serial.begin(9600);
mySerial.begin(9600);
lcd.begin(16, 2);
pinMode(ldr_pin, INPUT);
pinMode(light_pin, OUTPUT);
pinMode(fan_pin, OUTPUT);
pinMode(heater_pin, OUTPUT);
pinMode(sprinkler_pin, OUTPUT);
digitalWrite(light_pin,HIGH);
digitalWrite(fan_pin,HIGH);
digitalWrite(heater_pin,HIGH);
digitalWrite(sprinkler_pin,HIGH);

Last section is the “Void loop()” The microcontroller functions were written here. Any

action that needed reading or writing values from pins or computation of different

variables was done here.

void loop() {

while (Serial.available() > 0)


{
sms_rx[index] = Serial.read();
mySerial.print(sms_rx[index]);
index++;
data_received = true;
}

if (data_received)
{ sms_rx[index] = '\0';
53

data_received = false;

process_txt(sms_rx);
for (int j = 0; j <= sizeof(sms_rx); j++)
{
sms_rx[j] = '\0';
}
index = 0;
}

The code to operate the ATmega328 microcontroller in this prototype was contained in

this section. This section is important as it performed the same function repeatedly. It

enabled the microcontroller read the DHT11 sensor, the LDR sensor, HC05 bluetooth

device and GSM SIM800L; and triggered the fans, the heater, the water pump and the

bulb. It also checked the prototype status and updated the user through messages at

regular intervals.

The code extract below demonstrates how this function sent a message any time the

user requested the greenhouse parameters.

void process_txt(char *txt)

{if (strcasestr_P(txt, PSTR("config")) != 0)


{
if (strcasestr_P(txt, PSTR("data")) != 0)
{
send_data_text();
}
if (strcasestr_P(txt, PSTR("manual")) != 0)
{
auto_mode = false;
send_text(number, manual_activated_string);
}
if (strcasestr_P(txt, PSTR("auto")) != 0)
{
auto_mode = true;
send_text(number, auto_activated_string);
}
54

3.11.5 AT Commands

The Cell phones and GSM modules use a set of AT commands depending on GSM

technique. They include AT commands related to SMS such as AT+CMGS,

AT+CMGL and AT+CMGR. There are two categories of AT commands; the basic AT

commands and the extended AT commands. The AT commands that do not start

without ‘+’ are the basic, while those AT commands with ‘+’ are the extended ones. A

set of some of the AT commands applied in this research are described in table 3.6.

Table 3.6: SMS AT Commands

Command Description
AT+CPMS Store message
AT+CMGF Format message
AT+CSCA Address for Service Centre
AT+CSCB Broadcast message Select cell
AT+CNMI Indications of New Message
AT+CMGL Messages listing
AT+CMMS To send More messages
+CMTI SMS delivery notification
+CMT Directly delivered SMS Notification
+CDSI SMS status report SMS Notification
+CBM Directly delivered cell broadcast SMS Notification
AT+CMGR Read SMS
AT+CMGS Send SMS
AT+CMGD Delete SMS
55

CHAPTER FOUR

RESULTS AND DISCUSSIONS

4.1 Introduction

This chapter presents the experimental tests and results obtained on each component in

the process of designing the greenhouse prototype. It also gives in details the

experimental results on testing the performance of the designed prototype of

greenhouse system. First the experiments were carried out on the LDR sensor, the

DHT11 sensor, the HD44780U LCD module, the HCO5 Bluetooth module, the GSM

SIM800L module, the 5 V 4 channels relay module and the LM2596 power regulator.

Then after each of the parts was tested on breadboard, all the parts were assembled on

the PCB to form the desired greenhouse system. Finally the performance of the

designed system was tested and the results obtained.

4.2 Experiments and Results

4.2.1 Testing the LDR Sensor

This study utilized the LDR3190 light sensor from Sunrom Company. Three tests were

done to determine the state of the LDR sensor. First, the LDR sensor was subjected to

a bright light from the sun on a sunny day at noon, then the LDR sensor leads were

connected to the multimeter terminals and the multimeter indicated a low resistance

reading of 99.99 Ω. Secondly, the LDR was subjected to darkness by covering it with

an opaque paper, then the LDR leads were connected to the multimeter terminals and

the multimeter indicated a high resistance reading of 999.98 KΩ. This was in agreement

with manufacture resistance of 100 Ω at bright sun light and the resistance of 1000 KΩ

at total darkness. The final test was on calibration of the LDR sensor to measure light
56

intensity. To achieve this a standard light meter was placed side by side with the sensor

and the two subjected to illumination from various sources. Then the arduino serial

monitor values compared with the standard metre value of bright sunlight at noon. The

light metre value reading was 29999.984 lux when the arduino value was 01. This was

in agreement with manufacturer light intensity of 30000 lux on bright sunlight. The

sensor was subjected to four other sources and Eq. 4.1 was applied to calculate light

intensity of these sources. The values were compared to standard metre values as shown

in table 4.1. There was an error margin of ±1lx implying that the sensor was accurate

and hence reliable in the measurement light intensity.


29999.984
Light intensity(Lx) = (4.1)
AV

where: AV is value at the analogue input pin of the microcontroller connected to

potential divider.

Table 4.1: Light Intensity from Different Sources


Light Source Arduino Light Intensity Standard Metre
Illumination Value Value (lx) Value (lx)
Moonlight
(0.0006 W/m2) 1018 0.098 0.108
Bulb 1 49.980
(60 W) 600 48.432
Bulb 2 99.987
(100 W) 300 100.032
Bulb 3
(180 W) 60 499.985 498.232
Bright Sunlight
(4 × 1026 W) 01 29999.984 30001.357

Figure 4.1 shows how the LDR sensor was connected to Arduino board to enable it

communicate with the microcontroller. First, the LDR was connected to the analog

input pin 0 on the Arduino board through a voltage divider configuration. A 100 KΩ

resistor was also connected to the same leg and grounded. The other leg of the LDR

sensor was connected to VCC on the Arduino board.


57

Figure 4.1: Interfacing the LDR to Arduino

Then a program to control the LDR sensor was uploaded to the Arduino ATmega328

microcontroller. Once the program was uploaded, the output of the sensor was tested

by varying light on its surface. The sensor resistance value as observed on the Arduino

serial monitor, increased with decrease in brightness and vice versa. This was in

agreement with circuit set up. Figure 4.2 shows the Arduino serial monitor readings

from analogue pin of the microcontroller.

Figure 4.2: LDR Sensor Output on Arduino Serial Monitor


58

To determine the light intensity, the LDR was calibrated using a standard light meter

results in table 4.1 and Eq. 4.1 was incorporated into the system software.

4.2.2 Testing the DHT11 Sensor

This research used the PCB mounted DHT11sensor, from Sunrom Company. Figure

4.3 shows how the DHT11 was interfaced to the Arduino during testing process. The

DHT11 library files were installed from the arduino libraries and included in the sketch.

To output the humidity and temperature readings, a program to control the DHT11

sensor was uploaded to the Arduino ATmega328 microcontroller.

Figure 4.3: Interfacing the DHT11 to Arduino

Figure 4.4: DHT11 Data Output on Arduino Monitor


59

Figure 4.4 shows the Arduino serial monitor indicating the values of temperature and

humidity as measured by the DHT11 sensor.

To study the performance characteristics of the DHT11 sensor: the DHT11 sensor,

hygrometer and mercury thermometer were simultaneously exposed to three different

conditions. The first test was done inside Kenyatta University Physics research

laboratory. The second test was done inside a wooden box placed in the Kenyatta

University Physics research laboratory. The third test was done outside the Kenyatta

University Physics research laboratory. The data was taken at five minutes intervals for

a period of 60 minutes. Table 4.2 shows the humidity and temperature measurements

for the data taken inside the laboratory.

Table 4.2: Humidity and Temperature Data inside the Laboratory

Time (min) Humidity (%) Temperature (oC)


DHT11 (±1) Hygrometer DHT11 (±) Thermometer
0 20 20 18 17
5 19 20 15 16
10 20 21 17 17
15 20 18 15 16
20 19 17 15 14
25 19 20 17 16
30 20 21 16 17
35 19 20 16 17
40 20 22 16 15
45 20 18 16 15
50 20 21 16 17
55 19 20 16 15
60 19 18 16 17

From the table it is evident that the DHT11 sensor compared well with the hygrometer

and the thermometer in measuring the humidity and temperature in an ordinary

environment with average humidity and temperatures. Figure 4.5 shows humidity and

temperature graph plotted against time for the data in table 4.2.
60

Humidity and Temperature Versus Time

DHT11 Humidity Values Hygrometer Humidity Values


DHT11 Temperature Values Thermometer Temperature Values
25
Humidity (%) and Temperature (oC)

20

15

10

0
0 5 10 15 20 25 30 35 40 45 50 55 60
Time (min)

Figure 4.5: Comparisons of Humidity and Temperature inside Laboratory

In the second test, the sensor was used to measure temperature and humidity levels

outside the laboratory and the measurement results recorded for a period of 60 minutes.

These data were collected on a cold drizzling day to find the effects of exposing the

DHT11 sensor to extreme humid environment and constant temperatures. Table 4.3

shows the measurements data against time.

Table 4.3: Humidity and Temperature Data outside Laboratory

Time (min) Humidity (%) Temperature (oC)


DHT11 (±1) Hygrometer DHT11 (±1) Thermometer
0 77 77 15 16
5 77 77 15 16
10 77 78 15 15
15 77 78 15 14
20 78 77 15 15
25 78 78 15 16
30 78 79 15 14
35 78 77 15 14
40 77 76 15 14
45 80 79 15 15
50 80 80 15 16
55 80 81 15 15
60 80 80 15 16
61

Figure 4.6 shows humidity and temperature graph plotted against time for the data in

table 4.3.

Humidity and Temperature Versus Time

DHT11 Humidity Values Hygrometer Humidity Values


DHT11 Temperature Values Thermometer Temperature Values
Humidity (%) and Temperature (oC)

90
80
70
60
50
40
30
20
10
0
0 5 10 15 20 25 30 35 40 45 50 55 60
Time (min)

Figure 4.6: Comparisons of Humidity and Temperature outside Laboratory

The final test was done inside a wooden box for the same period of time. These data

were collected inside a closed wooden box to find the effects of exposing the DHT11

sensor to constant humid environment and constant temperatures. Table 4.4 shows

record of measured data against time.

Table 4.4: Humidity and Temperature Data inside Box


Time (min) Humidity (%) Temperature (oC)
DHT11 (±1) Hygrometer DHT11 (±1) Thermometer
0 21 20 19 18
5 21 21 19 19
10 21 12 19 18
15 19 18 20 21
20 19 19 20 21
25 19 20 19 18
30 19 20 18 17
35 17 18 19 18
40 17 19 19 18
45 17 18 19 19
50 17 17 19 19
55 18 17 19 20
60 17 16 19 18
62

Figure 4.7 shows humidity and temperature graph plotted against time for the data in

table 4.4.

Humidity and Temperature versus Time

DHT11 Humidity Values Hygrometer Humidity Values


DHT11 Temperature Values Thermometer Temperature Values
Humidity (%) and Temperature (oC)

25

20

15

10

0
0 5 10 15 20 25 30 35 40 45 50 55 60
Time (min)

Figure 4.7: Comparisons of Humidity and Temperature inside Box

These measurements were compared to the hygrometer and the mercury thermometer

measurements and they were found to have an error margin of ±1. Hence the DHT11

sensor was accurate, and hence reliable for the measurement of humidity and

temperature in this research work.

4.2.3 Testing the HD44780U LCD Module

Figure 4.8: Interfacing the LCD to Arduino


63

Figure 4.9 shows how the LCD module was interfaced with Arduino during testing.

When the program to control the LCD was uploaded to the Arduino board, the LCD

displayed the words ‘hello, world’ after every second. After testing the working of the

LDR sensor, the DHT11 sensors and the LCD, the three were combined on a bread

board as shown on the picture in figure 4.9. Then a combined program in Appendix F

was uploaded to Arduino to test their working. The LCD displayed temperature,

humidity and light values automatically.

Figure 4.9: Sensors and LCD Module during Test

4.2.4 Testing the GSM SIM800L Module

The GSM SIM800L was interfaced with Arduino as shown in figure 4.11. First, a SIM

card personal identification number (PIN) was disabled, then inserted in the GSM

module as shown in figure 4.10.

Figure 4.10: GSM SIM800L SIM Card


64

Figure 4.11: Interfacing the GSM SIM800L to Arduino

To enable Arduino to communicate with GSM SIM800L module, a program to control

the GSM SIM800L was uploaded to the Arduino ATmega328 microcontroller. The

serial monitor baud rate was synchronized with that of the SIM800L GSM module at

baud rate of 9600 as shown on the program in Appendix G. An SMS was sent via

Arduino serial monitor and viewed on a cell phone. Another SMS was sent using the

same cell phone to the SIM800L GSM module and viewed on Arduino monitor as

shown in the diagram on figure 4.12.

Figure 4.12: Testing GSM SIM800L output on Arduino IDE


65

4.2.5 Testing the HC05 Bluetooth

Figure 4.13 shows the bluetooth module connection to Arduino during testing.

Figure 4.13: Interfacing the HC05 Bluetooth to Arduino

The programs to control the Bluetooth (in Appendix H and Appendix I) were uploaded

one at time to test the working of HC05 Bluetooth module. The bluetooth application

software on the phone was opened and a connection between the phone and the module

was established. The serial monitor was also opened and “bluetooth test” was seen

scrolling up the screen in both windows.

4.2.6 Testing the 4 Channel 5 V Relay Module

Figure 4.14 shows how the relay module was interfaced with Arduino during testing.

Figure 4.14: Interfacing the Relay Module to Arduino


66

The program to control the relays (Appendix J) was uploaded to the Arduino to test the

module. When the relay module was turned, the four LEDs turned on one by one

repeatedly meaning that the module was working well.

4.2.7 Testing the LM2596 Power Regulator

A step down transformer converted the source 240 V a.c to 12 V a.c which was

converted to 12 d.c by a rectifier. The 12 V d.c was back converted to 5 V by the

LM2596 power regulator. The 5 V power supply for the greenhouse prototype was

provided by the LM2596 regulator. To test the stability of the power regulator, it output

was connected to some resistors in series and voltage across them was measured. Table

4.5 shows the output voltage and their corresponding errors. The power regulator

produced 4.99 V irrespective of the load at the output. This implied that the regulator

error was 0.005 %, this is in line with manufacturer voltage of 5 V at and the load

capacity of 10 KΩ.

Table 4.5: LM2596 Regulator Output Voltage versus Resistances

Resistances
𝐕𝐎𝐮𝐭 (V) Error
(K Ω)
1 4.99 0.005
2 4.99 0.005
3 4.99 0.005
4 4.99 0.005
5 4.99 0.005
6 4.99 0.005
7 4.99 0.005
8 4.99 0.005
9 4.99 0.005
10 4.99 0.005
∞ 4.99 0.005
67

Once the sensors, relays, GSM module and bluetooth module were tested on the

breadboard, soldering of each of the component was done on the PCB. The complete

designed system on the PCB is clearly show on the photo in figure 4.15. The actuation

unit comprised of 5 V four channel relay module. The module was chosen because our

project required four actuators (bulb, fan, heater and sprinkler).

LDR

GSM Module
GSM Power
Regulator Relay modules

Microcontroller

Bluetooth module

LCD

DHT 11 Sensor

GSM Antenna

Figure 4.15: Designed Greenhouse System on the PCB 23

The complete designed greenhouse prototype is shown on figure 4.16. The prototype

dimensions are 0.5 m (length) × 0.30 m (breadth) × 0.6 m (height). It is comprised of

two fans to enable the cooling of the system and control humidity, a bulb to light the

system, a sprinkler connected to a water source through a pump to provide humidity

and heater to supply heat. The LDR sensor measure light illuminance while the

DHT11sensor measured temperature and humidity, and their positions in the prototype

a clearly indicated. The control station consisted of the LCD, the GSM SIM800L

module, the HCO5 Bluetooth module and the ATmega328 microcontroller chip.
68
Complete System Design
Bulb
Fans DHT11 Sensor LDR Sensor
Power Source

LCD
Heater Pump
Sprinkler Control Station
Figure 3.19 24
Figure 4.16: Complete Designed Prototype Greenhouse without Cover

4.3 Program Test

In this research; to test the functioning of the sensors, the GSM module, the Bluetooth

module, the LCD module, and the relay modules, separate programs were designed,

developed and implemented. Several simulations and tests were conducted on the

devices and after confirmation of each program proper working, all these programs

were integrated to form one comprehensive program to operate the whole greenhouse

prototype. The comprehensive program was simulated on the Arduino serial monitor

before uploading to the ATmega328 microcontroller to ascertain it workability. The

software uploading to the ATmega328 controller, was done by first housing the chip to

the Arduino board and then configuring the board and the ports as shown on figure

4.17. After uploading the program, the microcontroller was dismantled from the

Arduino board and plugged in the designed PCB system to operate the system.
69

Figure 4.17: Configuring the Arduino Ports

4.4 Testing the Designed Prototype Greenhouse

The greenhouse system developed in this study automates the process of monitoring

and control of greenhouse parameters. The GSM SIM800L and Bluetooth HC05

modules provides wireless communication. The input part comprised of the light,

temperature and humidity sensors for detecting light illuminance, temperature and

humidity levels respectively. The outputs of the system microcontroller comprised of

the relay module, the GSM module and the Bluetooth module.

4.4.1 Testing Transmission of the GSM SIM800L

To test the transmission speed of the GSM SIM800L, an experiment to investigate time

difference between the GSM and LCD readings was conducted. Table 4.6 shows the

results obtained in this experiment for comparison between the readings of the phone

and the LCD. This implies that the ATmega328 and the GSM SIM800L are sufficiently

quick to give greenhouse parameter information on time.


70

Table 4.6: Comparisons of the LCD and GSM Readings

Trials LCD Readings GSM Readings

Time of Humidity Temperature Light Humidity Temperature Light


the Day (%) (ºC) (lx) (%) (ºC) (lx)

08.00 a.m 30 17 112 30 17 112

08.15 a.m 31 18 123 31 18 123

08.30 a.m 30 19 132 30 19 132


08.45 a.m 33 20 189 33 20 189
09.00 a.m 36 21 234 36 21 234
09.15 a.m 39 20 231 39 20 231
09.30 a.m 38 19 228 38 19 228

4.4.2 Testing Range the HC05 Bluetooth

To operate the greenhouse prototype via bluetooth signals, an application software

called Bluetooth Terminal was downloaded from Google applications store, then

installed in the cell phone. Finally the application was configured and when the link

between the HC05 Bluetooth and the cell phone was established, monitoring of the

greenhouse prototype was possible.

To establish the maximum distance of connection of the HC05 Bluetooth, the phone

with the bluetooth application was moved away from the system. The distance of the

phone from the greenhouse system was decreased carefully and the largest distance

when there was connection recorded as shown on table 4.7. From these results the HC05

Bluetooth connected within a radii of 10 m. The distance decreased in case there was

an object blocking the phone. The manufacture recommended distance is 8 to10 metres.
71

Table 4.7: HC05 Bluetooth Range

Attempt Length (m)

1 10.4

2 9.9
3 10.2
4 10.3
5 10.8
6 10.4
7 10.0
8 10.2
9 10.0
Average 10.2

4.4.3.1 Performance Parameters of the Prototype Greenhouse

An experimental study was carried out, outside Kenyatta university Physics laboratory

2 in the month of September, 2018, to determine the performance parameters of the

designed prototype greenhouse system, as well as the gradients of humidity and

temperature along the prototype with the actuators enabled. Measurements were taken

using seven sensors at different positions. Five DHT11 sensors and two LDR sensors

were used during the experiments. One DHT11 sensor and one LDR sensor were placed

outside the prototype for outside measurements. The other one LDR sensor was

suspended high inside the prototype, four DT11 sensors were mounted inside the

prototype. The four DHT11 sensors were placed, according to positions S2,S3,S4 and

S5 as “very close to outflow fan”, “next to outflow fan”, “centre”, and “next to inflow

fan”, respectively. The sensor positions were labelled (S1) to (S7). (S1): outside DHT11

sensor, (S2-S3-S4-S5): inside DHT11 sensors, (S6): inside LDR sensor, and (S7):
72

outside LDR sensor. The sensors with numbers of (S1-S6-S7) were suspended at a

height of 60 cm from the ground. The sensors with numbers of (S2- S3-S4-S5) were

placed at intervals of 18 cm at heights of 48 cm from the ground inside the prototype.

The actuation unit was turned off between 12:15 and 13:15, and turned on between

14:15 and 15:15 for five days. The temperature, pressure and light intensity values were

noted at 5 minutes intervals and average per hour computed and recorded down.

The levels of average light intensity per hour inside the prototype were approximately

550 lx (system off), and 569 lx (system on), respectively. When the system was off;

between 12:15 and 13:15, levels of average temperature per hour calculated for S2, S3,

S4 and S5 were approximately 32 °C, 30 °C, 31 °C, and 29 °C, respectively, along the

horizontal axis from the inflow fan through the sprinkler, to the outflow fan, After

turning on the system, at stable cooling conditions between 14:15 and 15:15, levels of

average temperature per hour calculated for S2, S3, S4 and S5 dropped to

approximately 20 °C, 24 °C, 27 °C, and 26°C respectively.

When the system was off, levels of average humidity per hour calculated for S2, S3, S4

and S5 were approximately 29%, 40%, 38%, and 46%, respectively. At 14:15 – 15:15,

levels of average humidity per hour calculated for S2, S3, S4 and S5 sensors positions

rose up to approximately 67%, 55%, 49%, and 56%, respectively. These results are

integrated in Table 4.8 for both temperature and humidity gradients.

The results for the performance parameters of prototype greenhouse system during the

experiments are summarized in table 4.9. The average (Av.), the standard deviation

(S.D.), the Minimum (Min) and Maximum (Max) values are clearly indicated. The
73

difference between the outside temperature and inside temperature is an important

parameter to describe the cooling performance of the two fan actuation system.

Therefore, the cooling effect of the system was calculated from the equation 4.2;

∆t ce= t ο − t i (4.2)

Where: 𝑡𝜊 = outside air temperature (°C) and 𝑡𝑖 = inside air temperature (°C)

The cooling efficiency (η) of the system was determined as the ratio between the fall in

air temperature after passing through the inflow fan and the maximum drop under

conditions of air saturation, and was calculated using the equation 4.3;

t (1) − t (2)
η = t db(1) − t db (1) × 100 (4.3)
db wb

Where: η = cooling efficiency (%), t db (1) = outside dry-bulb temperature (°C) of

entering air to inflow fan, t db (2) = dry-bulb temperature (°C) of leaving air from

inflow fan, t wb (1) = outside wet-bulb temperature (°C) of entering air to inflow fan.

Table 4.8: Temperature and Humidity According to Sensor Positions


Sensor Positions
S1 S2 S3 S4 S5
Greenhouse Actuator
Close to Next to Next to
Parameters Status
Outside Outflow Outflow Middle Inflow
Fan Fan Fan
Off 32.03 32.02 30.10 30.93 29.02
Temperature S.D. 0.27 0.42 0.43 0.37 0.54
(°C ) On 31.43 20.27 24.50 27.04 26.18
S.D. 0.173 0.17 0.15 0.31 0.18
Δt - 11.75 5.60 3.89 2.84
Off 24.67 28.52 40.06 37.55 45.79
S.D. 1.53 1.44 1.79 1.07 1.57
Humidity (%) On 23.03 66.96 55.50 48.67 55.98
S.D. 1.06 0.83 0.46 0.68 0.92
Δrh - 38.44 15.44 11.12 10.19

From these results, when the actuators were on, the internal temperature was 24.5 ºC

while external temperature was 31.43 ºC. This implies that the internal temperatures
74

were lower than external temperatures. The average cooling effect and cooling

efficiency per hour for designed prototype system were 6.9 ºC and 75.9%, respectively.

At stable cooling state, the maximum cooling efficiency was 78%.

Table 4.9: Performance Parameters of the Prototype Greenhouse

Quantities Symbol Av S.D. Min Max


Outside Temperature
(°C) to 31.4 0.17 31.1 31.8
Wet-bulb
Temperature (°C) twb 16.9 0.28 16.4 17.7
Temperature (°C) at
Outflow Fan t2 20.4 0.13 20.2 20.8
Inside Temperature
(°C) ti 24.5 0.14 24.3 24.7
Cooling Effect (°C) ∆𝑡𝑐𝑒 6.9 0.27 6.8 7.1
Cooling Efficiency
(%) η 75.9 1.32 74.2 78.0

4.4.3.2 Monitoring and Control Experiments

To test the performance of the designed prototype greenhouse, two sets experimental

investigations were carried out. First, the sensor values were collected from the

prototype at intervals of 15 minutes for ten hours (from 8 a.m to 6 p.m), with actuators

enabled to maintain greenhouse parameters within the optimum range. Secondly, the

sensors measured values were collected from the prototype for the same time frame,

with actuator off to show effects of the designed control system.

Table 4.10 shows the data for temperature with and without control from 8 a.m to 6

p.m. The first temperature column shows values of the temperature change with

relevant control procedures while the second column shows temperature change

without using control procedures.


75

Table 4.10: Prototype Greenhouse Data for Temperature

Temperature(ºC) Temperature(ºC)
Time of Time of
the Day With Without the Day With Without
(Hrs) Control Control (Hrs) Control Control

08.00 a. m. 21 16 01.15 p.m. 20 28


08.15 a.m. 19 17 01.30 p.m. 23 29
08.30 a.m. 21 17 01.45 p.m. 24 29
08.45 a.m. 23 19 02.00 p.m. 21 28
09.00 a.m. 20 18 02.15 p.m. 23 27
09.15 a.m. 25 17 02.30 p.m. 21 25
09.30 a.m. 24 19 02.45 p.m. 20 26
09.45 a.m. 20 20 03.00 p.m. 20 27
10.00 a.m. 22 22 03.15 p.m. 21 25
10.15 a.m. 21 21 03.30 p.m. 22 26
10.30 a.m. 23 20 03.45 p.m. 22 23
10.45 a.m. 21 24 04.00 p.m. 24 24
11.00 a.m. 22 25 04.15 p.m. 23 21
11.15 a.m. 23 27 04.30 p.m. 20 22
11.30 a.m. 24 28 04.45 p.m. 24 23
11.45 a.m. 23 29 05.00 p.m. 22 20
12.00 a.m. 25 30 05.15 p.m. 20 21
12.15 p.m. 24 31 05.30 p.m. 21 18
12.30 p.m. 23 31 05.45 p.m. 20 17
12.45 p.m. 23 29 06.00 p.m. 23 16
01.00 p.m. 21 28

Optimum temperature range was set as illustrated in figure 4.18. The range of

temperature was between 18 ºC and 26 ºC, otherwise relevant actuator was activated.

Heater will be < Ideal temperature > Fan will be


ON 18 - 26 ºC ON

Figure 4.18: Relay Condition for Prototype Greenhouse Temperature

Figure 4.19 shows a graph of the temperature variation for the 10 hours, the change in

temperature with actuator off is represented by the red line. It is evident that,

temperature increased with time to a maximum of 31 ºC at 12.30 p.m. Crops growth


76

and development are affected by high temperatures since high temperature affect

enzyme structure and their working. The change in temperature with actuators on is

represented with the blue line. The effect of the actuators is evident in that the

temperature is maintained within the optimum levels.

Temperature Versus Time of the Day

Temperature With Control Temperature Without Control

30

25
Temperature (oC)

20

15

10
08.00 a. m. 10.30 a.m. 01.00 p.m. 03.30 p.m. 06.00p.m.
Time of the Day (Hrs)

Figure 4.19: Prototype Greenhouse Temperature Graphs

Table 4.11 shows the data for humidity with and without control from 8 a.m to 6 p.m.

The first humidity column shows values of the humidity change with relevant control

procedures while the second column shows humidity change without using control

procedures.
77

Table 4.11: Prototype Greenhouse Data for Humidity

Humidity (%) Humidity (%)


Time of the Time of the
Day (Hrs) With Without Day (Hrs) With Without
Control Control Control Control

08.00 a.m. 69 91 01.15 p.m. 51 19


08.15 a.m. 73 90 01.30 p.m. 48 17
08.30 a.m. 75 82 01.45 p.m. 57 18
08.45 a.m. 72 81 02.00 p.m. 58 18
09.00 a.m. 70 79 02.15 p.m. 59 20
09.15 a.m. 71 77 02.30 p.m. 60 21
09.30 a.m. 70 78 02.45 p.m. 56 20
09.45 a.m. 66 76 03.00 p.m. 53 21
10.00 a.m. 64 66 03.15 p.m. 56 20
10.15 a.m. 60 65 03.30 p.m. 51 23
10.30 a.m. 65 63 03.45 p.m. 59 26
10.45 a.m. 66 59 04.00 p.m. 57 31
11.00 a.m. 57 37 04.15 p.m. 56 34
11.15 a.m. 58 38 04.30 p.m. 57 39
11.30 a.m. 53 35 04.45 p.m. 61 45
11.45 a.m. 60 33 05.00 p.m. 59 47
12.00 a.m. 57 30 05.15 p.m. 60 58
12.15 p.m. 56 29 05.30 p.m. 62 63
12.30 p.m. 53 23 05.45 p.m. 63 70
12.45 p.m. 57 24 06.00 p.m. 65 75
01.00 p.m. 52 21

Figure 4.20 shows the graph of humidity readings for the 10 hours. The change in
humidity with the actuators off is represented by the red line. It is evident that humidity
decreased to 17 % by 1:30 p.m., crops growing in dry air lose a lot of water through the
process of transpiration. Similarly if humidity is above 80 percent, there risk of spread
of fungal diseases. In both cases crops can be affected in flower and fruit growth stages,
hence controlling humidity is crucial.

The change of humidity with actuator enabled is represented by the blue line, it is
evident that humidity levels were maintained within the optimum range throughout the
test period
78

Humidity Versus Time of the Day

Humidity With Control Humidity Without Control

90

80

70
Humidity (%)

60

50

40

30

20

10
08.00 a.m. 10.30 a.m. 01.00 p.m. 03.30 p.m. 06.00 p.m.
Time of the Day (Hrs)

Figure 4.20: Prototype Greenhouse Humidity Graphs

The optimum humidity range was set as illustrated in figure 4.21. The range of humidity

was between 40% and 80%, otherwise relevant actuator was activated.

< >
Sprinkler will be Humidity Fun will be
ON 40% - 80% ON

Figure 4.21: Relay Condition for Prototype Greenhouse Humidity

Table 4.12 shows the data for light intensity with and without control for the 10 hours.

The first light column shows values of the light intensity change with relevant control

procedures while the second column shows light intensity change without using control

procedures.
79

Table 4.12: Prototype Greenhouse Data for Light Intensity

Light Intensity (lx) Light Intensity (lx)


Time of the Time of the
Day (Hrs) With Without Day (Hrs) With Without
Control Control Control Control
08.00 a.m. 540 486 01.15 p.m. 889 1080
08.15 a.m. 598 503 01.30 p.m. 867 1085
08.30 a.m. 618 472 01.45 p.m. 783 1083
08.45 a.m. 625 689 02.00 p.m. 980 1092
09.00 a.m. 501 654 02.15 p.m. 970 1085
09.15 a.m. 534 681 02.30 p.m. 969 1082
09.30 a.m. 600 790 02.45 p.m. 673 980
09.45 a.m. 619 787 03.00 p.m. 678 998
10.00 a.m. 677 780 03.15 p.m. 613 820
10.15 a.m. 635 721 03.30 p.m. 611 725
10.30 a.m. 651 745 03.45 p.m. 521 879
10.45 a.m. 680 874 04.00 p.m. 634 731
11.00 a.m. 680 790 04.15 p.m. 690 802
11.15 a.m. 623 783 04.30 p.m. 679 773
11.30 a.m. 730 951 04.45 p.m. 667 845
11.45 a.m. 611 841 05.00 p.m. 545 734
12.00 a.m. 715 933 05.15 p.m. 614 555
12.15 p.m. 731 1001 05.30 p.m. 634 528
12.30 p.m. 623 1031 05.45 p.m. 623 413
12.45 p.m. 849 1021 06.00 p.m. 613 401
01.00 p.m. 867 1060

Figure 4.22 shows the graph of the variation of light intensity with time. The light

intensity with the actuator off is represented by the red line. It is evident that light

intensity increased with time to a maximum value of 1092 lux at 2:00 p.m. and drops

to 401 lux at 6:00 p.m. Light affects crops growth since high light intensity increases

transpiration while crops growing in dark are weak. Light intensity with actuators on is

represented by the blue line. This implies that system was able to maintain light above

500 Lux which is the health light intensity for proper growth and development of crops.
80

Light Intensity versus Time of the Day


Light With Control Light Without Control
1100

1000

900
Light Intensity (lx)

800

700

600

500

400

300
08.00 a.m. 10.30 a.m. 01.00 p.m. 03.30 p.m. 06.00 p.m.
Time of the Day (Hrs)

Figure 4.22: Prototype Greenhouse Light Intensity Graphs


81

CHAPTER FIVE

CONCLUSIONs AND RECOMMENDATIONS

5.1 Conclusions

In this work, design and implementation of a microcontroller based system to monitor

and control greenhouse parameters using sensors, SMS technology and Bluetooth

signals has been achieved. Specifically the following research objectives were

achieved:

(i) The light dependent resistor (LDR) sensor was utilized to measure light intensity

and the DHT11 sensor was utilized to measure humidity and temperature in

greenhouse.

(ii) The sensors, the relays, the LCD, the GSM and the Bluetooth were interfaced to

the microcontroller.

(iii) A program in C language was developed and uploaded to the ATmega328

microcontroller to control the greenhouse prototype.

(iv) The prototype greenhouse system is able to: Measure the temperature levels, the

humidity levels and the light illuminance values in the greenhouse, display the

values on the LCD, transmit it to the owner’s phone via the Bluetooth or the

GSM modules and keep these parameters at optimum levels by use of the fans,

the heater, the bulb and the sprinkler.

5.2 Recommendations

The designed automatic greenhouse prototype was able to monitor and control the

greenhouse parameters and keep them at optimum range. However some modifications

can be put into place to enhance its robustness. These include:


82

(i) The reliability of the designed system can be exploited to build a network of

such monitoring and control systems for several greenhouses.

(ii) The designed prototype greenhouse can be applied in the agricultural sector

to design and implement smart greenhouses.

5.3 Recommendations for further research

For further research on the designed prototype greenhouse system, this study

recommends the following:

(i) A website can be incorporated in the designed system to monitor the actual

greenhouse values and save the data in an online database for future reference.

(ii) A power backup from solar cells can be included in the system to provide

electricity in case of power blackout and also lower the cost of the operating

the prototype greenhouse.


83

REFERENCES

Arduino Corporation. (2013). Arduino:Arduino Corporation. Retrieved July 17, 2013,


from Arduino Corporation Web site: http://arduino.cc/en/Main/ArduinoBoardUno

Augarten, S. (1983). The Most Widely Used Computer on a Chip: The TMS 1000. State
of the Art: A Photographic History of the Integrated Circuit. New York: Ticknor &
Fields.

Dabadi, H. (2003). Techonology Transfer:Capacity building and the Private Sector of


Nepal. New York: United Nations.

Fraden, J. (2010). Handbook of Modern Sensors: Physics, Designs, and Applications. .


Pringer Science & Business Media.

Guraiah, B., and Nagaswetha, G. (2014). GSM Based Greenhouse Monitoring System
for Agriculture Field. International Journal of Professional Engineering Studies, 3(3).

Han, M., and Zhao, P. (2011). Design of temperature humidity wireless sensor network
node based on DHT11. Journal of Jinggangshan University (Natural Science), 32: 67-
70.

Howard, A. (1991). Data Acquisition Techniques Using Personal Computers. San


Diego: Academic Press.

Huho, J., and Kosonei, R. (2010). Understanding Extreme Climatic Events for
Economic Development in Kenya. International Organization of Scientific Research
Journal of Environmental Science, Toxicology and Food Technology, 8: 14-25.

Karvinen, T., and Karvinen, K. (2014). Getting Started with Sensors: Measure the
World with Electronics, Arduino, and Raspberry Pi. Maker Media, Inc.

Marhaento, B., and Singh, H. (2002). Development of a Computer Based Greenhouse


Environment Controller. Proceedings of the World Congress of Computers in
Agriculture and Natural Resources, (pp. 13-15). Retrieved December 23, 2018, from
American Society of Agriculture and Biological Engineers: http;//www.asabe.org

Mizunuma, S., Katoh, T., and Hata, S. (2003). Applying IT to farm fields—a wireless
LAN. Journal of Nippon Telegraph and Telephone Technical Corporation Review, 2:
56–60.

Morais, R., Cunha, J., Cordeiro, M., Serodio, C., Salgado, P., and Couto, C. (1996).
Solar data acquisition wireless network for agricultural applications. Proceedings of the
19th IEEE Convention of Electrical and Electronics Engineers in Israel, (pp. 527–530).
Jerusalem, Israeli.

Narasaiah, M. (2007). Energy and food security. New Suchin: Delhi.


84

Obanda, W. (2010). Design and fabrication of an electronic system for monitoring and
controlling temperature, light illuminance and humidity in a greenhouse. Master's
thesis,Kenyatta University,Kenya.

Paavola, M. (2007). Wireless Technologies in Process Automation - A Review and an


Application Example. Oulu,Finland: University of Oulu.

Plaksina, O., & Raush, T. (2005). Development of a KNX Based Greenhouse Climate
Control. Journal of Vienna University of Technology, Institute of Computer
Technologies, 27-29.

Pushkar, M., and Amey, D. (2016). PIC Microcontroller Based Greenhouse Monitoring
and Control System. International Journal of Advanced Research in Electrical,
Electronics and Instrumentation Engineering, 5(9).

Quan, M. (2011). Automated Wireless Greenhouse Management System. New Zealand:


Massey University.

Rana, H., Ali, F., and Moofed, T. (2013). Wireless Monitor and Control system for
greenhouse. International Journal of Computer Science and Mobile Computing, 2 (12):
69-87.

Remya, K., Yaseen, M., Nisil, M., and Ajay, M. (2016). Greenhouse Monitoring and
Control Based on IOT Using WSN. ITSI Transactions on Electrical and Electronics
Engineering(ITSI-TEEE), 4 (3): 2320-8945.

Soredio, C., Montiero, J., and Coutu, A. (1998). Integrated network for agricultural
management applications. Proceedings of the IEEE International Symposium on
Industrial Electronics, 2: 679–683. Pretoria, South Africa.

Soto- Zarazua G., Romero- Archuleta B., Mercado- Luna A., Toledano- Ayala M.,
Rico- Garcia E. ,Peniche- Vera R. and Herrera- Ruiz G. (2011). Trends in Automated
Systems Development for Greenhouse Horticulture. International Journal of
Agricultural Research, 6 (1): 1-9.

Suribabu, K., and Naidu, T. (2016). Dsign of Intelligent Greenhouse Monitoring and
Control System Based on CAN Bus. International Journal of Innovative Technologies,
4(3): 0559-0565.

Swarna, P., Shanaz, A., and Rupanita, D. (2015). Computerized Greenhouse Data
Acquisition System Using Arduino with LabVIEW. International Journal of Advanced
Research In Electrical, Electronics And Instrumentation Engineering, 4 (4).

Tianlong, N. (2010). Application of Single Bus Sensor DHT11 in Temperature


Humidity Measure and Control System. Microcontrollers & Embedded Systems, 6:
026.

Wanjiru, S., Wanjiru, G., and Wanjiku, M. (2014). Status Report on the Kenya National
Food Security: Zero Tolerance to Hunger. Nairobi, Kenya: University of Nairobi.
85

APPENDICES

APPENDIX A: Flow Chart of the Prototype Greenhouse Program

START

INITIALIZE SENSORS,
ACTUATORS &MODULES

READ TEMP

YES
IS TMIN<TEMP<TMAX? MAINTAIN

NO

YES IS YES
IS PUT OFF
HEATER
TEMP>TMAX? HEATER
ON?

NO
NO PUT ON
YES FAN
IS
PUT OFF FAN
FAN ON?

NO

YES YES
IS IS PUT OFF
TEMP<TMIN? FAN ON? FAN

NO NO
PUT ON
HEATER

IS YES
PUT OFF
HEATER
FAN
ON?

NO
1 2 3
86

1 2 3

READ HUMIDITY

IS YES
MAINTAIN
HMIN<HUM<HMAX?

NO

IS YES IS YES PUT OFF


HUM>HMAX PUMP ON? PUMP
?
NO NO
PUT ON
FAN
IS YES PUT OFF
FAN ON? FAN

NO

IS YES YES
IS PUT OFF
HUM<HMIN? FAN ON? FAN

NO NO PUT ON
PUMP
YES PUT OFF
IS
PUMP ON? FAN

NO

ANY YES
ERROR?

NO

SEND SMS

STOP
87

APPENDIX B: ATmega328 Pins Configuration

Pin Pin Description Secondary Function


Name
1 PC6 Pin 6 of PORTC RESET pin
2 PD0 Pin 0 of PORTD RXD for USART
3 PD1 Pin 1 of PORTD TXD for USART
External Interrupt 2 Input
4 PD2 Pin 2 of PORTD External Interrupt source 0
5 PD3 Pin 3 of PORTD External Interrupt source1
PWM - Timer/Counter2 Output
6 PD4 Pin 4 of PORTD Timer0 External Counter Input
USART External Clock I/O
7 VCC Positive voltage connection
8 GND Ground connection
9 PB6 Pin 6 of PORTB Clock Oscillator pin 1
Timer Oscillator pin 1
10 PB7 Pin 7 of PORTB Clock Oscillator pin 2
Timer Oscillator pin 2
11 PD5 Pin 5 of PORTD Timer1 External Counter Input
PWM Counter0 Output B Compare
12 PD6 Pin 6 of PORTD Analog Comparator Positive I/P
PWM Counter0 Output A Compare
13 PD7 Pin 7 of PORTD Analog Comparator Negative I/P
14 PB0 Pin 0 of PORTB Counter1 Input Capture Pin
15 PB1 Pin 1 of PORTB Counter1 Output Compare A Output
16 PB2 Pin 2 of PORTB SPI Slave Select Input
Counter1 Output Compare A Output
17 PB3 Pin 3 of PORTB MOSl input
SPI for programming
Counter2 Output Compare B Output
18 PB4 Pin 4 of PORTB MISO
SPI for programming
19 PB5 Pin 5 of PORTB SPI Bus Serial Clock
SPI for programming
20 AVCC Power for Internal ADC
21 AREF ADC Analog Reference Pin
22 GND GROUND
23 PC0 Pin 0 of PORTC ADC Input Channel 0
24 PC1 Pin 1 of PORTC ADC Input Channel 1
25 PC2 Pin 2 of PORTC ADC Input Channel 2
26 PC3 Pin 3 of PORTC ADC Input Channel 3
27 PC4 Pin 4 of PORTC ADC Input Channel 4
2-wire Serial Bus Data I/O
28 PC5 Pin 5 of PORTC ADC Input Channel 5
Two-wire Serial Bus Clock Line
88

APPENDIX C: Code Listing 1

//This code tested the functioning of the LDR sensor.

//It instructs the microcontroller to read and print the sensor values on the Arduino IDE.

int sensorPin = A0;


int sensorValue = 0;

void setup() {
Serial.begin(9600);
}

void loop() {
sensorValue = analogRead(sensorPin);
Serial.println(sensorValue);

delay(100);

}
89

APPENDIX D: Code Listing 2

//This code tested the functioning of the DHT11 sensor.

//It instructs the microcontroller to read and print the sensor values on the Arduino IDE.

#include <dht.h>
dht DHT;

#define DHT11_PIN 7

void setup()
{
Serial.begin(9600);
}

void loop()
{
int chk = DHT.read11(DHT11_PIN);
Serial.print("Temperature = ");
Serial.println(DHT.temperature);
Serial.print("Humidity = ");
Serial.println(DHT.humidity);
delay(1000);
}
90

APPENDIX E: Code Listing 3

//This program tested the working of the LCD.

//This sketch prints "Hello World!" on the LCD and turns on and off the display.

#include <LiquidCrystal.h>

const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2; LiquidCrystal lcd(rs, en, d4,


d5, d6, d7);

void setup() {
lcd.begin(16, 2); lcd.print("hello, world!");
}

void loop() {
lcd.noDisplay();
delay(500);
lcd.display();
delay(500);
}
91

APPENDIX F: Code Listing 4

//This software tested the functioning of the LCD, DHT11 sensor and LDR sensor.
// It instructs the microcontroller to read and print the sensor values on the LCD.

#include "Wire.h"
#include "LCD.h"
#include "DHT.h"
#include "LiquidCrystal_I2C.h"
#define DHTPIN 10
#define DHTTYPE DHT11

int ldr = A3;


DHT dht(DHTPIN, DHTTYPE);
LiquidCrystal_I2C lcd(0x27,2,1,0,4,5,6,7);

void setup()
{
lcd.begin (16,2); // 16 x 2 LCD module
lcd.setBacklightPin(3,POSITIVE);
lcd.setBacklight(HIGH);
pinMode(DHTPIN, INPUT);
pinMode(ldr, INPUT);
dht.begin();
}
void loop()
{
int ldrValue = analogRead(ldr);
float humidity = dht.readHumidity();
float temp = dht.readTemperature();

lcd.setCursor(0,0);
lcd.print("T:");
lcd.print(temp);
lcd.print("*C ");

lcd.print("H:");
lcd.print(humidity);
lcd.print("%");
lcd.setCursor(0,1);

lcd.print("Light:");
lcd.print(ldrValue);

delay(1000);
}
92

APPENDIX G: Code Listing 4

//This program tested the working of the GSM SIM800L.

//The program takes commands from the Arduino terminal and sends them to the GSM

Module and vice versa. The code also verifies if the Software Serial library is also

working fine.

#include <SoftwareSerial.h>

String Arsp, Grsp;


SoftwareSerial gsm(10, 11);

void setup() {
Serial.begin(9600);
Serial.println("Testing GSM SIM800L");
gsm.begin(4800);
}

void loop()
{
if(gsm.available())
{
Grsp = gsm.readString();
Serial.println(Grsp);
}

if(Serial.available())
{
Arsp = Serial.readString();
gsm.println(Arsp);
}
93

APPENDIX H: Code Listing 5

//This program tested the working of the HC05 BLUETOOTH.

//This program enables the bluetooth module send data to a connected bluetooth device

#include <SoftwareSerial.h>
SoftwareSerial BTserial(2, 3); // RX | TX
char c = ' ';

void setup()
{
Serial.begin(9600);
Serial.println("Enter AT commands:");
BTserial.begin(9600);
}

void loop()
{
BTserial.println("Bluetooth Test");
Serial.println("Bluetooth Test");
delay(1000);
}
94

APPENDIX I: Code Listing 6

//This program tested the working of the HC05 BLUETOOTH.

//The codes sends the messages from the terminal to the Bluetooth Module and

messages from the Bluetooth module to the terminal.

#include <SoftwareSerial.h>
SoftwareSerial EEBlue(10, 11); // RX | TX

void setup()
{
Serial.begin(9600);
EEBlue.begin(9600); Serial.println("The bluetooth gates are open.\n Connect to HC05
from any other bluetooth device with 1234 as pairing key!.");
}

void loop()
{
if (EEBlue.available()) Serial.write(EEBlue.read());
(Serial.available()) EEBlue.write(Serial.read());
}
95

APPENDIX J: Code Listing 7

//This program tested the working of the 5 V 4 channel relay module.

//This code prints turns on four LEDs one by one repeatedly so long as the relay

module is turned on.

//the relays connect to

int IN1 = 3;
int IN2 = 4;
int IN3 = 5;
int IN4 = 6;
#define ON 0
#define OFF 1

void setup()
{
relay_init();
}

void loop() {
relay_SetStatus(ON, OFF, OFF,OFF);
delay(2000);
relay_SetStatus(OFF, ON, OFF,OFF);
delay(2000);
relay_SetStatus(OFF, OFF, ON,OFF);
delay(2000);
relay_SetStatus(OFF, OFF, OFF,ON);
delay(2000);
}
void relay_init(void)
{
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(IN3, OUTPUT);
pinMode(IN4, OUTPUT);
relay_SetStatus(OFF,OFF,OFF,OFF);
}{
digitalWrite(IN1, status_1);
digitalWrite(IN2, status_2);
digitalWrite(IN3, status_3);
digitalWrite(IN4, status_4);
}
96

APPENDIX K: Entire Prototype Greenhouse Program

// Programmer: STEPHEN NYAGA

// PHYSICS DEPARTMENT

// KENYATTA UNIVERSITY

// Created on: 5th Aug 2018

// The Program controlled fully the prototype greenhouse system

#include "DHT.h"
#include <LiquidCrystal.h>
#include <SoftwareSerial.h>
#include <EEPROM.h>
#include <avr/pgmspace.h>
#include <string.h>
#define DHTPIN 6
SoftwareSerial mySerial(3,4); // RX, TX
LiquidCrystal lcd(8, 9, 10, 11, 12, 13);
const char config_delimeter[2] = "#";
char number[15] = "+254724593277";

const char fan_on_string[] PROGMEM = "Fan switched on.";


const char fan_off_string[] PROGMEM = "Fan switched off.";
const char heater_on_string[] PROGMEM = "Heater swtched on";
const char heater_off_string[] PROGMEM = "Heater switched off";
const char light_on_string[] PROGMEM = "Light switched on";
const char light_off_string[] PROGMEM = "Light switched off";
const char welcome_string[] PROGMEM = "Welcome.System switched on.";
const char config_string[] PROGMEM = "Data configured";
const char manual_activated_string[] PROGMEM = "Manual activated.";
const char auto_activated_string[] PROGMEM = "Auto activated.";
const char temp_overlimit_string[] PROGMEM = "Temperature overlmit.";
const char temp_lowerlimit_string[] PROGMEM = "Temperature lower limit.";
const char light_overlimit_string[] PROGMEM = "Light overlimit.";
const char humidity_overlimit_string[] PROGMEM = "Humidity overlimit.";
const char humidity_lowerlimit_string[] PROGMEM = "Humidity overlimit.";
const char sprinkler_off_string[] PROGMEM = "Sprinkler switched off.";
const char sprinkler_on_string[] PROGMEM = "Sprinkler switched on.";

#define DHTTYPE DHT11 // DHT11


DHT dht(DHTPIN, DHTTYPE);
int ldr_pin = A5;
int light_pin = 14;
int fan_pin = 15;
int heater_pin = 16;
int sprinkler_pin = 17;
97

char sms_rx[122];
boolean data_received = false;
int index = 0;
boolean text_sent = false;
boolean auto_mode = false;

int temp_addr = 20;


int humidity_addr = 30;
int light_addr = 40;

int temp_upper_limit = 26;


int temp_lower_limit = 18;
int humidity_upper_limit = 70;
int humidity_lower_limit = 40;
int light_limit = 900;
char *temp_token;
char *humidity_token;
char *light_token;
char *header_token;

void setup() {

Serial.begin(9600);
mySerial.begin(9600);
lcd.begin(16, 2);
pinMode(ldr_pin, INPUT);
pinMode(light_pin, OUTPUT);
pinMode(fan_pin, OUTPUT);
pinMode(heater_pin, OUTPUT);
pinMode(sprinkler_pin, OUTPUT);
digitalWrite(light_pin,HIGH);
digitalWrite(fan_pin,HIGH);
digitalWrite(heater_pin,HIGH);
digitalWrite(sprinkler_pin,HIGH);
dht.begin();
lcd.print(F("INITIALIZING..."));

temp_upper_limit = EEPROM.read(temp_addr);
humidity_upper_limit = EEPROM.read(humidity_addr);
light_limit = EEPROM.read(light_addr);

delay(20000);
ping_GSM();
mySerial.println(F("welcome"));
send_text(number, welcome_string);
}
int light_value;
float humidity ;
float temperature;
int counter;
98

void loop() {
while (Serial.available() > 0)
{
sms_rx[index] = Serial.read();
mySerial.print(sms_rx[index]);
index++;
data_received = true;
}
if (data_received)
{
sms_rx[index] = '\0';
data_received = false;
process_txt(sms_rx);
for (int j = 0; j <= sizeof(sms_rx); j++)
{
sms_rx[j] = '\0';
}
index = 0;
}
humidity = dht.readHumidity();
temperature = dht.readTemperature();
light_value = analogRead(ldr_pin);
mySerial.print(F("humidity = "));
mySerial.println(humidity);
mySerial.print(F("temperature = "));
mySerial.println(temperature);
mySerial.print(F("light value = "));
mySerial.println(light_value);
if(auto_mode == true){

}
lcd_display();
if(auto_mode){
if(temperature > temp_upper_limit){
send_text(number,temp_overlimit_string);
digitalWrite(fan_pin,LOW);
}
else{
digitalWrite(fan_pin,HIGH);
}
if(temperature < temp_lower_limit){
send_text(number,temp_lowerlimit_string);
digitalWrite(heater_pin,LOW);
}
else{
digitalWrite(heater_pin,HIGH);
}
if(humidity > humidity_upper_limit){
send_text(number,humidity_overlimit_string);
digitalWrite(fan_pin,LOW);
99

}
else{
digitalWrite(fan_pin,HIGH);
}
if(humidity < humidity_lower_limit){
send_text(number,humidity_lowerlimit_string);
digitalWrite(sprinkler_pin,LOW);
}
else{
digitalWrite(sprinkler_pin,HIGH);
}
if(light_value < light_limit){
send_text(number,light_overlimit_string);
digitalWrite(light_pin,LOW);
}
else{
digitalWrite(light_pin,HIGH);
}
if(counter>900){
send_data_text();
counter = 0;
}
}
delay(1000);
counter++;
}
void lcd_display(){
lcd.clear();
lcd.print("T:");
lcd.print(temperature);
lcd.print((char)223);
lcd.print('C');
lcd.print(" H:");
lcd.print(humidity);
lcd.print('%');
lcd.setCursor(0,1);
lcd.print(F("Light: "));
lcd.print(light_value);
}
void process_txt(char *txt)
{
if (strcasestr_P(txt, PSTR("config")) != 0)
{
header_token = strtok(txt,config_delimeter);
temp_token = strtok(NULL,config_delimeter);
humidity_token = strtok(NULL,config_delimeter);
light_token = strtok(NULL,config_delimeter);
temp_upper_limit = atoi(temp_token);
humidity_upper_limit = atoi(humidity_token);
light_limit = atoi(light_token);
100

EEPROM.write(temp_addr, temp_upper_limit);
EEPROM.write(humidity_addr, humidity_upper_limit);
EEPROM.write(light_addr, light_limit);
send_text(number, config_string);
}
if (strcasestr_P(txt, PSTR("data")) != 0)
{
send_data_text();
}
if (strcasestr_P(txt, PSTR("manual")) != 0)
{
auto_mode = false;
send_text(number, manual_activated_string);
}
if (strcasestr_P(txt, PSTR("auto")) != 0)
{
auto_mode = true;
send_text(number, auto_activated_string);
}
if (strcasestr_P(txt, PSTR("fan on")) != 0)
{
auto_mode = false;
digitalWrite(fan_pin, LOW);
send_text(number, fan_on_string);
}
if (strcasestr_P(txt, PSTR("fan off")) != 0)
{
auto_mode = false;
digitalWrite(fan_pin, HIGH);
send_text(number, PSTR("fan off"));
}
if (strcasestr_P(txt, PSTR("light on")) != 0)
{
auto_mode = false;
digitalWrite(light_pin, LOW);
send_text(number, light_on_string);
}
if (strcasestr_P(txt, PSTR("light off")) != 0)
{
auto_mode = false;
digitalWrite(light_pin, HIGH);
send_text(number, light_off_string);
}
if (strcasestr_P(txt, PSTR("heater on")) != 0)
{
auto_mode = false;
digitalWrite(heater_pin, LOW);
send_text(number, heater_on_string);
}
if (strcasestr_P(txt, PSTR("heater off")) != 0)
101

{
auto_mode = false;
digitalWrite(heater_pin, HIGH);
send_text(number, heater_off_string);
}
if (strcasestr_P(txt, PSTR("sprinkler on")) != 0)
{
auto_mode = false;
digitalWrite(sprinkler_pin, LOW);
send_text(number, sprinkler_on_string);
}
if (strcasestr_P(txt, PSTR("sprinkler off")) != 0)
{
auto_mode = false;
digitalWrite(sprinkler_pin, HIGH);
send_text(number,sprinkler_off_string);
}
}
void send_data_text()
{
Serial.println(F("ATE0\r"));
delay(500);
Serial.println(F("AT+CMGF=1\r"));
delay(500);
Serial.print(F("AT+CMGS=\""));
Serial.print(number);
Serial.println("\"\r");
delay(500);
Serial.print(F("Temp. = "));
Serial.print(temperature, 1);
Serial.print(".\r\n");
Serial.print(F("Humidity = "));
Serial.print(humidity, 1);
Serial.print("%.\r\n");
Serial.print(F("Light = "));
Serial.print(light_value);
Serial.print(".\r\n");
Serial.write(0x1a);
}
void ping_GSM()
{
Serial.println("ATE0\r");
delay(500);
for (int k = 0; k < 10; k++) {
Serial.println("AT\r");
delay(200);
}
Serial.println(F("AT+CNMI=2,2,0,0,0\r"));
delay(200);
}
102

void send_text(const char *num, const char *msg)


{
Serial.println(F("ATE0\r"));
delay(500);
Serial.println(F("AT+CMGF=1\r"));
delay(500);
Serial.print(F("AT+CMGS=\""));
Serial.print(num);
Serial.println("\"\r");
delay(500);
char c;

while ( ( c = pgm_read_byte( msg++ ) ) ) {


Serial.print(c);
}
Serial.write(0x1a);
}
103

APPENDIX L: Internal Architecture of the ATmega328 Microcontroller


104

APPENDIX M: SIM800L GSM Module Data Sheet


105

APPENDIX N: ATmega328 Microcontroller Data Sheet


106
107

APPENDIX O: LM2596 Power Regulator Data Sheet


108

APPENDIX P: Schematic of the Prototype Greenhouse System


109

APPENDIX Q: Light Dependent Resistor Data Sheet


110

You might also like