Professional Documents
Culture Documents
Design and Fabrication of A Greenhouse...
Design and Fabrication of A Greenhouse...
I56/CE/28340/2013
JANUARY 2020
i
DECLARATION
This Thesis is my original work and has not been presented at other awards of degree
I56/CE/28340/2013
Department of Physics
Kenyatta University
This thesis has been submitted with our approval as University supervisors:
Department of Physics
Kenyatta University
Department of Physics
Kenyatta University
ii
DEDICATION
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
TABLE OF CONTENTS
DECLARATION ............................................................................................................I
DEDICATION .............................................................................................................. II
ABSTRACT............................................................................................................... XV
INTRODUCTION ....................................................................................................... 1
CHAPTER FOUR...................................................................................................... 55
REFERENCES........................................................................................................... 83
APPENDICES ............................................................................................................ 85
LIST OF FIGURES
LIST OF TABLES
Table 4.2: Humidity and Temperature Data inside the Laboratory ............................. 59
DIN Data In
RF Radio Frequency
RX Receiver
TX Transmitter
ABSTRACT
CHAPTER ONE
INTRODUCTION
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.
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.
systems would monitor and control greenhouse parameters such as pH of soil, soil
moisture, light intensity, relative humidity and temperature. The microcontroller would
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
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
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
relative humidity and light luminance in a greenhouse using sensors, SMS technology
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
that automates the greenhouse monitoring and controlling processes using sensors. This
will maximize the crop yields, minimize maintenance cost and save time.
The general objective of this research work was to design, fabricate and implement a
ii. To interface sensors, LCD, GSM SIM800L and HCO5 Bluetooth to the
ATmega328 microcontroller,
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
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
technologies for greenhouse automation processes and existing greenhouse control and
monitoring systems.
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
transparent, enclosed structure in which plants are cultivated and is spacious enough to
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
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 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,
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
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
works;
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
Serodio et al. (1998) designed and implemented an integrated network, for greenhouse
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
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
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
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
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
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.
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.
greenhouse prototype. The sensing unit comprised of sensors such as SHT75 for
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
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,
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
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
LPC2148 controller. It had two nodes each node had LPC2148 microcontroller,
for soil moisture, temperature and humidity. The second node interfaced LCD and
buzzer. The project was implemented using advanced CAN protocol and a
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
Pushkar and Amey (2016) designed an embedded system for greenhouse management.
EEPROM, Real time clock (RTC), and relays. Five sensors were used namely; LM35D
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
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
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
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
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
communicated with the GSM module by AT Commands, which were used to send and
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
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’
of values. The output of a sensor is interfaced to the input pin of a microcontroller and
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.
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
measurement range of 20% to 90% with an error of ±5% and temperature range of 0 to
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
reliable and very stable. The sensor has a component for measuring humidity which is
17
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
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
In this study, the sensor was placed inside the greenhouse then connected to the
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
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
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
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):
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
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
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
calculated from temperature coefficient curve. For the thermistor used in this research:
This study used the light dependent resistor (LDR) sensor, shown in figure 3.7, which
level of light intensity impinging on the surface of the sensor. They are made up of
Specification Value
Current 75 mA
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
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.
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
RL ×Vin
VOUT = (3.4)
RL +RI
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
analyse the input signals from the sensors and subsequently instructing the actuators,
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.
+ 1.8 to + 5.5 V.
d. Six program based power save modes; Noise Reduction mode, Idle mode,
mode.
f. 1 Kbytes EEPROM and 2 Kbytes Internal SRAM with CPU Speed 1 MIPS for
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
i. Two 8-bit counters having inbuilt Prescaler plus compare mode, One 16-bit
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
program is quick AVR Harvard architecture. The chip has a sensor for controlling
26
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
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
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
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
ATmega328 contains extended input/output space in the SRAM for storage of special
instructions.
The Arduino uno microcontroller board, is a single board microcontroller board that
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
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
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
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
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
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
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.
A mobile phone refers to a handy telephone, which through a cell site (base station) or
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
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.
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
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
undersea phone cables, all linked to switching centres to allow phones to communicate
to each other.
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 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
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
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.
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.
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
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
Gaussian Frequency Shift Keying (GFSK) modulation at 2.4 GHz on ISM band. It has
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,
A LCD is a thin, flat display device made up of any number of color or monochrome
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
registers in terms of numbers and characters. When letters and digits are to be displayed
ii. They can display both numbers and characters unlike LEDs which can only
iii. Due to their internal controller the microcontroller is saved from sending data
to display continuously.
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
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.
The input connections of relay module comprise of Logic GND which is connected to
to digital pins of microcontroller or left unconnected if not in use and Logic VCC which
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
3.8.2 Actuators
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
a. Ventilation fans: Two direct current fans determined the rate of air flowing
c. Water Pump: Pump provided the means for moving water through the system
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.
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
The LCD module was interfaced in 4 bit mode as illustrated in figure 3.23. The LCD
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.
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
LCD ATmega328
Pin 4 PD6
Pin 5 PD5
Pin 6 PD4
Pin 11 PD3
Pin 12 PD2
Pin 13 PD1
Pin 14 PD0
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
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
Figure 3.25 show circuit connections of the Bluetooth module to the ATmega328
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.
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
harmony. The one wire line is connected via a resistor to the power source. So the line
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 ",
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
Figure 3.29 shows how the 5 V 4 channel relays board was 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
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
3.11.1 Introduction
directives, executable by the processor in a given order to carry out preset task. It
ensure collect task implementation. There are certain words, grammar and rules for
programming languages.
controller. The three levels of programming languages are: machine code, assembly
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
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.
Ports etc.
ii. Initialize the sensors, GSM, Bluetooth, LCD and the relays. Send SMS
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
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
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
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
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
x. End.
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
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
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
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
#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
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
void loop() {
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
3.11.5 AT Commands
The Cell phones and GSM modules use a set of AT commands depending on GSM
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.
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
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
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
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
potential divider.
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
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
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.
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
Figure 4.4 shows the Arduino serial monitor indicating the values of temperature and
To study the performance characteristics of the DHT11 sensor: the DHT11 sensor,
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
From the table it is evident that the DHT11 sensor compared well with the hygrometer
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
20
15
10
0
0 5 10 15 20 25 30 35 40 45 50 55 60
Time (min)
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
Figure 4.6 shows humidity and temperature graph plotted against time for the data in
table 4.3.
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)
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
Figure 4.7 shows humidity and temperature graph plotted against time for the data in
table 4.4.
25
20
15
10
0
0 5 10 15 20 25 30 35 40 45 50 55 60
Time (min)
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
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,
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
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
Figure 4.13 shows the bluetooth module connection to Arduino during testing.
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
Figure 4.14 shows how the relay module was interfaced with Arduino during testing.
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
A step down transformer converted the source 240 V a.c to 12 V a.c which was
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Ω.
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
LDR
GSM Module
GSM Power
Regulator Relay modules
Microcontroller
Bluetooth module
LCD
DHT 11 Sensor
GSM Antenna
The complete designed greenhouse prototype is shown on figure 4.16. The prototype
two fans to enable the cooling of the system and control humidity, a bulb to light the
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
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
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
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
the relay module, the GSM module and the Bluetooth module.
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
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
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
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
An experimental study was carried out, outside Kenyatta university Physics laboratory
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
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
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
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
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
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.
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.
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,
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
Temperature(ºC) Temperature(ºC)
Time of Time of
the Day With Without the Day With Without
(Hrs) Control Control (Hrs) Control Control
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.
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,
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
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)
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
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
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)
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
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
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
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)
CHAPTER FIVE
5.1 Conclusions
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.
(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,
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
(i) The reliability of the designed system can be exploited to build a network of
(ii) The designed prototype greenhouse can be applied in the agricultural sector
For further research on the designed prototype greenhouse system, this study
(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
REFERENCES
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.
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.
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.
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.
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.
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).
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).
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
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
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
//It instructs the microcontroller to read and print the sensor values on the Arduino IDE.
void setup() {
Serial.begin(9600);
}
void loop() {
sensorValue = analogRead(sensorPin);
Serial.println(sensorValue);
delay(100);
}
89
//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
//This sketch prints "Hello World!" on the LCD and turns on and off the display.
#include <LiquidCrystal.h>
void setup() {
lcd.begin(16, 2); lcd.print("hello, world!");
}
void loop() {
lcd.noDisplay();
delay(500);
lcd.display();
delay(500);
}
91
//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
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
//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>
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
//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
//The codes sends the messages from the terminal to the Bluetooth Module and
#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
//This code prints turns on four LEDs one by one repeatedly so long as the relay
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
// PHYSICS DEPARTMENT
// KENYATTA UNIVERSITY
#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";
char sms_rx[122];
boolean data_received = false;
int index = 0;
boolean text_sent = false;
boolean auto_mode = false;
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