100% found this document useful (1 vote)
219 views

Automatic Watering System Using Arduino

Uploaded by

dika fran
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
219 views

Automatic Watering System Using Arduino

Uploaded by

dika fran
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 73

AUTOMATIC WATERING SYSTEM WITH

MOISTURE AND WATER LEVEL DETECTOR


USING ARDUINO

By
Gabriel Putra Pinastika
ID No. 001201600043

A Thesis
Submitted to the Faculty of Computing
President University
in partial fulfillment of the Requirements
for the Degree of Bachelor of Science
in Information Technology

Cikarang, Bekasi, Indonesia

May 2021
Copyright by
Gabriel Putra Pinastika
2021

i
AUTOMATIC WATERING SYSTEM WITH
MOISTURE AND WATER LEVEL DETECTOR
USING ARDUINO

By
Gabriel Putra Pinastika
ID No. 001201600043

Approved:

Ir. Rila Mandala, M. Eng., Ph.D. Drs. Nur Hadisukmana, M. Sc.


Thesis Advisor Program Head of Science in
Information Technology

Ir. Rila Mandala, M. Eng., Ph.D.


Dean of Faculty of Computing

ii
STATEMENT OF ORIGINALITY

In my capacity as an active student of President University and as the author of the


thesis stated below:

Name : Gabriel Putra Pinastika


Student ID number : 001201600043
Study Program : Information Technology
Faculty : Computer Science

I hereby declare that my thesis plan entitled “AUTOMATIC WATERING


SYSTEM WITH MOISTURE AND WATER LEVEL DETECTOR USING
ARDUINO” is to the best of my knowledge and belief, an original piece of work
based on sound academic principles. If there is any plagiarism detected in this
thesis, I am willing to be personally responsible for the consequences of these acts
of plagiarism, and will accept the sanctions against these acts in accordance with
the rules and policies of President University.

I also declare that this work, either in whole or in part, has not been submitted to
another university to obtain a degree.

Cikarang, Indonesia, June 4th, 2021

Gabriel Putra Pinastika

iii
SCIENTIFIC PUBLICATION APPROVAL FOR
ACADEMIC INTEREST

As an academic community member of the President's University, I, the


undersigned:

Name : Gabriel Putra Pinastika


Student ID number : 001201600043
Study program : Information Technology

for the purpose of development of science and technology, certify, and approve to
give President University a non-exclusive royalty-free right upon my final report
with the title:

“AUTOMATIC WATERING SYSTEM WITH MOISTURE AND WATER


LEVEL DETECTOR USING ARDUINO”

………………………...............................................................................................

With this non-exclusive royalty-free right, President University is entitled to


converse, to convert, to manage in a database, to maintain, and to publish my final
report. There are to be done with the obligation from President University to
mention my name as the copyright owner of my final report.

This statement I made in truth.

Cikarang, Indonesia, June 4th, 2021

Gabriel Putra Pinastika

iv
ADVISOR APPROVAL FOR
JOURNAL/INSTITUTION’S REPOSITORY

As an academic community member of the President's University, I, the


undersigned:

Name : Gabriel Putra Pinastika


ID number : 001201600043
Study program : Information Technology
Faculty : Computer Science

declare that following thesis:

Title of thesis : “AUTOMATIC WATERING SYSTEM WITH


MOISTURE AND WATER LEVEL DETECTOR USING
ARDUINO”
Thesis author : Gabriel Putra Pinastika
Student ID number : 001201600043

will be published in journal/institution’s repository (underline that applies)

Cikarang, Indonesia, June 4th, 2021

Gabriel Putra Pinastika

v
SIMILARITY INDEX REPORT

vi
ABSTRACT

Agriculture industry as the world’s largest water consumer is facing crisis in this
past decades as the climate change makes weather unpredictable, competition with
real-estate sector over water and land usage, as well as decrease of manual labors
caused the lost interest in younger generation to continue working in this field. This
thesis proposed a system that can help with modernization in agriculture industries.
The automatic watering system is a perfect solution because it does not need much
attention from the user except during maintenance. This system consists of the
following parts: the prototype of the automatic watering system using Arduino, web
client that allows the user to control and monitor the prototype, and the database to
save the prototype settings and the watering information. The automatic watering
system will keep send data to the web client and the database as long as there is
sufficient internet connection nearby.

Keywords: Automatic, Arduino, Watering System

vii
DEDICATION

To my grandmother,

I’m still sad you couldn’t see me graduating university like I promised you.

To my mother, Eleonora.

I would’ve made a terrible doctor, mom. People would’ve died.

To my father, Gunawan.

Told you I’ll finish it.

To my little brother.

Still need that Netflix subscription?

And lastly, this thesis is dedicated to everybody you hate.


Sorry. Life’s like that sometimes.

viii
ACKNOWLEDGEMENT

Praise and gratitude, the author would like to convey to the presence of The One
Almighty God for giving the author guidance and blessings so that the author can
complete this thesis.

The thesis was prepared to fulfill one of the requirements to obtain a Bachelor’s
degree at President University. The completion of this thesis cannot be separated
from help, support and guidance from various parties. Therefore, on this occasion
the author would like to thank profusely to:

1. Mr. Rila Mandala, M. Eng., Ph.D., as my thesis advisory. I would like to


express my gratitude to Mr. Rila for the support, encouragement,
motivation, guidance, advices, energy, and time through the whole process
of this thesis. I would not be able to come up with idea and spirit for this
thesis and to complete all necessities for this thesis on time.
2. Mrs. Indah, as the Secretary of the Information Technology Study Program.
I would like to express my gratitude to Mrs. Indah because she is always
patient with me that always ask and bother her.
3. All of the lecturers in Information Technology Study Program of President
University.
4. Thank you to my friends in university life Mahdi M. Arief, Voila Puri
Gumilar, Ega Frandika, and Farrell Eghar Saputra for the best supports and
motivations given to me.
5. Thank you to Yolanda Romauli for always accept me for who I am. As well
as the best supporter, story listener, for your laugh, help and support for me
since day one I meet you in this university. And always believes me with
the most of the things I need in this life, and thank you for always besides
me, being my second home. The best place for the process to through ups
and many downs struggle.

ix
6. And of course, to my parent and siblings who support me no matter what
decision I took in my life. I might have given up a long time ago if it were
not for them.

x
TABLE OF CONTENTS

STATEMENT OF ORIGINALITY ....................................................................... iii

SCIENTIFIC PUBLICATION APPROVAL FOR ACADEMIC INTEREST ..... iv

ADVISOR APPROVAL FOR JOURNAL/INSTITUTION’S REPOSITORY ..... v

SIMILARITY INDEX REPORT ........................................................................... vi

ABSTRACT .......................................................................................................... vii

DEDICATION ..................................................................................................... viii

ACKNOWLEDGEMENT ..................................................................................... ix

TABLE OF CONTENTS ....................................................................................... xi

LIST OF TABLES ............................................................................................... xiv

LIST OF FIGURES .............................................................................................. xv

CHAPTER I INTRODUCTION .......................................................................... 17

1.1 Problem Background .............................................................................. 17

1.2 Problem Statement.................................................................................. 18

1.3 Objectives ............................................................................................... 18

1.4 Scopes and Limitations........................................................................... 18

1.5 Methodology .......................................................................................... 19

1.6 Research Outline .................................................................................... 22

CHAPTER II LITERATURE STUDY ................................................................ 24

2.1 Automatic Watering System................................................................... 24

2.2 Arduino ................................................................................................... 24

2.2.1 Arduino Uno ........................................................................................ 24


2.2.1 Firmata ................................................................................................ 25
2.3 Raspberry Pi ........................................................................................... 27

xi
2.3.1 Raspberry Pi 3 Model B ....................................................................... 27
2.4 HS-SR04 ................................................................................................. 28

2.5 Soil Moisture Sensor .............................................................................. 28

2.6 5V DC Water Pump................................................................................ 29

2.7 JavaScript ............................................................................................... 30

2.7.1 Express.js/Node.js ............................................................................... 30


2.7.2 Johnny-Five.......................................................................................... 31
2.7.3 React ................................................................................................... 31
2.8 Related Work .......................................................................................... 31

2.8.1 Rancangan Bangun Sistem Kontrol Irigasi Tetes untuk Pertanian Cabai
..................................................................................................................... 32
2.8.2 Rancangan Bangun Sistem Pengairan Sawah Otomatis menggunakan
Arduino dan Android .................................................................................... 32
2.9 Comparison Overview ............................................................................ 33

CHAPTER III SYTSEM ANALYSIS .................................................................. 34

3.1 System Overview ........................................................................................ 34

3.2 Functional Analysis ..................................................................................... 35

3.3 Software Development ................................................................................ 35

3.4 Hardware Development ............................................................................... 36

3.5 Use Case Diagram ....................................................................................... 37

3.6 Use Case Narrative ...................................................................................... 37

3.7 Swim Lane Diagram .................................................................................... 42

CHAPTER IV SYSTEM DESIGN ....................................................................... 47

4.1 User Interface Diagram ............................................................................... 47

4.2 Prototype System Design ............................................................................ 49

4.2.1 Wiring Diagram.................................................................................... 49


4.3 Entity Relationship Diagram ....................................................................... 51

CHAPTER V SYSTEM IMPLEMENTATION ................................................... 52

xii
5.1 User Interface Design .................................................................................. 52

5.2 Prototype System Details ............................................................................ 53

5.2.1 Initialization ......................................................................................... 53


5.2.2 Global State ......................................................................................... 54
5.2.3 Starting the Boards .............................................................................. 55
5.2.4 Real Time Sensor Data Transfer........................................................... 56
5.2.5 Pump Function .................................................................................... 57
5.2.6 User Controlled Action ........................................................................ 58
5.2.7 Scheduler............................................................................................. 59
5.2.7.1 Automatic Watering Scheduler ........................................................ 59
5.2.7.2 Reset Job .......................................................................................... 62
CHAPTER VI SYSTEM TESTING ..................................................................... 63

6.1 Testing Environment ................................................................................... 63

6.2 Testing Scenario .......................................................................................... 63

6.2.1 Real Time Data Monitoring.................................................................. 63


6.2.2 Automatic Watering Based on User Settings ....................................... 65
6.2.3 Manual Pump by the User ................................................................... 66
6.2.4 Configure Automatic Watering Settings .............................................. 66
CHAPTER VII Conclusion and Further Work ..................................................... 69

7.1 Conclusion ................................................................................................... 69

7.2 Further Work ............................................................................................... 69

xiii
LIST OF TABLES

Table 2. 1 Arduino Uno Components and Functions............................................ 26


Table 2. 2 Components and Function of Raspberry Pi 3 Model B ....................... 27
Table 2. 3 Feature Comparison with Related Works ............................................ 33

Table 3. 1 Functional Requirements ..................................................................... 35


Table 3. 2 Software Requirements ........................................................................ 35
Table 3. 3 Hardware Requirements....................................................................... 36
Table 3. 4 Real-Time Monitoring Table ............................................................... 38
Table 3. 5 Automatic Watering on Scheduled Time ............................................. 39
Table 3. 6 Manual User Action ............................................................................. 40
Table 3. 7 Change Prototype Settings ................................................................... 41

Table 6. 1 Real Time Monitoring Test-case.......................................................... 63


Table 6. 2 Automatic Watering Feature Test-case ................................................ 65
Table 6. 3 Manual User Action Test-case ............................................................. 66
Table 6. 4 Prototype Settings Update Test-case.................................................... 66

xiv
LIST OF FIGURES

Figure 1. 1 Phases of Waterfall Methodology ...................................................... 21

Figure 2. 1 Arduino Uno Board ............................................................................ 25


Figure 2. 2 Raspberry Pi 3 Model B Components ................................................ 27
Figure 2. 3 HS-SR04 Ultrasonic Sensor ............................................................... 28
Figure 2. 4 Arduino Soil Moisture Sensor ............................................................ 29
Figure 2. 5 5V DC Water Pump ............................................................................ 30

Figure 3. 1 Automatic Plant Watering System Use Case Diagram....................... 37


Figure 3. 2 Real-Time Data Monitoring Swim Lane Diagram ............................. 43
Figure 3. 3 Automatic Watering on Scheduled Time Swim Lane Diagram ......... 44
Figure 3. 4 Manual User Action Swim Lane Diagram ......................................... 45
Figure 3. 5 Change Prototype Settings Swim Lane Diagram ............................... 46

Figure 4. 1 Current Plant Status ............................................................................ 47


Figure 4. 2 Watering Settings Menu ..................................................................... 48
Figure 4. 3 Wiring Diagram .................................................................................. 49

Figure 5. 1 Interface of Monitoring Page .............................................................. 52


Figure 5. 2 Interface of Prototype Configuration Page ......................................... 53
Figure 5. 3 Initialization Process Source Code ..................................................... 54
Figure 5. 4 Global State Source Code ................................................................... 55
Figure 5. 5 Initialization Process Source Code ..................................................... 56
Figure 5. 6 Real Time Sensor Data Transfer Source Code ................................... 57
Figure 5. 7 Pump Function Source Code .............................................................. 58

xv
Figure 5. 8 User Controlled Action Source Code ................................................. 59
Figure 5. 9 Automatic Watering Scheduler Source Code ..................................... 60
Figure 5. 10 Generate New Schedule Function Source Code ............................... 61
Figure 5. 11 Watering Count Reset Source Code ................................................. 62

Figure 6. 1 Result of Real Time Monitoring Test-case No. 1 ............................... 64


Figure 6. 2 Result of Real Time Monitoring Test-case No. 2 ............................... 65
Figure 6. 3 Prototype Settings Update Result ....................................................... 67
Figure 6. 4 Automatic Watering on Scheduled Time Result ................................ 67
Figure 6. 5 Automatic Watering on Scheduled Time Result ................................ 67
Figure 6. 6 Automatic Watering on Scheduled Time Result ................................ 67
Figure 6. 7 Automatic Watering on Scheduled Time Result ................................ 68
Figure 6. 8 Manual User Action Result ................................................................ 68
Figure 6. 9 Manual User Action Result ................................................................ 68

xvi
CHAPTER I
INTRODUCTION

1.1 Problem Background


Water is basic necessity for any living being, it is used to dehydrate the body
and also used to provide supply agriculture industries which provides food security
for the people. Agriculture industries is the world largest water consumer, as farm
that use irrigation as watering system uses as much as 70% water usage worldwide,
over 40% reported in many OECD countries. And along with the population growth
is estimated to reach over 50 billion by 2050, which means agriculture industries is
projected to make 50% more income generated by 2050.

But the lucrative prospect of agriculture industries does not come with its own
fair share of problem. In order to boost the growth of the plant, farmers often resort
to using chemical fertilizer and pesticide which creates waterways and groundwater
pollutions. The competition with residential area over land and/or water usage has
led to drain the natural aquifers which cause negative environmental issues in long-
term duration.

Other issues faced by the industries are low prices of agriculture product
prices caused by government policies, escalating climate change which makes
seasonal planting even harder, and labor shortages due to younger generation is opt-
out from the industry because they considered it dirty work. And as Covid-19
pandemic made the situation even worse, the industry is starting to realize that
automation is the solution to solve some of its problem.

17
This thesis develops an Automatic Plant Watering System with Moisture Sensor
by utilizing Arduino acting as the microcontroller and Raspberry Pi 3 as the server
acting as a bridge between the Arduino and the client application. And the system
is powered by Raspberry Pi, it only draws 86-watt hour (Wh) per day according to
calculation done by Alex Eames and Jeff Geerling, which translate to 2.58 kWh in
30 days. By implementing precise watering and combination of Arduino and
Raspberry Pi, this thesis aims to help solve the problem which current agricultural
sector are facing: excessive water and power usage, and decrease of manual labors.

1.2 Problem Statement


This thesis aims to partially or completely solve the following problems:
1. How to increase people’s awareness of excessive water and power usage?
2. How to create a system to prevent excessive water usage in farming
industry?
3. How to design web application to control the automatic watering system?

1.3 Objectives
The primary objective of this thesis is to create an automatic watering system
by using Arduino as microcontroller in tandem with Raspberry Pi as the backend
server and web application feature to remotely manage the system. The watering
system is using moisture sensor to track the ground humidity level and weather
forecast data obtained from OpenWeather API to determine the correct time for
plant watering. The web application can be used by the user to tweak the Arduino
settings, view watering logs, view current water level in storage tank and water the
plant in advance ignoring the automatic system.

1.4 Scopes and Limitations


The application developed in this research will have the following features:

1. Automatically water plant based on current humidity level and weather


forecast.

18
2. The system can show the watering logs that can be used to determine the
best watering conditions.

The system has several limitations which are:

1. The system needs to be constantly exposed to internet in order to


communicate between the system and the sensor.
2. The user still needs to manually fill the water tank.
3. The system works best in controlled environment such as indoor farming.
4. The soil moisture sensor and the battery need to be replaced regularly.
5. The soil moisture sensor needs to be recalibrated for each type of soil and/or
water.

1.5 Methodology
The methodology used to develop this thesis is Waterfall Model. The Waterfall
Model is a project management with linear approach where the project requirements
are gathered in the beginning of the project then the project plan is created
sequentially to fulfill those project requirements. The model is named Waterfall
Model because each phases flows steadily to the next phase, just like a waterfall.

The Waterfall Model is a detailed and organized methodology, and is proven


methodology because it’s has been available for a long time. And although other
industries also use waterfall model, however, when people talk about “waterfall
model” it is usually referring to its usage in software development.

The advantages and disadvantages of waterfall model is explained below.

Advantages:

1. The model is usable without needing advanced knowledge because of its


simplicity nature.

19
2. Manageable due to the model inability to adapt to new changes, therefore
each phase has specific output or results.
3. The stages are clearly defined, and prepared and finished one by one as the
phases cannot overlap each other.
4. Best suited for smaller project if the requirements are well documented.
5. Any changes in the system are made during the development process.

Disadvantages:

1. If the software has already finished testing phases, it’s hard to revise
something that’s not previously defined in the analysis stage.
2. The amount of risk is high thus making the model uncertain by nature.
3. Not suitable for complex projects where the requirements are expected to
frequently change.
4. Working software only available in the late development life cycle,
disabling the client ability to gives valuable feedback.
5. Once the software has fully developed, even small errors or changes may
cause a lot of problems.

20
Figure 1. 1 Phases of Waterfall Methodology

The Waterfall Model sequential is explained as the following:

1. Requirement Analysis and Gathering


All possible system requirements are gathered during this initial phase to be
analyzed by the developer. The results are then documented to provide
guidance used in the rest of the phases.
2. System Design
The documentation from the analysis phase is used to prepare the system
design. The system architecture such as: programming language, UI
wireframe, or any other high-level project details is created during this
phase.
3. Implementation
The system is developed in this phase, where each functionality of the
system is split into smaller components call units which allow for code
reusability. Each unit is tested separately to find any errors or bug and to
ensure its functionality according to the predefined system design.

21
4. Integration and Testing
All the units developed in the implementation phase are integrated into a
one single system. Once the integrations have finished, the developer
perform another testing to ensure each unit are compatible with each other.
5. Deployment of the system
Once all the test case returns no failure, the product is ready to be deployed
or released for public usage.
6. Maintenance
As test case might not cover all possible scenario, there’s a chance for
failures when deployed therefore patches for the system are released to
update the system.

1.6 Research Outline


Chapter I Introduction

This chapter describe the background behind this


thesis, the purpose of the thesis, scope and limitation,
and the methodology used.

Chapter II Literature Study

This chapter consist of the explanation for all


materials and literature study used during
development process.

Chapter III System Analysis

The overviews of the system such as the software


requirements is covered in this chapter. The result of
the analysis is then used to determine the system
overall features and how it behave in solving the
problem.

Chapter IV System Design

22
The system blueprints are covered during this chapter
where the system architecture and UI design is
defined. The UI design also include diagrams such as
Entity Relationship Diagram, activity diagram, and
use case diagram.

Chapter V Implementation

The development process of the system is covered in


this chapter, explaining the main source code for the
system

Chapter VI Test Scenario

The test-case for the system is written in this chapter


to perform system testing and covers various
technical and non-technical scenarios. The testing is
conducted to ensure the system meets the software
requirements defined in the previous chapter, and to
find any bugs or errors in the system.

Chapter VI Conclusion and Future work

The conclusion of this thesis is discussed in this


chapter, explaining how the problem is solved and
the system requirements is fulfilled. Futures work
and improvements of the system are also explained
in this system.

23
CHAPTER II
LITERATURE STUDY

2.1 Automatic Watering System


Automatic Watering System means a fully independent irrigation system. It
uses current moisture data and weather forecast data to automatically water the
plants. The user can manage the system using a web application designed to gives
the user the ability to control every aspect of the system such as water usage,
watering time and frequency, and logs system so user can view the watering data.

2.2 Arduino
Arduino is an open-source electronics platform with easy-to-use hardware and
software principle. The inputs are read by Arduino boards: proximity sensor, touch
or gesture, even a social media message, and turn it into an output – activating a
motor, turning on an LED, post something online by sending an instruction to the
microcontroller on the boards.

Created by Ivrea Interaction Design Institute with the purpose to help students
learn electronic and programming, especially those in 3rd world country without
previous exposure or knowledge to technology. But as Arduino explodes in
popularity, Arduino is adapting to the new trends and needs, transforming itself
from simple 8-bit board to product for IoT applications, wearable, 3D printing, and
embedded environment. All Arduino boards are open-source, engaging the
creativity of the user to create something that fits their needs.

2.2.1 Arduino Uno


One of the most popular worldwide variant of Arduino board is Arduino Uno,
which supported by wide arrange of modules to support almost every user needs.

24
Based on ATmega328P microcontroller, equipped with 14 digital pins both output
and input (on which 6 can be used as PWM outputs), 6 analogs input/output, 16
MHz quartz crystal, an USB connection, a power jack, an ICSP header and a reset
button. To use Arduino is pretty simple and straightforward, simply plugged in the
board to power supply using AC-to-DC adapter, or computer using USB cable, or
battery if the board is deployed on places with no place without electricity.

Figure 2. 1 Arduino Uno Board

2.2.1 Firmata
Firmata is a protocol to allow communication between Arduino Uno that only
accept C/C++ programming language and the host computer running other

25
programming language. The protocol is implemented on firmware level of any
microcontroller’s architecture and the software package on the host computer.

Table 2.1 provide an explanation for Arduino Uno components along with its
function.

Table 2. 1 Arduino Uno Components and Functions

No. Component Function


Supplying power to the Arduino through an USB
1 Power USB
cable.
2 Power (Barrel Jack) Direct connection to the AC mains power supply.
Control the voltage directed at the Arduino boards
3 Voltage Regulator and stabilize the DC voltages used by the processor
and other elements.
4 Crystal Oscillator Helps Arduino calculating time.
5 Reset Button Restart the boards to load new program.
6 Pin 3.3V Provide 3.3V output volt.
7 Pin 5V Provide 5V output volt.
8 GND Pin Used to ground the circuit.
9 Pin Vin Power the board using AC mains power supply.
Read signal from analog sensor and convert it into
10 Analog Pin
digital value.
Main The brain of the Arduino and where the programs
11
microcontroller are stored.
An AVR, a tiny programming header for Arduino
12 ICSP Pin consists of MOSI, MISO, SCK, RESET, VCC, and
GND.
13 Power LED Light up if the board is working correctly.
TX LED flashes when sending serial data. RX
14 TX and RX LEDs
flashes during receiving process.
15 Digital I/O 14 digitals I/O pins.

26
2.3 Raspberry Pi
Raspberry Pi is a series of small single-board computers developed in the
United Kingdom by the Raspberry Foundation. The Raspberry Pi project originally
leaned towards the promotion of teaching basic computer science in schools and in
developing countries.

2.3.1 Raspberry Pi 3 Model B


Raspberry Pi 3 Model B is one of the most popular models of Raspberry Pi.
Supported with Quad-Core 64-bit CPU, WiFi, and Bluetooth makes it a good choice
for developing IoT devices in remote location.

Figure 2. 2 Raspberry Pi 3 Model B Components

The Raspberry Pi 3 Model B components as well as its function is explained in


Table 2.2.

Table 2. 2 Components and Function of Raspberry Pi 3 Model B

No. Component Function


1. 64-bit Quad-Core CPU The main computing power of Raspberry Pi.

27
Input-output that can be used to connect any
2. GPIO pins
module or sensor to the board.
3. HDMI Display Port Display output to external monitor.
The main storage of Raspberry Pi, where the
4. Micro SD card slot
OS is stored.
5. Micro USB power input Powering the Raspberry Pi.
Allow transferring camera data directly into
6. CSI camera port
the board.
Allow multiple device/peripherals
7. USB Port
connection.
8. Ethernet Port Connect to internet using LAN cable.

2.4 HS-SR04
The ultrasonic distance sensor can provide non-contact measurement
functionality on range between 2cm to 400cm with a ranging accuracy that can
reach up to 3mm. Equipped with ultrasonic transmitter, a receiver and a control
unit.

Figure 2. 3 HS-SR04 Ultrasonic Sensor

2.5 Soil Moisture Sensor


The two exposed conductors on the sensor where shape is similar to a fork, is a
variable resistor on which the resistance differs depending on the water quantity on
the soil. As the resistance is proportional to water quantity exposed to the

28
conductors, it means that the more quantity of water the soil has means better
conductivity resulting in lower resistance, and vice-versa. Soil moisture level can
be determined by reading the sensor output – either analog or voltage output –
which varies according to the resistance.

Figure 2. 4 Arduino Soil Moisture Sensor

2.6 5V DC Water Pump


An equipment to transfer water or any liquid for that matter, that works by
increasing the water pressure in order to move it from one place to another. Widely
used globally as means to supply water for residential area, industrial, etc. Used to
transport water from water tank to the plants.

29
Figure 2. 5 5V DC Water Pump

2.7 JavaScript
JavaScript originally started as a programming language maintained by the
ECMA Foundation that provide an ability to implement complex features on a
website ranging from dynamic content update, interactive maps, or even animating
2D/3D graphics. It’s a staple on basic web technology stack along with HTML and
CSS. But with the rise of non-browser environment such as Node.js, its application
has extended into much more complex such as machine learning or desktop
application.

2.7.1 Express.js/Node.js
Node.js is a non-browser environment running on V8 engine developed by
Google which essentially allows to run JavaScript code outside of browser
environment. It’s open-source, available on any major operating system and
maintained by OpenJS Foundation whose aims is to raise the growth of JavaScript
and web ecosystem. By using “Javascript everywhere” paradigm, Node.js is
planning to unite web application development under a single language, in contrast

30
to conventional method of using separate programming language for frontend and
backend.

Express.js (or more commonly known as Express) is usually mentioned together


along with Node.js. It’s a web application framework that provide fast prototyping
to create backend services for web and mobile application including but not limited
to REST API, WebSocket server, etc.

2.7.2 Johnny-Five
Johnny-Five is the JavaScript robotics and IoT platform that enables developer
to write and run any Arduino projects using JavaScript. The only drawback it has
is the boards must be constantly connected to the host which run Node.js or
connected to Raspberry Pi which is capable to run Node.js.

2.7.3 React
React is one of the most popular JavaScript libraries used to develop scalable
user interfaces. By encouraging Component Driven Development which
breakdown every part of a website into a smaller code pieces called “components”,
that allows for code reusability turning debugging and managing web application
so much easier as developer did not need to scroll through a thousand lines of codes
just to fix one simple error. It also supports server-side rendering using Node.js and
mobile application using React Native.

2.8 Related Work


This section shows the works that suggest a different concept or method to
tackle the similar problems. The related works shown below can also use different
approach to solve another problem.

31
2.8.1 Rancangan Bangun Sistem Kontrol Irigasi Tetes untuk Pertanian Cabai
This automatic irrigation system works by utilizing moisture sensor to detect
soil moisture of chili plant with each watering is timed with specific interval from
the previous watering time. Developed by Muholidin as the requirement for
bachelor thesis in Yogyakarta Muhammadiyah University.

2.8.2 Rancangan Bangun Sistem Pengairan Sawah Otomatis menggunakan


Arduino dan Android
The system is built using Arduino Mega 2560 and DS18B20 temperature
sensors. It works by measuring the field temperature and moisture, and when the
data fall below the threshold, the microcontroller automatically opens the irrigation
water door to water the field. The data is displayed using 20x4 LCD and
manageable via Android application. Developed by Bayu Saputra for his bachelor
degree thesis in Bangka Belitung University.

32
2.9 Comparison Overview
The differences between this research and related works are explained in Table 2.3.

Table 2. 3 Feature Comparison with Related Works

Irigasi Pengairan
Features This Thesis
Tetes Sawah
Prototype can detect
water and soil moisture ✓ ✓ ✓
level.
Prototype automatically
water the plant based ✓ ✓ ✓
on gathered data and settings.
Prototype can get weather
❌ ❌ ✓
forecast data.
Owner can manage the
prototype from web / mobile ❌ ✓ ✓
application

33
CHAPTER III
SYTSEM ANALYSIS

This chapter purpose is to explain the analysis from program functions and
behavior as stated in the software requirements. The application requirements and
development procedure are shown in order to identify its goal and purpose. The
content of this chapter is the following: Functional Analysis, Use Case Narrative,
Swim Lane Diagram, Functional Analysis, Development Process Analysis, System
Overview, and Hardware and Software Requirements.

3.1 System Overview


The purpose of this research is to develop a system that allows automatic plant
watering based on current weather data and soil humidity using water level sensor
and moisture sensor. The system will be applied using Arduino as the
microcontroller of the sensors and Raspberry Pi as the server for communicating
between Arduino and the client. The sensor will run 24/7 and on each scheduled
time, the sensor will gather data from weather forecast using third-party API and
use the current soil moisture to determine the right time to water the plant. The data
will then be logged into a server containing the following information:

• Watering Time
Consist of two types of times: the start and end time. Both are the time when
the prototype starts and finish watering the plant
• Moisture Data
Moisture data of the soil before and after the watering.
• Water Usage
Track the usage of the water during this watering period.
• Performed By
Track whether the action is done automatically by the system or by the
owner.

34
The system is using SocketIO on top of Express.js server to provide real-time
connection, with React as its frontend framework for the web application. The
owner can configure the system settings via web applications and also view the
watering data recorded in the database to gain better insight of the water amount
the plant might need. This thesis is created in order to raise awareness of excessive
water usage as well as reducing manual labor required to do simple task.

3.2 Functional Analysis


The functional requirements of Automatic Watering System using Arduino and
Soil Moisture Sensor is explained in Table 3.1.

Table 3. 1 Functional Requirements

No. Functional Requirements


1. Manageable from web application.
2. Can detect soil moisture level and water storage level.
Can automatically water the plant based on gathered data and user
3.
settings.
4. Can manually water the plant from user input.

3.3 Software Development


The development requires a specific developments tools and libraries. Table 3.2
shows the software used to develop the system.

Table 3. 2 Software Requirements

Software
No. Function
Requirements
Used as an IDE to develop the frontend and
1 Visual Studio Code
backend for the web application.
2 Microsoft Word 2016 Used as documentation tools for this thesis.
3 Tinkercad Used to design the Arduino circuits.
4 Lucid Chart Used to design the Use Case diagram.

35
5 Figma Used to design the frontend wireframe.
6 Javascript Used both as server and frontend framework.
7 MongoDB Used as the database.
8 Postman Used to test the backend REST API.
Used as an intermediate protocol to bridge
Arduino which only accept C/C++ language and
9 Firmata
the host system running other programming
languages.

3.4 Hardware Development


The hardware requirements of the system are shown in Table 3.3.

Table 3. 3 Hardware Requirements

Hardware
No. Function
Requirements
Used to run all the software during the
1. PC
development process.
Used as the main computer to manage the
2. Raspberry Pi 3 Model B microcontroller during deployment as well as
the server for real-time monitoring.
3. Arduino Uno Used as the microcontroller of the prototype.
Used to measure soil moisture and humidity
4. Soil Moisture Sensor
level.
5. HR-SC04 Used to measure water level in the storage tank.
Used to connect multiple components of the
6. Jumper Wires
Arduino.
Used as platform connecting the Arduino to
7. Breadboard
various modules.
8. Water Pump Used as water pump from the storage to the pot.
Power Adapter 9V-12V
9. Used to provide power to the system.
DC

36
Power Adapter and Used to provide power to Raspberry Pi 3 and
10.
USB cable Arduino

3.5 Use Case Diagram


Use case diagram is a diagram that shows the relation between actor and the
system by describing the interaction of one or more actors with the system. Use
case diagram specify the expected behavior/results not the actual method of how to
achieve those results.

Figure 3. 1 Automatic Plant Watering System Use Case Diagram

3.6 Use Case Narrative


Use Case Narrative provide a better illustration events that happens during
actor-system encounter. Each event is broken down into smaller action and written
in table to provide structured reflection of the system’s use case narrative. The table
also include name used to identify the event name, description, precondition, event
sequences, post-condition, and system business rule.

37
Table 3. 4 Real-Time Monitoring Table

Name Real-Time Monitoring


ID UC01
Primary Business Actor User
Primary System Actor Prototype
Other Participating Actor None
The event when the system sends real-time data from
Description
the prototype to the client application.
Precondition None
User visit the web application, user monitor the data
received from the prototype, user manage the settings
Trigger
or leave it as default, the system will water the plant
based on the settings.
Typical Course of Event Actor Action System Response
Step 1: User visit the
website to view real-time
sensor data.
Step 2: The system is
sending the sensor data
from prototype to the
client.
The user can view real-time sensor data from the
Post Condition
prototype.

Business Rule • The prototype needs to constantly plugged in to


power supply and connected to the internet.

38
Table 3. 5 Automatic Watering on Scheduled Time

Name Automatic Watering on Scheduled Time


ID UC02
Primary Business
User
Actor
Primary System Actor System
Other Participating
None
Actor
The event where the prototype measure current
Description
weather data and current moisture level.
Precondition None
Trigger The time reached the scheduled time.
Typical Course of
Actor Action System Response
Event
Step 1: Reach the
scheduled time.
Step 2: The system fetch
current weather
prediction from 3rd party
API and tracked
watering count for the
day.
Step 3: If tracked
watering count for the
day exceed the amount
of maximum watering
defined in the
configuration, the
prototype will skip
watering.
Step 4.1: If the weather
prediction is raining, but
“ignoreWeather”
configuration is enabled,
the system will start
watering.
Step 4.2: If the weather
prediction is raining and
“ignoreWeather” is
disabled in the
configuration, the
prototype will skip
watering.

39
Step 5.1: If current soil
moisture data is below
the threshold, the
prototype will start
watering.
Step 5.2: If the current
soil moisture data is
above the threshold, the
prototype will skip
watering.
Step 6: The prototype
will send the watering
information to the
database after successful
watering.
Post Condition The prototype will work according to real-time data.
• The prototype needs to constantly plugged in to
Business Rule
power supply and connected to the internet.

Table 3. 6 Manual User Action

Name Manual User Action


ID UC03
Primary Business
User
Actor
Primary System Actor System
Other Participating
None
Actor
The event is when the prototype will water the
Description plant based on user input. It will ignore every user
defined setting except for the total time watering.
Precondition None
Trigger The user triggers the action from web application
Typical Course of
Actor Action System Response
Event
Step 1: The user visits
the web application.

Step 2: User trigger the


manual action from the
client application.

40
Step 3: The client
application emits
“manualPump” event to
the server using
WebSocket protocol.
Step 4. The server
receives the event and
order the prototype to
water the plant for the
duration defined in
configuration file.
Step 6: The prototype
will send the watering
information to the
database.
The prototype will work according to user action
Post Condition and perform action on specified total amount of
time.
• The prototype needs to constantly plugged in to
Business Rule
power supply and connected to the internet.

Table 3. 7 Change Prototype Settings

Name Change Prototype Settings


ID UC04
Primary Business
User
Actor
Primary System Actor System
Other Participating
None
Actor
The event where the system restarting the scheduler
Description
in order to reload the newly edited configuration.
Precondition None
Trigger The user triggers the action from web application
Typical Course of
Actor Action System Response
Event
Step 1: The user visits
the web application.

Step 2: User change the


prototype configuration
using the client
application.

41
Step 3: The client
application emits
“settingsUpdate” event
to the server using
WebSocket protocol.

Step 4: The server


receives the event and
re-fetch the new settings
data.

Step 5. The system will


reschedule automatic
watering using the new
value
The automatic watering is rescheduled to the new
Post Condition
settings.
• The prototype needs to constantly plugged in to
Business Rule
power supply and connected to the internet.

3.7 Swim Lane Diagram


Swim lane diagram is a flow chart to visually represent the system series of
action and control flow. The term activity is used to describe system operation
where the control flow is drawn between each operation.

42
Figure 3. 2 Real-Time Data Monitoring Swim Lane Diagram

Real-time data monitoring activity is explained in Figure 3.2. It starts by the


prototype activating its sensor and the result is captured by the system. If user visit
the web application, user can view real-time sensor data updated every one second
sends from the system using WebSocket protocol.

43
Figure 3. 3 Automatic Watering on Scheduled Time Swim Lane Diagram

Figure 3.3 shows the activity of automatic watering when the system has
reached the scheduled time. It starts by the system performing various check against
current sensor data and settings from database. If current sensor data is matched
with the settings, the system then order prototype to start watering using
predetermined settings and after each successful watering, the system will send the
watering log to be recorded in the database. If the check returns false, it will skip
watering and wait for the next scheduled time.

44
Figure 3. 4 Manual User Action Swim Lane Diagram

Figure 3.4 shows the activity for manual user action. By triggering the action
from client application, the system will receive the action transmitted using
WebSocket protocol and order the prototype to start watering, regardless of any
delimiters from user configuration except for the total time watering.

45
Figure 3. 5 Change Prototype Settings Swim Lane Diagram

Figure 3.5 shows the activity when the prototype settings is changed. When the
user changes the configuration from client, it will simultaneously update the
configuration stored in the database, prompting the system to reschedule based on
the updated configuration.

46
CHAPTER IV
SYSTEM DESIGN

The System Design chapter covers the user interfaces, data, components to
satisfy the system requirements.

4.1 User Interface Diagram


The client application design is shown in this section. The user interface is the
program visual part that aims to gives better user experience and as communication
method between the prototype and the client.

Figure 4.1 shows the dashboard menu for the user displaying current sensor data
in real-time and the latest watering data.

Figure 4. 1 Current Plant Status

47
Figure 4.2 shows the watering parameter for the owner to change – or it’ll run
using provided default settings if the owner didn’t change anything.

Figure 4. 2 Watering Settings Menu

48
4.2 Prototype System Design
The implemented Circuit Design and Wiring Diagram of the system is
explained in this section.

4.2.1 Wiring Diagram


Circuit Diagram shown in Figure 4.4 purpose is to gives better understanding
for Figure 4.3 Wiring Diagram.

Figure 4. 3 Wiring Diagram

49
The components that are used in the prototype shown in Figure 4.3 are the
following: Arduino Uno, HC-SR04 Ultrasonic Sensor, Soil Moisture Sensor, Relay
Module and 5V DC Pump.

Figure 4. 4 Fritzing Circuit Arduino and Modules

50
4.3 Entity Relationship Diagram
Figure 4.5 shows the Entity Relationship Diagram (ERD) that explain the
relationship for each table in the database.

Figure 4. 5 Automatic Watering System ERD

The database consists of four tables: User, WateringCount, WateringData,


WateringSettings. The WateringData table functions as a log for each watering
performed by either system or the user. The table has 7 attributes: DataID as the
Primary Key (PK), UserID as identifier for each log belongs to which user,
startTime, endTime, startHumidity, endHumidity, performedBy. The
WateringSettings table is changeable by use from the web application and is used
to defines the prototype settings. The table has 9 attributes: SettingsID (PK), UserID
(FK), pumpTime, repeatWatering, wateringHumidity, waterEvery,
wateringTimeRange, ignoredWeathers, ignoreWeather. The WateringCount table
is used to track how many times watering is performed today and is configured to
automatically reset at 00:00 system time zone.

51
CHAPTER V
SYSTEM IMPLEMENTATION

The implementation of automatic watering system prototype is described in this


section. The main tools to write the system source code is Visual Studio Code IDE,
while Arduino IDE is used to upload the firmware to board required to run and
control the Arduino from Javascript. The Javascript will read sensor data from the
board and to communicate to the client in real-time using WebSocket, and to
connect to the database. This chapter consist of 2 parts: Prototype System Details
and User Interface. The Prototype System Details shows the source code
implemented in the system while the UI section describe the client application user
interfaces to provide the user ability to monitor and control the prototype.

5.1 User Interface Design


This section shows the following user interfaces: main homepage for real-time
monitoring and settings page for configuring the automatic watering settings. The
monitoring page also provides manual pumping option if the user desire to ignore
the automatic settings.

Figure 5. 1 Interface of Monitoring Page

52
And the automatic watering configuration can be managed using the setting
page as shown in Figure 5.2. After each successful update, the system will restart
the scheduler in order to load the new configured settings.

Figure 5. 2 Interface of Prototype Configuration Page

5.2 Prototype System Details


The detailed source code behind the prototype features are explained in this
section.

5.2.1 Initialization
This process explains the initialization phase of the prototype. This process
consists of loading the necessary module for the system and the board to run.

require("dotenv").config();
const { Boards, Proximity, Sensor, Pin } = require("johnny-five");

53
const raspi = require("raspi-io").RaspiIO;
const { calibrateSoilSensor, calculateWaterLevel } = require("./helper/
helper");
const schedule = require("node-schedule");
const express = require("express");

const app = express();


app.use(express.json());
app.use(express.urlencoded({ extended: false }));

const { default: axios } = require("axios");


const url = process.env.SERVER_URL;

const http = require("http").Server(app);


const io = require("socket.io")(http, {
cors: {
origin: "*",
methods: ["GET", "POST"],
},
});

const boards = new Boards([


{ id: "pi", io: new raspi() },
{ id: "uno", port: "/dev/ttyACM0", repl: false },
]);
Figure 5. 3 Initialization Process Source Code

As shown in Figure 5.3, the program starts by loading necessary module from
Johnny-Five library as the means to read sensor data and control the boards. Line 2
is creating new instance of Raspberry Pi library as the system code will be run on
the Raspberry Pi. Helper functions are also imported during this period which are
used to convert sensor data to human readable language. The WebSocket server is
also declared on top of basic http server. The initialization ends by creating new
instance of Boards which takes array of objects with Raspberry Pi and Arduino Uno
as the arguments.

5.2.2 Global State


Declaring global state for the system allows for flexibility as the Boards
function job shown in Figure 5.5 is only to read the sensor data and then rewrite the
global state with the new sensor data.

54
// Global state
let settings = {};

let arduinoData = {
waterLevel: 0,
humidityLevel: 0,
};

let waterData = {
startTime: null,
endTime: null,
startHumidity: 50,
endHumidity: 60,
performedBy: "",
};

const devices = {};


Figure 5. 4 Global State Source Code

The object arduinoData is used to store sensor data while both waterData and
settings object is used as reusable code that will be called after each successful
watering and new configuration update respectively. And the devices object is used
to store Arduino module to be used outside of Boards function scope shown in
Figure 5.5 such as turning on the pump on scheduled time.

5.2.3 Starting the Boards


This function is called when the system can successfully connect to the
Raspberry Pi and Arduino Uno as defined in boards instance shown in Figure 5.3
and all modules connected to boards is functioning properly.

boards.on("ready", function () {
// Init pump pin
devices.pump = new Pin({
pin: 4,
board: boards.byId("uno"),
});
devices.pump.high();

// Gathering water level data


const waterLevel = new Proximity({
controller: "HCSR04",
pin: 10,

55
freq: 1000,
board: boards.byId("uno"),
});

waterLevel.on("data", (data) => {


arduinoData = {
...arduinoData,
waterLevel: calculateWaterLevel(data.cm),
};
});

// Gathering soil moisture data


const humidity = new Sensor({
pin: "A0",
freq: 500,
board: boards.byId("uno"),
});

humidity.on("data", (data) => {


arduinoData = {
...arduinoData,
humidityLevel: calibrateSoilSensor(data),
};
});
});
Figure 5. 5 Initialization Process Source Code

After the boards is ready then the system will try to communicate with modules
defined in devices.pump, waterLevel, and humidity instances. The devices.pump
store new key-value pair to the devices global state defined in Figure 5.4. While
both waterLevel and humidity function have default arguments “data” that means
on every data change from sensor reading resulted in calling the callback function
for rewriting the sensor data back to arduinoData global state.

5.2.4 Real Time Sensor Data Transfer


This section explains the process of sending sensor data in real-time to the client
for monitoring over WebSocket protocol by calling io function declared in Figure
5.6.

// publish data to client on interval


setInterval(() => {
io.emit("currentStatus", arduinoData);

56
io.emit("getNextWatering", new Date(wateringJob.nextInvocation()));
}, 1000);
Figure 5. 6 Real Time Sensor Data Transfer Source Code

By utilizing Javascript native setInterval function which allow continuous run


of action every specified time, the io function will emit an action to the client with
2 arguments: the name of the action, and the data to send to the client. When the
client receives the action, it will re-render to display newly updated data.

5.2.5 Pump Function


This section includes two functions: startWatering and stopWatering. When the
startWatering function is called it will send LOW value to pump defined inside
devices object to turning it on, while doing so, it also emits an event to let the client
know that the system is currently performing an action.

// Function to control pumping


const startWatering = () => {
devices.pump.low();
io.emit("pumpStatus", {
pumpStatus: "Pumping",
});
waterData = {
...waterData,
startTime: new Date(),
startHumidity: arduinoData.humidityLevel,
};
};

const stopWatering = async (actor, wateringCount) => {


devices.pump.high();
io.emit("pumpStatus", {
pumpStatus: "Idle",
});

waterData = {
...waterData,
endHumidity: arduinoData.humidityLevel,
endTime: new Date(),
performedBy: actor,
};

await axios.post(`${url}/watering-data`, waterData);

57
io.emit("latestWatering");

if (actor === "User") {


return null;
} else {
let waterCountTemp = {
...wateringCount,
count: wateringCount.count + 1,
};

return await axios.patch(


`${url}/count/60ae75dbce061c52bcf8d62c`,
waterCountTemp
);
}
};
Figure 5. 7 Pump Function Source Code

And when endWatering function is called, it will send HIGH value to the pump
pin to turn it off. But as opposed to startWatering, this function is a bit different as
it takes two arguments: actor and wateringCount. These arguments are needed for
the system to differentiate between action performed by user and by system, and to
send new watering data to the database.

5.2.6 User Controlled Action


As the prototype is expected to accept manual user action instead of just running
indefinitely, real-time connection between client and server is required. On the
Figure 5.8, the io function is called on the default ”connection” event (the client is
connected to the server), with socket as the event handler. The example in
“socket.on(“pumpInit”)” means that every time the user trigger manual pump
action from the web application, it will call startWatering function shown in Figure
5.7, and by using setTimeout function that will perform an action after specific
amount of time has passed, it will call endWatering function indicating that the
watering process has finished.

// Manual pumping
io.on("connection", (socket) => {
socket.on("pumpInit", async (data) => {

58
if (data.pumpStatus === "Pumping") {
startWatering();

setTimeout(async () => {
stopWatering("User");
}, settings.pumpTime * 1000);
}
return;
});

socket.on("settingsUpdate", () => {
generateNewSchedule()
});
});
Figure 5. 8 User Controlled Action Source Code

The process will also listen to action “settingsUpdate” which triggered on every
settings update made by the user. It will call a function shown in Figure 5.10 to
restart the scheduler using the new value.

5.2.7 Scheduler
The system has two schedulers running in parallel, each with its own purpose:
wateringJob and resetJob. The scheduler is taking advantages of node-schedule
library, which is a time-based job scheduler for any major operating system to run
any action at fixed times, dates, or interval similar to cron, a scheduler for most
Unix/Linux system.

5.2.7.1 Automatic Watering Scheduler


The process of creating a scheduler is started by creating wateringJob function
with fake schedule and call generateNewSchedule function shown in Figure 5.10.

const wateringJob = schedule.scheduleJob("* * * * *", async () => {


try {
const {
data: { weather },
} = await axios.get(
`https://api.openweathermap.org/data/2.5/weather?q=Cikarang&appid
=${process.env.WEATHER_API}&units=metric`
);

59
weathers = {
...weathers,
name: weather[0].main,
};

const { data } = await axios.get(`${url}/count/60ae75dbce061c52bcf8


d62c`);

if (data.count >= settings.repeatWatering) {


console.log("Exceed watering count for today");
} else if (data.count < settings.repeatWatering) {
if (
arduinoData.humidityLevel <= settings.wateringHumidity &&
settings.ignoreWeather === true
) {
console.log("watering with ignore weather true");
startWatering();

setTimeout(async () => {
stopWatering("System", data);
}, settings.pumpTime * 1000);
} else if (
arduinoData.humidityLevel <= settings.wateringHumidity &&
settings.ignoreWeather === false
) {
console.log(weathers);
console.log(settings.ignoredWeathers);
if (settings.ignoredWeathers.indexOf(weathers.name) > -1) {
console.log(
"Current force cast is matched with ignored weathers in set
tings\nSkipping..."
);
} else {
startWatering();

console.log("watering with ignore weather false");

setTimeout(async () => {
stopWatering("System", data);
}, settings.pumpTime * 1000);
}
} else if (arduinoData.humidityLevel > settings.wateringHumidity)
{
console.log("skip watering because the soil still moist");
}
} else {
console.log("skip watering");
}
} catch (err) {
console.log(err);
}
});
Figure 5. 9 Automatic Watering Scheduler Source Code

60
const generateNewSchedule = async () => {
const { data: data } = await axios.get(
`${url}/settings/60ad5a5f08b24b313cc23dea`
);

settings = {
...data,
};

console.log(`Settings updated...\nRescheduling job`);


wateringJob.reschedule(
`0 ${settings.wateringTimeRange[0]}-
${settings.wateringTimeRange[1]}/${settings.waterEvery} * * *`
);
};
Figure 5. 10 Generate New Schedule Function Source Code

The schedule is written using cron syntax i.e., “* * * * *” which translate to


“run an action at every minute” or “0 9-17/3 * * *” which translate to “run an
action at minute 0 past every 3rd hour from 1 through 17”. The reason behind using
a fake schedule then overwrite it during system start and/or new configuration
update is due to a bug encountered during development process on which the system
fails to restart after saving new configuration file. And by using this method, it
allows the scheduler to be restarted without affecting system availability.

61
5.2.7.2 Reset Job
The purpose of resetJob scheduler is to reset the watering count back to 0 on
every start of new day at 00:00 system time zone.

const resetJob = schedule.scheduleJob("0 0 * * *", async () => {


try {
let waterCountTemp = {
count: 0,
};

return await axios.patch(


`${url}/count/60ae75dbce061c52bcf8d62c`,
waterCountTemp
);
} catch (err) {
console.log(err);
}
});
Figure 5. 11 Watering Count Reset Source Code

62
CHAPTER VI
SYSTEM TESTING

The test-case written in this chapter is used to ensure the completed program
meets the software requirement defined in the previous chapter. This chapter consist
of two parts which are the followings: testing scenario and environment.

6.1 Testing Environment


Before the testing began, the system needs to use the hardware requirement to
ensure the system functionality. The following condition needs to be satisfied in
order to perform the testing:

1. The system and the prototype must be connected to the internet at all times.
2. The protype must be constantly connected to power supply.

6.2 Testing Scenario


Testing scenario is a multiple test-case to test the system functionality against
multiple scenarios without inspecting the system code, therefore only the physical
and/or digital result of the system is reviewed.

6.2.1 Real Time Data Monitoring


The results from real time data monitoring are shown in Table 6.1

Table 6. 1 Real Time Monitoring Test-case

No. Scenario Expected Result Evaluation


The prototype is not plugged The web application
1. in to the power supply and/or is not displaying real- As expected.
not connected to internet. time data.

63
The prototype is plugged in The web application
2. to the power supply and is displaying real- As expected.
connected to internet. time data.

Figure 6. 1 Result of Real Time Monitoring Test-case No. 1

In Figure 6.1 is showing the result from Table 6.1 scenario No. 1 where it
displays no value in the place of Soil Humidity and Water Level, while Figure 6.2
is showing the result from Table 6.1 scenario No. 2, where the data is updated in
real-time.

64
Figure 6. 2 Result of Real Time Monitoring Test-case No. 2

6.2.2 Automatic Watering Based on User Settings


This section evaluates the features performed automatically by the prototype in
accordance to the user settings and the system requirements as shown in Table 6.2

Table 6. 2 Automatic Watering Feature Test-case

No. Scenario Expected Result Evaluation


The prototype
Perform soil moisture successfully read soil
1. As expected.
sensor reading. moisture data from the
sensor.
Perform watering action The prototype can
2. on specific time and successfully perform As expected.
specific settings. action on specific time.
Continuous sensor The system can fetch
3. As expected.
reading. sensor data from the

65
prototype for a long
duration without restart.
The system read and
Read and write real-time
write real-time event to
4. event to and/or from the As expected.
and/or from the client
client.
and perform accordingly.

The results for automatic watering are shown in Figure 6.4, 6.5, 6.6, and 6.7
respectively where Figure 6.4 and 6.5 shows the watering results while Figure 6.6
and 6.7 shows the system decided to skip watering because real-time data does not
match with the user configuration.

6.2.3 Manual Pump by the User


This section evaluates the user-based action to the prototype with test case
shown in Table 6.3.

Table 6. 3 Manual User Action Test-case

No. Scenario Expected Result Evaluation


The prototype
1. Watering on user action. successfully turns on the As expected.
pump after user action.

6.2.4 Configure Automatic Watering Settings


This section evaluates the effect of updating the configuration from the web
application to the system and prototype.

Table 6. 4 Prototype Settings Update Test-case

No. Scenario Expected Result Evaluation


User update the The prototype restarts the
1. configuration from web scheduler to work with As expected.
application. new value.

66
In Figure 6.3 shows that the system recognizes update action from user and
restarting the system to load the new configuration.

Figure 6. 3 Prototype Settings Update Result

6.3 Testing Result Pictures

Figure 6. 4 Automatic Watering on Scheduled Time Result

Figure 6. 5 Automatic Watering on Scheduled Time Result

Figure 6. 6 Automatic Watering on Scheduled Time Result

67
Figure 6. 7 Automatic Watering on Scheduled Time Result

Figure 6. 8 Manual User Action Result

Figure 6. 9 Manual User Action Result

68
CHAPTER VII
Conclusion and Further Work

7.1 Conclusion
The development of the system and the prototype in this thesis results in the
following conclusions:

1. The prototype can inspire farmer to start adapting with new technology that
doesn’t require much of manual labor, this thesis achieve this result by
putting an emphasis on schedule-based pumping with custom timer and
interval to ensure that the plant is properly watered.
2. The prototype can measure moisture and water storage level from sensor as
well as sending those data to the client in real-time.
3. The prototype can be configured manually by the user.
4. The prototype can complete its task automatically without needing user
action at scheduled time.

7.2 Further Work


To accomplish the perfect watering system that are able to perform
automatically without user interference further work is need. This thesis source
code will be open-sourced once the author has finished their thesis defense. The
followings suggestion are things that can be implemented to improve this thesis.

1. Better consumption of electricity. Even though both Raspberry Pi 3 and


Arduino Uno did not use much power, the system is actually running 24/7
to ensure real-time monitoring is working so timed sleep will save even
more power usage.
2. Adding fail-save method to ensure the system is still running in case of an
error or module failure happens during runtime.

69
3. Multiple sensor and module. The ability to use multiple sensors will be nice
addition for user that operates large farming facility. This could also add
even more features such as sunlight detection, etc.
4. Automatic water tank fill.
5. Use AI to configure watering settings by learn the water usage based on
watering logs and plant type. Useful in large farming facility.

70
REFERENCES

Arduino.cc. (2019, December 24). Firmata

Library. https://www.arduino.cc/en/reference/firmata

The Economic Times. (n.d.). What is Waterfall

Model? https://economictimes.indiatimes.com/definition/waterfall-

model

Facebook Open Source. (n.d.). ReactJs Documentation.

https://reactjs.org/docs/getting-started.html.

(n.d.). https://github.com/firmata/arduino.

Johnny-Five. (n.d.). Johnny-Five Documentation.

https://github.com/rwaldron/johnny-five/wiki/Getting-Started.

Makerspace. (n.d.). Arduino For Beginner.

https://www.makerspaces.com/arduino-uno-tutorial-beginners/.

Muholidin. (2015). Rancang Bangun Sistem Kontrol Irigasi Tetes (Drip

Irrigation) untuk Pertanian Cabai [Master's

thesis]. http://thesis.umy.ac.id/datapublik/t77330.pdf

OECD. (n.d.). Water and Agriculture.

https://www.oecd.org/agriculture/topics/water-and-agriculture/.

Saputera, Bayu. (2018). Rancang Bangun Prototype Sistem Pengairan Sawah

Menggunakan Arduino dan Android [Master's

thesis]. http://repository.ubb.ac.id/1243/

Tutorial Points. (n.d.). SDLC - Waterfall Model.

https://www.tutorialspoint.com/sdlc/sdlc_waterfall_model.htm.

71
The World Bank. (2021, May 8). Water In Agriculture.

https://www.worldbank.org/en/topic/water-in-agriculture.

72

You might also like