manually and remotely controlled power outlets …

86
President University i MANUALLY AND REMOTELY CONTROLLED POWER OUTLETS WITH PASSWORD USING ARDUINO MEGA 2560 AND GPRS SHIELD A final project report presented to the Faculty of Engineering By The, Joses Hidayat 002201000012 in partial fulfillment of the requirements of the degree Bachelor of Science in Electrical Engineering President University January 2015

Upload: others

Post on 24-Nov-2021

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: MANUALLY AND REMOTELY CONTROLLED POWER OUTLETS …

President University i

MANUALLY AND REMOTELY CONTROLLED

POWER OUTLETS WITH PASSWORD

USING ARDUINO MEGA 2560 AND GPRS SHIELD

A final project report

presented to

the Faculty of Engineering

By

The, Joses Hidayat

002201000012

in partial fulfillment

of the requirements of the degree

Bachelor of Science in Electrical Engineering

President University

January 2015

Page 2: MANUALLY AND REMOTELY CONTROLLED POWER OUTLETS …

President University ii

“For My thoughts are not your thoughts,

and

My ways are not your ways,”

says the Lord.

— Isaiah 55:8, NLV

Page 3: MANUALLY AND REMOTELY CONTROLLED POWER OUTLETS …

President University iii

DECLARATION OF ORIGINALITY

I declare that this final project report, entitled ―Manually and Remotely Controlled Power

Outlets with Password Using Arduino Mega 2560 and GPRS Shield‖ is my own original

piece of work and, to the best of my knowledge and belief, has not been submitted, either

in whole or in part, to another university to obtain a degree. All sources that are quoted or

referred to are truly declared.

Cikarang, Indonesia, January 2015

The, Joses Hidayat

Page 4: MANUALLY AND REMOTELY CONTROLLED POWER OUTLETS …

President University iv

MANUALLY AND REMOTELY CONTROLLED

POWER OUTLETS WITH PASSWORD

USING ARDUINO MEGA 2560 AND GPRS SHIELD

By

The, Joses Hidayat

002201000012

Approved by

Ir. Carolus Kaswandi, M.Sc.

Final Project Supervisor

Dr.-Ing. Erwin Sitompul

Head of Study Program

Electrical Engineering

Dr.-Ing. Erwin Sitompul

Dean of Faculty of Engineering

Page 5: MANUALLY AND REMOTELY CONTROLLED POWER OUTLETS …

President University v

ACKNOWLEDGMENTS

I would like to express my deepest appreciation and gratitude to my final project

supervisor Ir. Carolus Kaswandi, M.Sc. for his guidance and patience during the process of

the final project so this final project can be done.

I also would like to thank all the people who write books, tutorials, and webpage

information I took as the references to create this final project. Furthermore, I would like to

thank my final project defense committee: Arthur Silitonga, M.Sc. and Ir. Irwan Margono,

M.Sc. for their attention, understanding, encouragement, insightful comments, and hard

questions.

I also would like to thank Dr.-Ing. Erwin Sitompul as the Dean of Faculty of Engineering

for his support during the days of the submission. I would like to thank all my lecturers for

the learning process they gave. Moreover, I would like to thank Iksan Bukhori, BSEE. as

the laboratory assistant for his guidance and support also.

Besides all of my lecturers, I would like to thank my family: Dad, Mom, Iiwing, Oo, Aan,

Ivan, the Hidayats, and the Liems for their support and enthusiast asking me when I will

finish my study.

I also want to thank all of my friends for their help, support, laughter, advice, and of course

for the hardest and yet boring and the most asked questions which are why I was still

around campus and when I would finish this project. Finally I did it guys! My university

life was wonderful with you guys: Deny, Dety, Rifky, Monica Sabrina, Alex, Bryan, Dicky

Kuswira, Dimas, Kristiawan, Arif, Albab, Hime, Thomas, Melisa, Sandra, Ruth Isaura,

Saras, Rizaldi, Astien, Rhiza, Dicky Salim, Calvin, Anthony, Resa, Ika, Don, Vanya, Cecil,

Lyras, Zerlyn, Aga, Okto, Natalia, Ruth Febrina, Rifka, Lilia, Barct, Winson, Putri, Okta,

Dita, Monica, Alfred, Becca, Nia, Atha, Ida, Inov, Ryan, Kris, Kriswanto, Stephiena, Ditta

Ariska, Melinda, Beta, Tode, Nicky, Abel, Andre, Bobby, Kezia, Yanti, Ardian, Ckendyh,

Johnson, Fikri, Adrian, Vincent, Anthony, Reyhan, Tanto, Hendy, Zakaria, Benaya,

Darren, Yokep, MY, Herry, Dery, Andrew, Yudi, Nia, Ainul, Lita, Yasti, Bonnie, Ivena,

Dita Nurul, Vivi, Nadhira, Merry, Vinni, Ingrit, Justine, Yudhistira, Fadli, Kak Chua, Kak

Oki, Mba So, Kak Bill, Kak Yudi, Kak Sigit, Ko Sugi, Kak Bagoes, Ko Bernard, Ko Ste,

Page 6: MANUALLY AND REMOTELY CONTROLLED POWER OUTLETS …

President University vi

Ko Jo, Kak Jer, Kak Feisal, Kak Grace, Ko Fen, Kak Nike, Kak Marlon, Kak Marintan,

Kak Mima, Kak Bebes, Kak Braska, Tere, Tasya, Jiyagi, Jericho, Ben, Uthe, Lambok,

Yana, Christian, Debo, Nike, Sam, Elo, Yasin, Fiedel, Jay, Henry, Rahmat, Clara, Jo,

Cindot, Angga, Rendy, Sang, Yoga, Melvin, Karema, Robert, Christy, Vina, Bu Diery, Pak

Dahliar, Bude, Mba Tini, Mas Dwi, and all of people whom I cannot mention one by one.

This final project cannot be done without the support from all of you. Thank you!

Cikarang, January 2015

The, Joses Hidayat

Page 7: MANUALLY AND REMOTELY CONTROLLED POWER OUTLETS …

President University vii

APPROVAL FOR SCIENTIFC PUBLICATION

I hereby, 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 project report

with the title:

MANUALLY AND REMOTELY CONTROLLED

POWER OUTLETS WITH PASSWORD

USING ARDUINO MEGA 2560 AND GPRS SHIELD

along with the related software or hardware prototype (if needed). With this non-exclusive

royalty-free right, President University is entitled to conserve, to convert, to manage in a

database, to maintain, and to publish my final project report. These are to be done with the

obligation from President University to mention my name as the copyright owner of my

final project report.

Cikarang, January 2015

The, Joses Hidayat

002201000012

Page 8: MANUALLY AND REMOTELY CONTROLLED POWER OUTLETS …

President University viii

ABSTRACT

This project is entitled ―Manually and Remotely Controlled Power Outlets with Password

using Arduino Mega 2560 and GPRS Shield‖. The main objective of this project is to

create a new design power outlet which can be controlled by password or by SMS. These

outlets can be controlled manually by inputting the correct password via keypad and

remotely by sending a text message to the outlets. The text message contains a unique

password for each outlet. Thus, by using the relay, the electric current from the outlets will

not flow unless the correct password is inputted or sent via SMS. The password used in

this project is a 4-digit unique password for each outlet. This project uses Arduino Mega

2560 as the microcontroller. This project also includes two power outlets and LEDs, LCD,

keypad, power supply, and GPRS shield. The SMS system is created by the help of GPRS

shield. By using this type of outlets, parents do not need to worry their toddlers play

outlets. Another function is people can control their own outlets so not anybody can use

their outlets without their permission.

Keywords: controllable power outlet, Arduino Mega 2560, liquid crystal library, keypad

library, password library, GPRS shield, SMS.

Page 9: MANUALLY AND REMOTELY CONTROLLED POWER OUTLETS …

President University ix

TABLE OF CONTENT

TITLE PAGE ..................................................................................................................... i

DECLARATION OF ORIGINALITY ............................................................................. iii

FINAL PROJECT REPORT APPROVAL PAGE ............................................................ iv

ACKNOWLEDGMENTS ..................................................................................................v

SCIENTIFC PUBLICATION APPROVAL PAGE ......................................................... vii

ABSTRACT .................................................................................................................. viii

TABLE OF CONTENT ................................................................................................... ix

LIST OF FIGURES ......................................................................................................... xi

LIST OF TABLES .......................................................................................................... xii

CHAPTER 1 INTRODUCTION ........................................................................................1

1.1. Final Project Background .....................................................................................1

1.2. Problem Statement ...............................................................................................2

1.3. Final Project Objectives........................................................................................2

1.4. Final Project Scopes and Limitations ....................................................................2

1.5. Final Project Outline ............................................................................................3

CHAPTER 2 DESIGN SPECIFICATION .........................................................................4

2.1. Arduino Mega 2560..............................................................................................4

2.2. Seeed Studio Arduino GPRS Shield V2.0 .............................................................5

2.3. Mean Well Switch Power Supply S-50-5 ..............................................................8

2.4. Keypad .................................................................................................................8

2.5. Liquid Crystal Display .........................................................................................9

2.6. Light Emitting Diode .......................................................................................... 10

2.7. Relay…… .......................................................................................................... 11

2.8. Power Outlet ...................................................................................................... 12

2.9. Arduino Integrated Development Environment (IDE) 1.0.5 ................................ 13

CHAPTER 3 DESIGN IMPLEMENTATION ................................................................. 16

3.1. Interfacing Arduino Mega 2560 with LED ......................................................... 16

Page 10: MANUALLY AND REMOTELY CONTROLLED POWER OUTLETS …

President University x

3.2. Interfacing Arduino Mega 2560 with LCD and Keypad ...................................... 17

3.2.1. Interfacing Arduino Mega 2560 with LCD ............................................. 17

3.2.2. Interfacing Arduino Mega 2560 with LCD and Keypad .......................... 18

3.3. Using Arduino Password Library........................................................................ 21

3.4. Interfacing Arduino Mega 2560 with Relay and Outlet ....................................... 21

3.5. Interfacing Arduino Mega 2560 with GPRS Shield............................................. 22

3.5.1. Send an SMS .......................................................................................... 22

3.5.2. Control LEDs via SMS ........................................................................... 23

CHAPTER 4 RESULTS AND DISCUSSIONS ............................................................... 25

4.1. Results. .............................................................................................................. 25

4.2. Discussions ........................................................................................................ 29

CHAPTER 5 CONCLUSIONS AND RECOMMENDATIONS ....................................... 31

5.1. Conclusions ........................................................................................................ 31

5.2. Recommendations............................................................................................... 31

REFERENCES ................................................................................................................ 32

APPENDIX A SKETCHES OF DESIGN IMPLEMENTATION ..................................... 34

APPENDIX B CIRCUIT DIAGRAM .............................................................................. 48

APPENDIX C FLOW CHART DIAGRAM ..................................................................... 49

APPENDIX D SOURCE CODE ...................................................................................... 51

Page 11: MANUALLY AND REMOTELY CONTROLLED POWER OUTLETS …

President University xi

LIST OF FIGURES

Figure 2.1 Arduino Mega 2560 front and rear [3] ................................................................4

Figure 2.2 Seeed Studio GPRS Shield v2.0 front and rear ..................................................6

Figure 2.3 Seeed Studio GPRS Shield v2.0 interface function [5] .......................................7

Figure 2.4 Mean well power supply [7] ..............................................................................8

Figure 2.5 3x4 Matrix membrane keypad and its keys connections .....................................9

Figure 2.6 16x2 LCD front and rear ................................................................................. 10

Figure 2.7 LED leads and symbol .................................................................................... 10

Figure 2.8 Relay based on pin distribution and internal configuration [9] ......................... 11

Figure 2.9 5 pins relay configuration [9] .......................................................................... 12

Figure 2.10 Outlet types F (Schuko outlet) ....................................................................... 12

Figure 2.11 Arduino IDE 1.0.5 layout .............................................................................. 13

Figure 2.12 Arduino IDE 1.0.5 toolbars ........................................................................... 14

Figure 3.1 Interfacing LEDs to Arduino ........................................................................... 16

Figure 3.2 Interfacing LCD to Arduino Mega 2560 .......................................................... 18

Figure 3.3 3x4 keypad configuration ................................................................................ 19

Figure 3.4 Interfacing LCD and 3x4 keypad to Arduino Mega 2560 ................................. 20

Figure 3.5 Takamisawa JS5N-K relay pin configuration [17] ........................................... 21

Figure 3.6 Interfacing relay and outlet to Arduino Mega 2560 .......................................... 22

Figure 3.7 Interfacing GPRS Shield to Arduino Mega 2560 ............................................. 23

Figure 3.8 Circuit diagram to control LEDS via SMS ....................................................... 24

Figure 4.1 Final result of the project ................................................................................. 25

Figure 4.2 The layout of the device .................................................................................. 26

Figure 4.3 The four steps within the device ...................................................................... 26

Figure 4.4 Initializing process .......................................................................................... 27

Figure 4.5 Enter password ................................................................................................ 27

Figure 4.6 Exit key ........................................................................................................... 28

Figure 4.7 Example of sent message (left) and received message (right) ........................... 28

Figure 4.8 The gap for the USB connection ...................................................................... 29

Figure 4.9 SMS time delay graph ..................................................................................... 30

Page 12: MANUALLY AND REMOTELY CONTROLLED POWER OUTLETS …

President University xii

LIST OF TABLES

Table 2.1 Arduino Mega 2560 Specification [2] .................................................................5

Table 2.2 Seeed Studio GPRS Shield Pins Configuration [5] ..............................................7

Table 2.3 16x2 LCD Pins Configuration ............................................................................9

Table 3.1 3x4 Keypad Configuration ................................................................................ 19

Page 13: MANUALLY AND REMOTELY CONTROLLED POWER OUTLETS …

President University 1

CHAPTER 1

INTRODUCTION

1.1. Final Project Background

Nowadays, electricity is one of the most important things around us. Electricity plays

important role in this modern era. Every new gadget invented by scientists needs

electricity. You cannot charge your devices, watch your favorite TV show, and even play

your favorite video games without electricity. This electricity can be used via outlet in your

home, office, or even in your hangout places. You just plug in your electric cord devices

and there you have it the electricity. It is easier to use electricity these days.

At home, despite the need of electricity, parent are worried about their children especially

toddlers. With the high curiosity they have, they play with many things including the

outlet. They try to put things into the hole of the outlet. They put pencil, scissors, hairpin,

even their finger. The worst case is when the things they try to put are conductors to

electricity. They can be electrically shocked.

Moreover, some places, such as stations, malls, and restaurants have provided free

electricity outlet as their facilities. However, the problem occurs when the outlet is not

supposed to be used by many people, or in other words, the outlet is not free to use, but

people still use it or people use it in such a long time. In home or office, people use

electricity unwisely. They turn electronic devices on for a long time. This can lead to the

increasing of electricity bill to be paid.

Therefore, the idea of the final project is to create an outlet which can be controlled

through password. The electricity will flow through the outlet when someone has inputted

the right password. In addition, the outlet should be controlled remotely too. The Short

Messaging Service (SMS) is the one that should be used. It is like home automation via

SMS [1], but in this case, the outlet is the one we control. By using this kind of outlet, we

can control the electricity which flows through the outlet.

Page 14: MANUALLY AND REMOTELY CONTROLLED POWER OUTLETS …

President University 2

1.2. Problem Statement

This project will mainly focus on designing an outlet by using Arduino Mega 2560 as the

controller. The Arduino Mega 2560 will be programmed through software Arduino

Integrated Development Environment (IDE) 1.0.5.

First step is creating the manually controlled outlet through password. After it had done

and succeeded, the next step is creating the remotely controlled outlet through SMS. The

SMS will be done with GPRS (General Packet Radio Service) Shield V2.0 from Seeed

Studio. The final step is merging both the systems and there is the new outlet design!

1.3. Final Project Objectives

The objectives of this final project are:

1. To design a device that can control an outlet through password. Someone should input

the right password before using the outlet.

2. To control the outlet from any distant by using SMS.

In conclusion, the objective of the final project is to create an outlet which can be

controlled both manually through password and remotely through SMS.

1.4. Final Project Scopes and Limitations

The final project will be conducted under the following scopes:

This final project will discuss about designing new outlet combined with controller.

The controller used is Arduino Mega 2560. To create communication system for SMS,

Arduino GPRS Shield V2.0 from Seeed Studio is used.

The software used to upload the program to Arduino is Arduino Integrated

Development Environment (IDE) 1.0.5. This software can be downloaded in Arduino

website.

In conducting this research, there are several limitations to be considered:

The design of the final project only composed of hardware and software components.

These hardware and software components are connected and trialed through some

experiments. No detailed mathematical calculation needed.

Page 15: MANUALLY AND REMOTELY CONTROLLED POWER OUTLETS …

President University 3

The final project is made and to be applied in Indonesia. Therefore, the outlet used is

the typical outlet in Indonesia with two holes.

This final project is a development of an existing outlet design. The common outlet is

combined with the controller to control the outlet through password and SMS.

1.5. Final Project Outline

The final project report consists of five chapters and is outlined as follows:

Chapter 1: Introduction. This chapter consists of problem background, Final Project

statement, Final Project objectives, Final Project scopes and limitations, and Final Project

outline.

Chapter 2: Design Specification. This chapter describes the specifications of final project

design. The specifications are both hardware and software used to build the final project in

order to meet the objectives.

Chapter 3: Design Implementation. This chapter describes the techniques and

implementation of the previously described design, how the hardware and software are

used to build the final project.

Chapter 4: Results and Discussions. This chapter consists of the result and analysis of the

final project. How the final project works is also described in this chapter.

Chapter 5: Conclusions and Recommendations. This chapter consists of conclusions

obtained throughout this project and recommendations for future projects.

Page 16: MANUALLY AND REMOTELY CONTROLLED POWER OUTLETS …

President University 4

CHAPTER 2

DESIGN SPECIFICATION

These are hardware and software needed to create this project besides resistors, capacitors,

and cables:

2.1. Arduino Mega 2560

Arduino is an open source and easy-to-learn microcontroller. Invented in 2005 by Massimo

Banzi and his friends, David Cuartielles, Gianluca Martino, Tom Igoe, and David Mellis,

this open source platform has procreated an international do-it-yourself revolution in

electronics because of its easy to use and compile. It can be connected with sensors,

motors, or any other devices. User just simply connects it to the computer through the USB

cable to upload the program. It comes in many versions. One of them is Arduino Mega

2560.

Arduino Mega 2560 is an Arduino board which uses ATmega2560 as the base. It has 54

digital input/output pins (of which 15 can be used as PWM —Pulse Width Modulation—

outputs), 16 analog inputs, 4 UARTs (hardware serial ports), a 16 MHz crystal oscillator, a

USB connection, a power jack, an ICSP header, and a reset button [2]. Figure 2.1 shows

the front and rear layout of the board.

Figure 2.1 Arduino Mega 2560 front and rear [3]

Digital input pin will sense the presence and absence of voltage while the analog input pin

measures a range of voltage on the pin [4:148-149]. Digital pins will operate at 5 volts and

Page 17: MANUALLY AND REMOTELY CONTROLLED POWER OUTLETS …

President University 5

use pinMode(), digitalWrite(), and digitalRead() functions. On the other hand, analog pin

will use analogRead() and analogWrite() functions.

As stated above, the Arduino Mega is built with 16 analog inputs from A0 to A15 and 54

digital inputs from 0 to 53. However, some digital inputs of Arduino Mega have

specialized functions, such as PWM and UART.

Digital pin 2 to 13 and 44 to 46 can be used as PWM. PWM is used to get an analog result

with digital means. This means you can use analogWrite() function within the digital pins.

UART stands for Universal Asynchronous Receiver/Transmitter. UART is used for TTL

serial communication. There are 4 UARTs built in Arduino Mega. Those UARTs consist

of RX pin as the receiver and TX as the transmitter. They are built in the digital pin 0

(RX0), 1 (TX0), 14 (TX3), 15 (RX3), 16 (TX2), 17 (RX2), 18 (TX1), 19 (RX1). Table 2.1

shows additional information about the Arduino Mega 2560.

Table 2.1 Arduino Mega 2560 Specification [2]

Microcontroller ATmega2560

Operation Voltage 5 V

Input Voltage 7-12 V (recommended)

6-20 V (limits)

Digital I/O Pins 54 (of which 15 provide PWM output)

Analog Input Pins 16

DC Current per I/O Pin 40 mA

DC Current for 3.3 V Pin 50 mA

Flash Memory 256 KB of which 8 KB is used by boot loader

SRAM 8 KB

EEPROM 4 KB

Clock Speed 16 MHZ

2.2. Seeed Studio Arduino GPRS Shield V2.0

Arduino comes with the shield which is compatible to Arduino and has many types

depends on the functions. There are motor shield, relay shield, keypad shield and many

more. This project will be using GPRS Shield V2.0 from Seeed Studio. Seeed Studio is one

Page 18: MANUALLY AND REMOTELY CONTROLLED POWER OUTLETS …

President University 6

of the Arduino board suppliers. In Indonesia, you can buy this shield online on

www.geraicerdas.com. Figure 2.2 shows the front and rear layout of the shield.

Figure 2.2 Seeed Studio GPRS Shield v2.0 front and rear

By using this shield, your Arduino can send an SMS to cell phone and dial a phone number

via easy to use AT commands through SIM900. SIM900 is a GSM (Global System for

Mobile communication)/GPRS developed by Shanghai SIMCom Wireless Solutions Ltd. It

can be used in M2M (Machine to Machine) application. It can be controlled via AT

commands (GSM 07.07, 07.05, and SIMCOM enhanced AT Commands).

The Seeed Studio which produces this Arduino GPRS Shield V2.0 has written its

specifications on the web [5]. This GPRS Shield is compatible with standard Arduino and

Arduino Mega. You can choose interface between hardware serial port and software serial

port. It also supports quad band 850/900/1800/1900 MHz. Before using this shield, ensure

your SIM card is unlocked. It also does not come with ESD (Electro Static Discharge)

precautions. You should take special care when handing it in dry weather. The default

setting of this GPRS shield UART is 19200 bps 8-N-1.

Figure 2.3 explains about the interface function of the shield. Software Serial is on the

digital pin D7 and D8 of Arduino meanwhile Hardware Serial is the digital pin D0 and D1.

Serial Port Select is to select which serial port wants to be used, software serial port or

hardware serial port. GPIO, PWM, and ADC of SIM 900 are the pins breakout of GPIO,

PWM, and ADC of SIM900. You can add external antenna for expansion on Antenna

Interface. Power Button is to activate SIM900 manually by pressing the button. However,

you can activate Power Button through software power button in digital pin D9 of the

Arduino.

Page 19: MANUALLY AND REMOTELY CONTROLLED POWER OUTLETS …

President University 7

Figure 2.3 Seeed Studio GPRS Shield v2.0 interface function [5]

Power-on indicator will light on green when the GPRS Shield is on. On the other hand,

Status Indicator will light on red when the SIM900 is working. While the SIM900 is

working, the Net Indicator will light on depends on the network connection.

Some of the pins usage of this arduino shield is listed below in Table 2.2.

Table 2.2 Seeed Studio GPRS Shield Pins Configuration [5]

Pin Usage

D0 RX hardware serial port

D1 TX hardware serial port

D7 RX software serial port

D8 TX software serial port

D9 Software power button for SIM900

VIN External power supply

GND Ground

The GPRS system belongs to 2.5G Cell Phone systems. It gets its name because it refers to

a cell phone generation between the 2G and 3G. Other technologies used in 2.5G systems

are EDGE and CDMA2000. 2.5G cell phone user can use their phone like the usual 2G

system with an addition in accessing the internet via the cell phone [6].

Page 20: MANUALLY AND REMOTELY CONTROLLED POWER OUTLETS …

President University 8

2.3. Mean Well Switch Power Supply S-50-5

Switch power supply is used to supply the Arduino including the shield. This project uses 5

V power supply with maximum output current is 10 A [7]. The input of the power supply

is 220-240 V. There are five pins within this power supply: AC Line, AC Neutral, AC

Ground, DC positive and DC negative. The AC pins: AC Line, AC Neutral, and AC

Ground are connected to the AC cable respectively. However, the DC positive will go to

the Vin pin of the board and the DC negative to the GND pin of the board. Figure 2.4

pictures the power supply.

Figure 2.4 Mean well power supply [7]

2.4. Keypad

Keypad is a device which helps us to type text. It is used in many electronics devices, such

as hand phone, Automatic Teller Machine, digital password lock door, and microwave. It

comes in many types. There are 3x4 matrix keypad, 4x4 matrix keypad, telephone style

keypad and many more. Keypad can be made from many push buttons; however, this

project will be used 3x4 matrix keypad made from plastic membrane. This 3x4 matrix

keypad is cheap and easy to use. It consists of 12 buttons which are numbered from 0 to 9

and character * and # as you can see in Figure 2.5, suitable enough for this project since we

do not need any alphabetic numbers. It has seven pins which connect the entire key in all

rows and columns. You can see the connections for each key if you pull out the sticker in

the back of the keypad. Keypad will help us to type the password to use the outlet. Some

Page 21: MANUALLY AND REMOTELY CONTROLLED POWER OUTLETS …

President University 9

keypad does not include with the data sheet therefore you should find which pin connects

which row and column.

Figure 2.5 3x4 Matrix membrane keypad and its keys connections

2.5. Liquid Crystal Display

Liquid Crystal Display (LCD) as pictured in Figure 2.6 is an electronic component which

displays text or picture depends on how we program it. LCD also comes in various types

and backlight colors (if any). For this project, a 16x2 LCD will be used. 16x2 means that

this LCD has 16 columns and 2 rows. The pin configuration for this 16x2 LCD is shown in

Table 2.3 [4:364-367].

Table 2.3 16x2 LCD Pins Configuration

LCD Pin Function

1 GND or 0 V or Vss

2 +5 V or Vdd

3 Vo or contrast

4 RS – Register Select Signal

5 R/W – Read/Write Select Signal

6 E – Operation (data read/write) enable signal

7 - 14 D0 – D7

15 A or Anode

16 K or Cathode

Page 22: MANUALLY AND REMOTELY CONTROLLED POWER OUTLETS …

President University 10

To use this LCD, we should connect a 10K potentiometer to provide contrast voltage to pin

3 unless you do want to see nothing displayed. A 10K potentiometer will have 3 pins. First

and the third pin should be connected to the LCD pin 1 and 2 while the middle pin is

connected to the pin 3. Try to adjust the pot by turn it until we get the best display.

If the LCD has the backlight connect the LCD pin 15 to +5 V and pin 16 to GND. You

may put resistor between one of those connections.

Figure 2.6 16x2 LCD front and rear

2.6. Light Emitting Diode

Light Emitting Diode or LED is a semiconductor device which gives light. LED has two

leads, the short (cathode) and the long (anode) ones. The color of the light depends on the

elements inside the LED. There is also multicolor LED such as RGB LED which has three

elements which is red, green, and blue. This type of LED will have more than two leads

since it consists of several LEDs in one package. However, this project will use the

common LED which has two leads (see Figure 2.7).

Figure 2.7 LED leads and symbol

The LED will turn on when the anode voltage is more positive than the cathode voltage

(forward voltage) [4:245-248]. For example, a common red LED has a forward voltage of

around 1.8 volts. If the anode voltage is not 1.8 volts more than the cathode voltage, LED

Page 23: MANUALLY AND REMOTELY CONTROLLED POWER OUTLETS …

President University 11

will not produce any light since there is no current flows through the LED. You may need

to limit the current flow through the LED with a resistor.

2.7. Relay

A relay is an electronic component which acts as a switch. It is activated when an electric

current flows through the relay which results in the opening or closing another circuit. A

relay contains a coil which is powered by the AC or DC current. When the applied voltage

or current exceeds the threshold value, the coil activates the armature, which will either

open the closed contacts or close the open contacts. This can happen because the coil

creates a magnetic field which actuates the switch mechanism. A relay magnetically

connects two circuits: control circuit which has control coil and load circuit which has the

switch [8] & [9].

There are several types of relay based on pin distribution and internal configuration, such

as 3-pin relay, 4-pin relay, and 5-pin relay. They are shown in Figure 2.8.

Figure 2.8 Relay based on pin distribution and internal configuration [9]

This final project will use the 5-pin relay. It has 5 terminal pins which are a pair of coil

pins, a common pin, a normally open (NO) pin and a normally closed (NC) pin. When the

relay is activated by the activation voltage, the common pin will break away from contact

with NC pin and makes contact with the NO pin. The common pin will break away from

contact with the NO pin and makes contact again with the NO pin when the relay is

deactivated. Figure 2.9 shows the example of pin configuration of this type of relay. Some

relays have their own specifications and pin configuration. It is recommended to look at

the datasheet for further information.

Page 24: MANUALLY AND REMOTELY CONTROLLED POWER OUTLETS …

President University 12

Figure 2.9 5 pins relay configuration [9]

2.8. Power Outlet

Because this project mainly about outlet, outlet is one of the elements needed. There are

many types of outlet and their holes types around the world, from type A to type M [10].

This project will use common outlet used and sold in Indonesia with the voltage range 220

– 240 Volts AC in 50 Hz frequency.

There are outlets type C, F, and G which are commonly used and sold in Indonesia [10] &

[11]. However, this project will only use the outlet types F, the most common used outlet

in Indonesia. This F-type outlet is commonly called as ―Schuko‖ outlet from the word

"Schutzkontakt", a German word meaning earthed/grounded contact. The Schuko

connection system is symmetrical or unpolarised. It means that the line and neutral are

connected at random, allowing the line and neutral to be reversed. Figure 2.10 shows this

Schuko outlet.

Figure 2.10 Outlet types F (Schuko outlet)

Page 25: MANUALLY AND REMOTELY CONTROLLED POWER OUTLETS …

President University 13

In addition, this outlet is compatible with plug types C, E, and F. Moreover, type C and F

outlet look similar, but F-type outlet has two additional grounded parts at the top and the

bottom of the outlet.

Before working with the power outlet, turn off the electrical current and identify which

cables are Line, Neutral, or Ground. This will help in interfacing the outlet with the relay

later.

2.9. Arduino Integrated Development Environment (IDE) 1.0.5

Arduino IDE 1.0.5 is the software to program the Arduino. It can be downloaded free from

http://arduino.cc/en/main/software. A program in Arduino is called a sketch. You create,

modify, and open the sketch which your Arduino board would do. It is easy-to-use even for

beginners since there are example programs included in the package. Some programs are

simple and some are quite complicated since the programs need some interfacing with

another device or sensors. Figure 2.11 shows the layout of the Arduino IDE 1.0.5.

Programming language of Arduino is quite similar with C or C++. Arduino programming

must contain two classes: setup and loop. The program in setup class will be executed once

you start the board, hence the program in loop class will be executed after the setup class

continuously.

Figure 2.11 Arduino IDE 1.0.5 layout

The Arduino IDE consists of menu toolbar, icon toolbar, script editor, and text console.

Menu toolbar consists of File, Edit, Sketch, Tools, and Help. Icon toolbar consists of

Page 26: MANUALLY AND REMOTELY CONTROLLED POWER OUTLETS …

President University 14

Compile to compile or verify your sketch, Upload to upload your sketch to your board,

New is to create new sketch, Open is to open sketch you saved before, Save is to save your

sketch, Serial Monitor is to open and view serial monitor screen, and Tab Button is to

choose Tab options: New Tab, Rename, Delete, Previous Tab, Next Tab, and show you

which Tab is active. Figure 2.12 shows the location of those toolbars.

Figure 2.12 Arduino IDE 1.0.5 toolbars

Script Editor area is the place where you view, write, or modify your sketch. It supports

common text-editing keys such as copy (Ctrl-C), find (Ctrl-F), cut (Ctrl-X), paste (Ctrl-V),

undo (Ctrl-Z), and even open (Ctrl-O) and save (Ctrl-S) [4:10-13].

Text console area will show you progress of compiling or uploading your sketch. It also

shows you how many bytes your sketch has if you succeed to upload the sketch to the

board or errors in your sketch if it contains any error(s).

Before uploading your sketch, do not forget to choose the board you are using and its serial

port. Connect your board through USB cable, choose the board and its serial port, compile

or verify your sketch, and upload it.

Once you save your sketch, IDE will create a folder with the same name of sketch and save

your sketch to that folder. The name of your sketch is limited. You cannot use some

Page 27: MANUALLY AND REMOTELY CONTROLLED POWER OUTLETS …

President University 15

characters. IDE will change it according to its system. IDE will save your sketch in

extension .ino.

Moreover, by using Arduino IDE, you can add some libraries which are a set of code.

Libraries will help you to simplify a program depends on which library you used and

device you want to interface. It is easier to connect to some devices, sensors, modules by

using additional library. There are many additional libraries out there on the internet. For

information, there are also built-in libraries in Arduino IDE. The additional libraries can be

installed to the your computer and software IDE. Do not forget to include the library on

your sketch if you want to use it.

Page 28: MANUALLY AND REMOTELY CONTROLLED POWER OUTLETS …

President University 16

CHAPTER 3

DESIGN IMPLEMENTATION

3.1. Interfacing Arduino Mega 2560 with LED

The first step in building this final project is interfacing the arduino with the LED with the

reference from Margolis [4:245-248]. The circuit can be seen in Figure 3.1 while the

sketch can be seen in Appendix A.1.

USB

Port

ARDUINO MEGA 2560

1213

GND5V

220 Ω

220 Ω

DIGITAL PIN

Figure 3.1 Interfacing LEDs to Arduino

The anode of LEDs (long lead) is connected to the Arduino Mega digital pin (12 and 13)

while the cathode (short lead) is connected to 220 ohms resistor and then GND pin of the

board. Connect the board to the computer via USB to supply the power. The composition

of this LED will make LED turn on when the digital pin is set HIGH and off when the

digital pin is set OFF. In short, this sketch will make LED turn on for five seconds and then

turn off for one second and turn on again for five seconds and continuously.

The LED functions as active high since it will light on when the pin is set HIGH and light

off when the pin is set LOW. The active-low LED will act in the opposite and in different

circuit. The anode pin is connected to the 5 V pin through resistor while the cathode pin is

connected to the digital pin [4:245-248].

The calculation of the resistor used is shown in the equation (3.1) below.

Page 29: MANUALLY AND REMOTELY CONTROLLED POWER OUTLETS …

President University 17

R = (Vs – Vf) / I (3.1)

The Vs is 5 V from Arduino 5 V pin. The Vf is the forward voltage of the LED, 1.8 V. The

I equals to LED current which is 0.015 A. Therefore the calculation of the resistor is (5 –

1.8) / 0.015, equals to 213 ohms. It is rounded to 220 ohms.

3.2. Interfacing Arduino Mega 2560 with LCD and Keypad

3.2.1. Interfacing Arduino Mega 2560 with LCD

This project will use 16x2 LCD as stated in previous chapter. The configuration of this

LCD is stated in Table 2.3. The sketch to interface Arduino Mega 2560 with LCD will use

LiquidCrystal library included in the package as the standard libraries. With the reference

from Arduino website [12], there are some functions which can be used with the LCD.

The functions which must be stated every time we use an LCD are LiquidCrystal() and

begin(). The LiquidCrystal() function has four syntaxes which can be used. These are:

a. LiquidCrystal lcd (rs, enable, d4, d5, d6, d7)

b. LiquidCrystal lcd (rs, rw, enable, d4, d5, d6, d7)

c. LiquidCrystal lcd (rs, enable, d0, d1, d2, d3, d4, d5, d6, d7)

d. LiquidCrystal lcd (rs, rw, enable, d0, d1, d2, d3, d4, d5, d6, d7)

which lcd is the variable type of the LCD, rs is the number of the Arduino pin connected to

RS pin of the LCD, is the number of Arduino pin connected to RW pin of the LCD, enable

is the Arduino pin connected to E (enable) pin of the LCD, and d0 to d7 are the numbers of

Arduino pins connected to corresponding pins of LCD. Pin d0, d1, d2, and d3 can be

omitted so the LCD will be controlled using four data lines which are d4, d5, d6, and d7.

The begin() will have syntax lcd.begin (cols,rows) which lcd is the variable type of the

LCD, cols is the number of columns in the LCD and rows is the number of rows in the

LCD. 16x2 LCD means the LCD has 16 columns and 2 rows. The number of columns and

rows is started from 0. Therefore, a 16x2 LCD has 16 columns from column 0th

to 15th and

2 rows from 0th

to 1st.

Moreover, do not forget to state ―#include <LiquidCrystal.h>‖ on the top line of your

sketch since you will use the liquid crystal library.

Page 30: MANUALLY AND REMOTELY CONTROLLED POWER OUTLETS …

President University 18

The circuit and sketch in interfacing Arduino Mega 2560 with LCD with a reference from

the module from instructables.com [13] can be seen in Figure 3.2 and Appendix A.2.

USB

Port

ARDUINO

MEGA

2560

25

23

GND

5V

D

I

G

I

T

A

L

P

I

N

29

27

33

31

35

21 43 65 11

LCD

12 1413 15 16

10 K

Figure 3.2 Interfacing LCD to Arduino Mega 2560

After the sketch is uploaded to the board, the LCD will display ―hello, world!‖ in the first

row and a timer in the second row.

3.2.2. Interfacing Arduino Mega 2560 with LCD and Keypad

Before interfacing the board with keypad, the pin configuration of keypad should be

known. Some vendors do not have datasheet within the keypad. Therefore, we should find

ourselves the pin configuration. The module from [13] had written how to find the pin

configuration of a keypad.

The simple way is to look at the back of the keypad (see Figure 2.5). We will see which

keys connected to which pins. Another way is by using multimeter. Set the multimeter to

continuity mode and put the test leads on pin 1 and 2. Press each key until we get

continuity. Make a note for each key and each pin and do this until we get all keys with

corresponding pins. The keypad used in this project has configuration shown in Table 3.1

and Figure 3.3.

Page 31: MANUALLY AND REMOTELY CONTROLLED POWER OUTLETS …

President University 19

Table 3.1 3x4 Keypad Configuration

Key Keypad Pin

1 3 and 7

2 2 and 7

3 1 and 7

4 3 and 6

5 2 and 6

6 1 and 6

7 3 and 5

8 2 and 5

9 1 and 5

* 3 and 4

0 2 and 4

# 1 and 4

Figure 3.3 3x4 keypad configuration

The sketch to interface Arduino Mega 2560 and keypad will use keypad library created by

Mark Stanley and Alexander Brevig [14]. Install the keypad library and state ―#include

<Keypad.h>‖ on the top line of the sketch. The list of function in this library is also stated

on the Arduino website [14]. The constructor of this 3x4 keypad used in the project is:

const byte ROWS = 4; //number of rows of keypad

const byte COLS = 3; //number of columns of keypad

Page 32: MANUALLY AND REMOTELY CONTROLLED POWER OUTLETS …

President University 20

char keys[ROWS][COLS] =

{{'1','2','3'},

{'4','5','6'},

{'7','8','9'},

{'*','0','#'}};

Byte rowPins[ROWS] = {25,24,23,22}; //arduino pins connect to the row pinouts

of the keypad, {row1, row2, row3, row4}

Byte colPins[COLS] = {28,27,26}; // arduino pins connect to the column pinouts of

the keypad, {column1, column2, column3}

Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);

The circuit and sketch for this part are based on Boxall as the reference [15] and can be

seen in Figure 3.4 and Appendix A.3.

3x4 KeypadUSB

Port

ARDUINO

MEGA

2560

25

23

GND

5V

D

I

G

I

T

A

L

P

I

N

29

27

33

31

35

21 43 65 11

LCD

12 1413 15 16

10 K

32

34

D

I

G

I

T

A

L

P

I

N

28

30

24

26

22

21 43 65 7

Figure 3.4 Interfacing LCD and 3x4 keypad to Arduino Mega 2560

Each pin of the keypad is connected to the digital pin of the Arduino. Once the sketch is

uploaded, whenever the key of the keypad is pressed, it will display on the LCD until all

Page 33: MANUALLY AND REMOTELY CONTROLLED POWER OUTLETS …

President University 21

rows and columns of the LCD are filled with the input keys. Then the system will clear the

LCD, delete all the input keys.

Moreover, within this project, the ‗*‘ and ‗#‘ key is changed to ‗←‘ and ‗OK‘.

3.3. Using Arduino Password Library

This project will use password library to create the password system. This library which is

created by Alexander Brevig is suitable for project which needs a password to control or

access. Brevig through the Arduino web [16] explained about all functions which can be

used via password library. Firstly, state ―#include <Password.h>‖ on the top of the sketch.

Create variable password and state the password.

The sketch of this password library trial can be seen in Appendix A.4. It is referred to the

built in examples of password library. Note that the LCD and keypad connection is

referred to Figure 3.4. The sketch will operate the Arduino to display word ―Success‖

when someone inputs the right password and ―Wrong‖ when someone inputs the wrong

password. Press ―*‖ to check the password and ―#‖ to reset the password.

3.4. Interfacing Arduino Mega 2560 with Relay and Outlet

The relay used in this project is 5 pins Takamisawa JS5N-K relay made by Fujitsu. The pin

configuration is shown in Figure 3.5.

Figure 3.5 Takamisawa JS5N-K relay pin configuration [17]

The circuit and sketch to interface Arduino with the relay and outlet can be seen in Figure

3.6 and Appendix A.5 with the reference from several tutorials from [4:300-302] and [18].

Page 34: MANUALLY AND REMOTELY CONTROLLED POWER OUTLETS …

President University 22

The sketch will activate the relay for 1 minute and then inactivate the relay for another

minute and so on. Connect the NO pin of relay to the AC current source and the COM pin

of relay to the LINE cable of the outlet. The idea of this interfacing is to control the LINE

current of the outlet via relay. Therefore, it is important to define which LINE cable is.

USB

Port

ARDUINO

MEGA

2560

GND

5V

DIGITAL

PIN2

1N4004

1 kΩ2N2222

AC

relay

OUTLETL

N

LN

Figure 3.6 Interfacing relay and outlet to Arduino Mega 2560

3.5. Interfacing Arduino Mega 2560 with GPRS Shield

The steps to interface and set up the GPRS Shield have been explained in the Seeed Studio

website [5] and the forum within the webpage [19]. To interface the Arduino Mega with

Seeed Studio GPRS Shield V2.0 via software serial, the RX and TX pin of the shield (D7

and D8) should be connected to TX and RX pin of the board. Arduino Mega 2560 have

several pins which can support change interrupts. They are 10, 11, 12, 13, 50, 51, 52, 53,

62, 63, 64, 65, 66, 67, 68, and 69 [20]. Thus, based on [19], the D7 of the shield is

connected to D10 of the board, and the D8 of the shield is connected to D11 of the board in

order to make the interfacing works. Check whether the board and shield can work well by

uploading the sketch based on [5].

3.5.1. Send an SMS

The sketch on Appendix A.6 shows the demo code to send an SMS to certain number [5].

The connection of the shield and board is equivalent as shown in Figure 3.7.

The shield is activated through digital pin 9. By using the serial monitor, the board and

shield will send an SMS in case of key ‗t‘ of keyboard to a certain number defined in the

sketch.

Page 35: MANUALLY AND REMOTELY CONTROLLED POWER OUTLETS …

President University 23

The AT Commands used in the sketch are:

AT+CMGF

This command is to select the SMS message format [21:98- 99]. The write

command is AT+CMGF=<mode>. The Terminal Adapter sets parameter which

input and output format of the message. The <mode> parameter will be 0 for PDU

mode and 1 for text mode. Therefore, to select the SMS format to text the

command AT+CMGF=1 will be used

AT+CMGS

This command is to send SMS message [21:105-106]. State the phone number

which the SMS will be send to and state your message, end with Ctrl+Z, ASCII

code 26. The writing command this AT command is

AT+CMGS=\‖phone_number\‖, after that input the content of the message and end

the command with ctrl+Z.

USB

Port ARDUINO

MEGA

2560

STACKED

WITH

GPRS

SHIELD

GND

5V

DIGITAL

PIN9

8

11

10

7

Figure 3.7 Interfacing GPRS Shield to Arduino Mega 2560

3.5.2. Control LEDs via SMS

The sketch of this program is on Appendix A.7 with the reference from John Boxall

[22:360-363]. Figure 3.8 shows the board connection with the LEDs. The sketch will

control two LEDs via SMS. The command of the SMS is #axbx with a is the LED 1, b is

the LED 2, and x indicates whether the LED is active (1) or inactive (0). For example, the

command #a1b0 is used to activate LED 1 and inactivate LED 2.

Page 36: MANUALLY AND REMOTELY CONTROLLED POWER OUTLETS …

President University 24

The AT Commands used in the sketch are:

AT+CMGF (as explained in subchapter 3.5.1. Send an SMS)

AT+CNMI

This command is to indicate new SMS message [21:108-110]. The write command

is AT+CNMI=2,2,0,0,0.

AT+CMGD

This command is to delete SMS message [21:97-98]. The command

AT+CMGD=1,4 will delete all messages from preferred message storage including

unread messages.

USB

Port ARDUINO

MEGA

2560

STACKED

WITH

GPRS

SHIELD

GND

5V

DIGITAL

PIN

9

8

11

10

7

220 Ω

220 Ω

13

12

Figure 3.8 Circuit diagram to control LEDS via SMS

After all the implementations above, the components need to be combined in one using a

plastic box. This final project will have two outlets which can be controlled. Therefore, it

needs two LEDs and two relays. Make sure to make hole for LCD, keypad, and outlets

cable.

The final result of this project is discussed in the following chapter.

Page 37: MANUALLY AND REMOTELY CONTROLLED POWER OUTLETS …

President University 25

CHAPTER 4

RESULTS AND DISCUSSIONS

4.1. Results

After the implementation, the components need to be combined into one and put them in a

plastic box. The circuit diagram, flow chart diagram, and source code of this project can be

seen in Appendix B, C, and D. The final result of the project, the new outlet design is

shown in Figure 4.1 and Figure 4.2 below. There is a hole in the right side to insert USB

cable connection to upload sketches if the user wants to change password and phone

number to send the SMS.

Figure 4.1 Final result of the project

Page 38: MANUALLY AND REMOTELY CONTROLLED POWER OUTLETS …

President University 26

Figure 4.2 The layout of the device

There are four states within this device. The first state is when both outlets are off. The

second is when outlet 1 is active and outlet 2 is off. The third is when outlet 1 is off and

outlet 2 is active. And the last, the fourth state is when both outlets are active. Figure 4.3

shows the condition of the four states

Figure 4.3 The four steps within the device

Page 39: MANUALLY AND REMOTELY CONTROLLED POWER OUTLETS …

President University 27

The manual instructions in using this device are listed below.

1. First time this device is turned on, it needs an initializing process for 30 seconds

shown in Figure 4.4.

Figure 4.4 Initializing process

2. Choose which outlets you want to turn on by pressing the key number related to the

outlet.

3. After choosing the outlet, wait until the LCD asks you to input the password then

press OK. The correct password will turn on the outlet. Figure 4.5 shows the LCD

layout when the device is asking for the outlet

Figure 4.5 Enter password

Page 40: MANUALLY AND REMOTELY CONTROLLED POWER OUTLETS …

President University 28

4. To inactivate the outlet press the exit ke (see Figure 4.6) and follow the instruction

displayed on the LCD.

Figure 4.6 Exit key

The remotely instructions via SMS in using this device is listed below.

1. Text an SMS to the device number. The content of the message is the password to

activate the outlet. The outlet is active when there is reply message from the device.

2. To inactivate via SMS, text ―#1‖ for outlet 1 and ―#2‖ for outlet 2.

Figure 4.7 shows the message in the cell phone.

Figure 4.7 Example of sent message (left) and received message (right)

Page 41: MANUALLY AND REMOTELY CONTROLLED POWER OUTLETS …

President University 29

4.2. Discussions

This outlet box is a prototype. To install this box in home, nail the box on the wall and

connect the AC house wiring with the AC cable of the box.

When someone inputs or texts the correct password, the board will set the digital pin of led

and relay of the inactive outlet HIGH. Those will light on the led and activate the relay to

connect the outlet to the AC current. Thus, the AC current will flow through the outlet and

the outlet can be used.

As the outlet is active, someone presses the exit key or texts ―#1‖ or ―#2‖. The action will

set the digital pin of led and relay of the inactive outlet LOW. Those will light off the led

and inactivate the relay to disconnect the outlet to the AC current. Thus, the AC current

will stop flow through the outlet and the outlet cannot be used.

The passwords used consist of 4 digit numbers. The 4 digit numbers as a password is

suitable enough to keep the secrecy to prevent other people reveal the passwords. There

will be around 10,000 4-digit combination numbers which can be made from number 0 to 9

listed on the keypad.

To change the password, the user should connect the Arduino to the Arduino IDE via USB

cable and upload the new sketch with the new password. There is a gap available on the

left side of the box to help the USB connection without opening the box. Figure 4.8 shows

the left view of the box with the gap for the USB connection.

Figure 4.8 The gap for the USB connection

Page 42: MANUALLY AND REMOTELY CONTROLLED POWER OUTLETS …

President University 30

There is around 8.55 seconds delay for this device to receive any SMS message and

activate the outlet. Since it is basically an SMS, this delay depends on how far the device

from the SMS sender and the base station of the SIM Card provider, the weather, and the

network. Figure 4.9 shows the graph of the delay from three different distances.

Figure 4.9 SMS time delay graph

The command message is definitely successfully transmitted and done when there is a

reply message from the device to the phone. If there is only notification that the SMS is

delivered, send the SMS again until the phone receives the reply message.

77.5

88.5

99.5

Del

ay (

s)

Distance (m)

SMS Time Delay

Delay (s) Average (s)

Page 43: MANUALLY AND REMOTELY CONTROLLED POWER OUTLETS …

President University 31

CHAPTER 5

CONCLUSIONS AND RECOMMENDATIONS

5.1. Conclusions

The final project has fulfilled the objective which is to create a new outlet design. The new

outlet design comes up in the box consist of two power outlets. They can be activated

manually and remotely. The manual activation of the outlet goes by pressing the correct

password on the keypad. Another function of the outlets is to be controlled remotely by an

SMS. The user sends an SMS containing the password to the device.

The outlets are the F-type outlet which is commonly used in Indonesia and already

installed in many houses.

5.2. Recommendations

There are some recommendations related to the development of this project in the future.

One of them is to control the outlet via Internet. The user log on to certain website

designed for the control of the outlet.

An automatic turn off system can also be added within the project. Whenever the electric

plug is pulled off from the outlet, the outlet will automatically turn off.

Create an automatic system to close the holes of the outlet so nothing can go through the

holes of the outlet. The holes will be opened if the user input the correct password.

Moreover, control the outlet via smartphone application. Nowadays, smartphone is used by

many people from various and different background. Smartphone has become a thing a

person should have in this modern era. Because of that, a smartphone application to control

the outlet should be developed.

Lastly, a camera can be also added to the project. The user can see live who come near the

outlet and activate the outlet.

Page 44: MANUALLY AND REMOTELY CONTROLLED POWER OUTLETS …

President University 32

REFERENCES

[1] B. Andrew, ―Automatic power on/off control system using sms and microcontroller,‖

BSEE thesis, Faculty of Engineering, President Univ., Bekasi, Indonesia, 2013.

[2] Arduino Mega 2560, Mantech Electronics (Pty) Ltd., Johannesburg, South Africa.

[3] Arduino Mega 2560, Microelectrónicos, Bogota, Colombia.

[4] M. Margolis and N. Weldin. Arduino Cookbook, 2nd

Edition. Sebastopol, CA:

O‘Reilly Media, Inc., 2011.

[5] ―GPRS Shield V2.0.‖ Available:

http://www.seeedstudio.com/wiki/GPRS_Shield_V2.0, Feb. 11, 2014 [May 17,

2014].

[6] L. E. Frenzel. Principles of Electronic Communications Systems, 3rd

Edition. New

York, NY: McGraw-Hill, 2008.

[7] Mean Well 50W Single Output Switching Power Supply S-50 Series, Mean Well

Enterprises Co., Ltd., New Taipei City, Taiwan, 2011.

[8] Relay, National Plastic Heater Sensor & Control Inc., Ontario, Canada.

[9] Understanding Relays, Autoshop 101, San Bruno, CA.

[10] Electricity Around the World, Travelstories, Athens, Greece, 2011.

[11] Travelers Guide to Electrical Power Around the World, Knoble Arts, Melbourne,

Australia.

[12] J. Hernandez. ―Arduino's LiquidCrystal Library with SPI.‖ Available:

http://arduino.cc/en/Reference/LiquidCrystal, [Apr. 3, 2014].

[13] Password Access with Arduino, Instructables, San Francisco, CA, 2011.

[14] M. Stanley. ―Keypad Library for Arduino.‖ Available:

http://playground.arduino.cc/code/Keypad, Mar. 22, 2014 [Apr. 3, 2014].

[15] J. Boxall. ―Arduino Tutorials – Chapter 42 – Numeric Keypads.‖ Available:

http://tronixstuff.com/2013/12/16/arduino-tutorials-chapter-42-numeric-keypads/,

Dec. 16, 2013 [Feb. 4, 2014]

[16] N. Gammon. ―Password Library for Arduino.‖ Available:

http://playground.arduino.cc/Code/Password, Nov. 16, 2013 [Apr. 3, 2014].

[17] Power Relay 1 Pole - 8A Medium Load Control JS Series, Fujitsu Components

Europe B.V., Hoofddorp, Netherlands, 2013.

Page 45: MANUALLY AND REMOTELY CONTROLLED POWER OUTLETS …

President University 33

[18] Connecting a 12 V Relay to Arduino, Instructables, San Francisco, CA, 2009.

[19] “Problem with Arduino and GPRS shield v2.‖ Available:

http://www.seeedstudio.com/forum/viewtopic.php?f=10&t=4405, Apr. 4, 2013 [Jun.

5, 2014].

[20] ―Software Serial Example.‖ Available: http://arduino.cc/en/Reference/softwareSerial,

[Jun. 12, 2014].

[21] SIM900 AT Command Manual V1.03, SIMCom Wireless Solutions Ltd., Shanghai,

China, 2010.

[22] J. Boxall. Arduino Workshop. San Francisco, CA: No Starch Press, Inc., 2013.

Page 46: MANUALLY AND REMOTELY CONTROLLED POWER OUTLETS …

President University 34

APPENDIX A

SKETCHES OF DESIGN IMPLEMENTATION

A.1 Sketch of Interfacing Arduino Mega 2560 with LEDs

const int led1=12; //declare LED pin

const int led2=13;

void setup ()

{

pinMode(led1,OUTPUT);//set the led as the output

pinMode(led2,OUTPUT);

}

void loop ()

{

digitalWrite(led1,HIGH); //led1 lights on

delay (5000);//delay for 5000ms

digitalWrite(led2,HIGH); //led2 lights on

delay(1000);

digitalWrite(led1,LOW); //led1 lights off

delay (5000);

Page 47: MANUALLY AND REMOTELY CONTROLLED POWER OUTLETS …

President University 35

digitalWrite(led2,LOW); //led2 lights off

}

A.2 Sketch of Interfacing Arduino Mega 2560 with LCD

#include <LiquidCrystal.h>

LiquidCrystal lcd(23,25,27,29,31,33,35);// initialize the library with the numbers of the

interface pins

void setup() {

// set up the LCD's number of columns and rows:

lcd.begin(16, 2);

// Print a message to the LCD.

lcd.print("hello, world!");

}

void loop() {

// set the cursor to column 0, line 1

// (note: line 1 is the second row, since counting begins with 0):

lcd.setCursor(0, 1);

// print the number of seconds since reset:

lcd.print(millis()/1000);

}

Page 48: MANUALLY AND REMOTELY CONTROLLED POWER OUTLETS …

President University 36

A.3 Sketch of Interfacing Arduino Mega 2560 with LCD and 3x4 Keypad

#include <Keypad.h>

#include <LiquidCrystal.h>

LiquidCrystal lcd(23,25,27,29,31,33,35);

//LiquidCrystal lcd(2,3,4,9,10,11,12); // set the LCD address to 0x27 for a 16 chars and 2

line display

// keypad type definition

const byte ROWS = 4; //four rows

const byte COLS = 3; //three columns

char keys[ROWS][COLS] =

{{'1','2','3'},

{'4','5','6'},

{'7','8','9'},

{'*','0','#'}};

byte rowPins[ROWS] = {34,32,30,28}; //connect to the row pinouts of the keypad

byte colPins[COLS] = {26,24,22}; // connect to the column pinouts of the keypad

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

int count=0;

void setup()

Page 49: MANUALLY AND REMOTELY CONTROLLED POWER OUTLETS …

President University 37

{

lcd.begin(16,2);//set up the LCD's number of columns and rows

}

void loop()

{

char key = keypad.getKey();

if (key != NO_KEY)

{

lcd.print(key);

count++;

if(count==17)

{

lcd.setCursor(0,1);

lcd.print(key);

count++;

}

if (count==34)

{

lcd.clear();

count=0;

Page 50: MANUALLY AND REMOTELY CONTROLLED POWER OUTLETS …

President University 38

}

}

}

A.4 Sketch of Using Password Library

#include <Password.h>

#include <Keypad.h>

#include <LiquidCrystal.h>

Password password = Password( "1234" );

// Define the Keymap

const byte ROWS = 4; // Four rows

const byte COLS = 3; // columns

char keys[ROWS][COLS] = {

{'1','2','3'},

{'4','5','6'},

{'7','8','9'},

{'*','0','#'}

};

byte rowPins[ROWS] = { 34,32,30,28 };

byte colPins[COLS] = { 26,24,22 };

Page 51: MANUALLY AND REMOTELY CONTROLLED POWER OUTLETS …

President University 39

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

LiquidCrystal lcd (23,25,27,29,31,33,35);

void setup(){

Serial.begin(9600);

lcd.begin(16,2);

keypad.addEventListener(keypadEvent); //add an event listener for this keypad

}

void loop(){

keypad.getKey();

}

//take care of some special events

void keypadEvent(KeypadEvent eKey){

switch (keypad.getState()){

case PRESSED:

lcd.print(eKey);

switch (eKey){

case '*': checkPassword(); break;

Page 52: MANUALLY AND REMOTELY CONTROLLED POWER OUTLETS …

President University 40

case '#': password.reset(); break;

default: password.append(eKey);

}

}

}

void checkPassword(){

if (password.evaluate()){

lcd.println("Success");

delay(5000);

lcd.clear();

//Add code to run if it works

}else{

lcd.println("Wrong");

delay(5000);

lcd.clear();

//add code to run if it did not work

}

}

A.5 Sketch of Interfacing Arduino Mega 2560 with Relay and Outlet

int Relay = 2;

Page 53: MANUALLY AND REMOTELY CONTROLLED POWER OUTLETS …

President University 41

void setup() {

pinMode(Relay, OUTPUT);

}

void loop() {

digitalWrite(Relay,HIGH);

delay(60000);

digitalWrite(Relay,LOW);

delay(60000);

}

A.6 Sketch of Sending an SMS

#include <SoftwareSerial.h>

#include <String.h>

SoftwareSerial mySerial(10,11);

void setup()

{

digitalWrite(9,HIGH);

mySerial.begin(19200); // the GPRS baud rate

Page 54: MANUALLY AND REMOTELY CONTROLLED POWER OUTLETS …

President University 42

Serial.begin(19200); // the GPRS baud rate

delay(500);

}

void loop()

{

//after start up the program, you can using terminal to connect the serial of gprs shield,

//if you input 't' in the terminal, the program will execute SendTextMessage(), it will

show how to send a sms message,

if (Serial.available())

switch(Serial.read())

{

case 't':

SendTextMessage();

break;

}

if (mySerial.available())

Serial.write(mySerial.read());

}

///SendTextMessage()

Page 55: MANUALLY AND REMOTELY CONTROLLED POWER OUTLETS …

President University 43

///this function is to send a sms message

void SendTextMessage()

{

mySerial.print("AT+CMGF=1\r"); //Because we want to send the SMS in text mode

delay(100);

mySerial.println("AT + CMGS = \"087779150537\"");//send sms message

delay(100);

mySerial.println("How are you ?");//the content of the message

delay(100);

mySerial.println((char)26);//the ASCII code of the ctrl+z is 26

delay(100);

mySerial.println();

}

A.7 Sketch of Controlling LEDs via SMS

#include <SoftwareSerial.h>

char inchar; // Will hold the incoming character from the GSM shield

SoftwareSerial SIM900(10, 11);

int led1 = 12;

int led2 = 13;

Page 56: MANUALLY AND REMOTELY CONTROLLED POWER OUTLETS …

President University 44

void setup()

{

Serial.begin(19200);

// set up the digital pins to control

pinMode(led1, OUTPUT);

pinMode(led2, OUTPUT);

digitalWrite(led1, LOW);

digitalWrite(led2, LOW);

// wake up the GSM shield

SIM900power();

SIM900.begin(19200);

delay(2000); // give time to log on to network.

SIM900.print("AT+CMGF=1\r"); // set SMS mode to text

delay(100);AT

SIM900.print("AT+CNMI=2,2,0,0,0\r");

delay(100);

Serial.println("Ready...");

}

void SIM900power()

// software equivalent of pressing the GSM shield "power" button

Page 57: MANUALLY AND REMOTELY CONTROLLED POWER OUTLETS …

President University 45

{

digitalWrite(9, HIGH);

delay(1000);

}

void loop()

{

//If a character comes in from the cellular module...

if(SIM900.available() >0)

{

inchar=SIM900.read();

if (inchar=='#')

{

delay(10);

inchar=SIM900.read();

if (inchar=='a')

{

delay(10);

inchar=SIM900.read();

if (inchar=='0')

{

Page 58: MANUALLY AND REMOTELY CONTROLLED POWER OUTLETS …

President University 46

digitalWrite(led1, LOW);

}

else if (inchar=='1')

{

digitalWrite(led1, HIGH);

}

delay(10);

inchar=SIM900.read();

if (inchar=='b')

{

inchar=SIM900.read();

if (inchar=='0')

{

digitalWrite(led2, LOW);

}

else if (inchar=='1')

{

digitalWrite(led2, HIGH);

}

delay(10);

SIM900.println("AT+CMGD=1,4"); // delete all SMS

Page 59: MANUALLY AND REMOTELY CONTROLLED POWER OUTLETS …

President University 47

}

}

}

}

}

Page 60: MANUALLY AND REMOTELY CONTROLLED POWER OUTLETS …

President University 48

APPENDIX B

CIRCUIT DIAGRAM

3x4 K

eypad

US

B

Po

rt

AR

DU

INO

ME

GA

2560

ST

AC

KE

D

WIT

H

GP

RS

SH

IEL

D25

23

GN

D

5V

D I G I T A L P I N

29

27

33

31

35

21

43

65

11

LC

D

12

14

13

15

16

10

K32

34

D I G I T A L P I N

28

30

24

26

22

21

43

65

7

22

0 Ω

22

0 Ω

5498 11

107

2

1N

40

04

1 k

Ω2N

22

22

AC

rela

y

OU

TL

ET

1

1N

40

04

1 k

Ω2N

22

22

rela

y

OU

TL

ET

2

3 Vin

Pow

er S

upply

AC

LV

+A

C

NV

-

LN

L

N

L

N

Page 61: MANUALLY AND REMOTELY CONTROLLED POWER OUTLETS …

President University 49

APPENDIX C

FLOW CHART DIAGRAM

Y

NAny sms

received?

Check the content of

the SMS

Which

content?

A

Start control via

SMS

Outlet 2

Active

Outlet 1

Active

Outlet 2

Inactive

Outlet 1

Inactive

Password Outlet 1 Password Outlet 2 #1 #2

Send SMS notification

End of control

via SMS

START

Initialization

(Turn on the GPRS and set

up the network)

Control the

outlet

manually?

END

Start

control via

SMS

Start

control

manually

A

N

Y

B

Page 62: MANUALLY AND REMOTELY CONTROLLED POWER OUTLETS …

President University 50

B

Password

correct?

Password

correct?

Input

password 2

Start manual

control

Y

Y

N

Input

password 1

Which

activity?

End of manual

control

Press 1 Press 2

Outlet

already

active?

Outlet

already

active?

Press ← Press ←

Press OKPress OK

Inactivate

outlet 1?

Inactivate

outlet 2?

Press OKPress OK

Outlet 2

Active

Outlet 1

Active

Outlet 2

Inactive

Outlet 1

Inactive

Inactivate outlet 1Activate outlet 2Activate outlet 1 Inactivate outlet 2

Y

N

Y

N

Y

N

Y

NN

Page 63: MANUALLY AND REMOTELY CONTROLLED POWER OUTLETS …

President University 51

APPENDIX D

SOURCE CODE

#include <Password.h>

#include <Keypad.h>

#include <LiquidCrystal.h>

#include <SoftwareSerial.h>

const int led1 = 4;

const int led2 = 5;

const int relay1 = 2;

const int relay2 = 3;

char password_1[]="0119";

char password_2[]="1714";

Password password1 = Password( password_1 );

Password password2 = Password( password_2 );

const byte ROWS = 4; // Four rows

Page 64: MANUALLY AND REMOTELY CONTROLLED POWER OUTLETS …

President University 52

const byte COLS = 3; // columns

// Define the Keymap

char keys[ROWS][COLS] = {

{'1','2','3'},

{'4','5','6'},

{'7','8','9'},

{'exit','0','ok'}

};

byte rowPins[ROWS] = { 34,32,30,28 };// Connect keypad ROW0, ROW1, ROW2 and

ROW3 to these Arduino pins.

byte colPins[COLS] = { 26,24,22 };// Connect keypad COL0, COL1 and COL2 to these

Arduino pins.

// Create the Keypad

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

int count=0;

LiquidCrystal lcd(23,25,27,29,31,33,35);

Page 65: MANUALLY AND REMOTELY CONTROLLED POWER OUTLETS …

President University 53

SoftwareSerial SIM900(10, 11);

char inchar;

char phoneno[] ="087779150537";

String smscontent;

void setup(){

Serial.begin(19200);

pinMode(relay1,OUTPUT);

pinMode(relay2,OUTPUT);

pinMode(led1,OUTPUT);

pinMode(led2,OUTPUT);

lcd.begin(16,2);

lcd.print("Initializing....");

SIM900power();

lcd.clear();

firststate();

}

void loop(){

keypad.getKey();

sms();

Page 66: MANUALLY AND REMOTELY CONTROLLED POWER OUTLETS …

President University 54

}

void SIM900power(){

digitalWrite(9,HIGH);

delay(100);

SIM900.begin(19200);

delay(30000); // give time to log on to network.

SIM900.print("AT+CMGF=1\r"); // set SMS mode to text

delay(100);

SIM900.print("AT+CNMI=2,2,0,0,0\r");

delay(100);

}

void firststate(){

lcd.print("OUTLET 1 PRESS 1");

lcd.setCursor(0,1);

lcd.println("OUTLET 2 PRESS 2");

keypad.addEventListener(keypad_stateselection);

}

void keypad_stateselection(KeypadEvent eKey){

Page 67: MANUALLY AND REMOTELY CONTROLLED POWER OUTLETS …

President University 55

switch (keypad.getState()){

case PRESSED:

lcd.clear();

delay(100);

lcd.print(eKey);

lcd.setCursor(0,1);

switch (eKey){

case '1':

//check first whether the outlet is active or not

if (digitalRead(relay1) == HIGH && digitalRead(led1)==HIGH){

lcd.clear();

delay(200);

lcd.print("OUTLET 1 IS");

lcd.setCursor(0,1);

lcd.print(" ALREADY ACTIVE");

delay(1000);

checkstate();

}

else{

lcd.print("OUTLET 1");

delay(1000);

Page 68: MANUALLY AND REMOTELY CONTROLLED POWER OUTLETS …

President University 56

lcd.clear();

outlet1();

}

break;

case '2':

//check first whether the outlet is active or not

if (digitalRead(relay2) == HIGH && digitalRead(led2)==HIGH ){

lcd.clear();

delay(200);

lcd.print("OUTLET 2 IS");

lcd.setCursor(0,1);

lcd.print(" ALREADY ACTIVE");

delay(1000);

checkstate();

}

else{

lcd.print("OUTLET 2");

delay(1000);

lcd.clear();

outlet2();

}

Page 69: MANUALLY AND REMOTELY CONTROLLED POWER OUTLETS …

President University 57

break;

case 'exit':

exitstate();

break;

default:

delay(500);

checkstate();

}

}

}

void outlet1(){

lcd.print("----OUTLET 1----");

delay(1000);

lcd.clear();

lcd.print("ENTER PASSWORD: ");

delay(100);

lcd.setCursor(2,1);

keypad.addEventListener(keypad_outlet1);

}

Page 70: MANUALLY AND REMOTELY CONTROLLED POWER OUTLETS …

President University 58

void keypad_outlet1(KeypadEvent eKey){

lcd.cursor();

switch (keypad.getState()){

case PRESSED:

lcd.print('*');

switch (eKey){

case 'ok':

lcd.clear();

delay(500);

checkpassword1();

break;

case 'exit':

lcd.clear();

delay(100);

checkstate();

break;

default:

password1.append(eKey);

}

}

}

Page 71: MANUALLY AND REMOTELY CONTROLLED POWER OUTLETS …

President University 59

void checkpassword1(){

if (password1.evaluate()){

digitalWrite(led1,HIGH);

digitalWrite(relay1,HIGH);

lcd.print("----OUTLET 1----");

lcd.setCursor(0,1);

lcd.print(" ACTIVATED! ");

delay(500);

password1.reset();

checkstate();

}

else{

lcd.print("INVALID PASSWORD");

delay(1500);

password1.reset();

checkstate();

}

}

void outlet2(){

Page 72: MANUALLY AND REMOTELY CONTROLLED POWER OUTLETS …

President University 60

lcd.print("----OUTLET 2----");

delay(1000);

lcd.clear();

lcd.print("ENTER PASSWORD: ");

delay(100);

lcd.setCursor(2,1);

keypad.addEventListener(keypad_outlet2);

}

void keypad_outlet2(KeypadEvent eKey){

lcd.cursor();

switch (keypad.getState()){

case PRESSED:

lcd.print('*');

switch (eKey){

case 'ok':

lcd.clear();

delay(500);

checkpassword2();

break;

case 'exit':

Page 73: MANUALLY AND REMOTELY CONTROLLED POWER OUTLETS …

President University 61

lcd.clear();

delay(100);

checkstate();

default:

password2.append(eKey);

}

}

}

void checkpassword2(){

if (password2.evaluate()){

digitalWrite(led2,HIGH);

digitalWrite(relay2,HIGH);

lcd.print("----OUTLET 2----");

lcd.setCursor(0,1);

lcd.print(" ACTIVATED! ");

delay(500);

password2.reset();

checkstate();

}

else{

Page 74: MANUALLY AND REMOTELY CONTROLLED POWER OUTLETS …

President University 62

lcd.print("INVALID PASSWORD");

delay(1500);

password2.reset();

checkstate();

}

}

void checkstate(){

lcd.noCursor();

lcd.clear();

if ((digitalRead(relay1) == LOW) && (digitalRead(led1)== LOW) &&

(digitalRead(relay2) == LOW) && (digitalRead(led2) == LOW)){

firststate();

}

else if ((digitalRead(relay1) == HIGH) && (digitalRead(led1) == HIGH) &&

(digitalRead(relay2) == LOW) && (digitalRead(led2) == LOW)){

secondstate();

}

else if ((digitalRead(relay1) == LOW) && (digitalRead(led1) == LOW) &&

(digitalRead(relay2) == HIGH) && (digitalRead(led2) == HIGH)){

thirdstate();

}

else {

Page 75: MANUALLY AND REMOTELY CONTROLLED POWER OUTLETS …

President University 63

fourthstate();

}

}

void secondstate(){

lcd.print("OUTLET 1: ACTIVE");

lcd.setCursor(0,1);

lcd.print("OUTLET 2 PRESS 2");

keypad.addEventListener(keypad_stateselection);

}

void thirdstate(){

lcd.print("OUTLET 1 PRESS 1");

lcd.setCursor(0,1);

lcd.print("OUTLET 2: ACTIVE");

keypad.addEventListener(keypad_stateselection);

}

void fourthstate(){

lcd.print("OUTLET 1: ACTIVE");

lcd.setCursor(0,1);

Page 76: MANUALLY AND REMOTELY CONTROLLED POWER OUTLETS …

President University 64

lcd.print("OUTLET 2: ACTIVE");

keypad.addEventListener(keypad_stateselection);

}

void exitstate(){

if ((digitalRead(relay1) == HIGH) && (digitalRead(led1) == HIGH) &&

(digitalRead(relay2) == LOW) && (digitalRead(led2) == LOW)){

exit_secondstate();

}

else if ((digitalRead(relay1) == LOW) && (digitalRead(led1) == LOW) &&

(digitalRead(relay2) == HIGH) && (digitalRead(led2) == HIGH)){

exit_thirdstate();

}

else if ((digitalRead(relay1) == HIGH) && (digitalRead(led1) == HIGH) &&

(digitalRead(relay2) == HIGH) && (digitalRead(led2) == HIGH)){

exit_fourthstate();

}

else {

checkstate();

}

}

void exit_secondstate(){

Page 77: MANUALLY AND REMOTELY CONTROLLED POWER OUTLETS …

President University 65

lcd.clear();

lcd.print(" INACTIVATE ");

lcd.setCursor(0,1);

lcd.print(" OUTLET 1 ? ");

keypad.addEventListener(keypad_exitsecondstate);

}

void keypad_exitsecondstate(KeypadEvent eKey){

switch(keypad.getState()){

case PRESSED:

switch(eKey){

case 'ok':

digitalWrite(relay1,LOW);

digitalWrite(led1, LOW);

lcd.clear();

delay(500);

lcd.print("----OUTLET 1----");

lcd.setCursor(0,1);

lcd.print(" INACTIVATED! ");

delay(1500);

checkstate();

Page 78: MANUALLY AND REMOTELY CONTROLLED POWER OUTLETS …

President University 66

break;

default:

checkstate();

}

}

}

void exit_thirdstate(){

lcd.clear();

lcd.print(" INACTIVATE ");

lcd.setCursor(0,1);

lcd.print(" OUTLET 2 ? ");

keypad.addEventListener(keypad_exitthirdstate);

}

void keypad_exitthirdstate(KeypadEvent eKey){

switch(keypad.getState()){

case PRESSED:

switch(eKey){

case 'ok':

digitalWrite(relay2,LOW);

Page 79: MANUALLY AND REMOTELY CONTROLLED POWER OUTLETS …

President University 67

digitalWrite(led2, LOW);

lcd.clear();

delay(1500);

lcd.print("----OUTLET 2----");

lcd.setCursor(0,1);

lcd.print(" INACTIVATED! ");

delay(500);

checkstate();

break;

default:

checkstate();

}

}

}

void exit_fourthstate(){

lcd.clear();

lcd.print("---PRESS 1 TO INACTIVATE OUTLET 1");

lcd.setCursor(0,1);

lcd.print("----PRESS 2 TO INACTIVATE OUTLET 2");

//delay(500);

Page 80: MANUALLY AND REMOTELY CONTROLLED POWER OUTLETS …

President University 68

for(int positioncursor=0;positioncursor<18;positioncursor++){

lcd.scrollDisplayLeft();

delay(1000);

}

lcd.clear();

lcd.print("Your choice: ");

keypad.addEventListener(keypad_exitfourthstate);

}

void keypad_exitfourthstate(KeypadEvent eKey){

switch(keypad.getState()){

case PRESSED:

lcd.print(eKey);

switch (eKey){

case '1':

lcd.clear();

exit_secondstate();

break;

case '2':

lcd.clear();

exit_thirdstate();

Page 81: MANUALLY AND REMOTELY CONTROLLED POWER OUTLETS …

President University 69

default:

checkstate();

}

}

}

void sms(){

//If a character comes in from the cellular module...

if(SIM900.available()>0){

inchar=SIM900.read();

if(inchar==password_1[0]){

inchar=SIM900.read();

if(inchar==password_1[1]){

inchar=SIM900.read();

if(inchar==password_1[2]){

inchar=SIM900.read();

if(inchar==password_1[3]){

digitalWrite(relay1,HIGH);

digitalWrite(led1,HIGH);

Page 82: MANUALLY AND REMOTELY CONTROLLED POWER OUTLETS …

President University 70

SIM900.println("AT+CMGD=1,4");

delay(10);

sendsms();

delay(10);

checkstate();

}

}

}

}

else if(inchar==password_2[0]){

inchar=SIM900.read();

if(inchar==password_2[1]){

inchar=SIM900.read();

if(inchar==password_2[2]){

inchar=SIM900.read();

if(inchar==password_2[3]){

digitalWrite(relay2,HIGH);

digitalWrite(led2,HIGH);

SIM900.println("AT+CMGD=1,4");

delay(10);

Page 83: MANUALLY AND REMOTELY CONTROLLED POWER OUTLETS …

President University 71

sendsms();

delay(10);

checkstate();

}

}

}

}

else if(inchar=='#'){

inchar=SIM900.read();

if(inchar=='1'){

digitalWrite(relay1,LOW);

digitalWrite(led1,LOW);

SIM900.println("AT+CMGD=1,4");

delay(10);

sendsms();

delay(10);

checkstate();

}

else if(inchar=='2'){

digitalWrite(relay2,LOW);

Page 84: MANUALLY AND REMOTELY CONTROLLED POWER OUTLETS …

President University 72

digitalWrite(led2,LOW);

SIM900.println("AT+CMGD=1,4");

delay(10);

sendsms();

delay(10);

checkstate();

}

}

else if(inchar=='c'){

inchar=SIM900.read();

if(inchar=='h'){

inchar=SIM900.read();

if(inchar=='e'){

inchar=SIM900.read();

if (inchar=='c'){

inchar=SIM900.read();

if(inchar=='k'){

SIM900.println("AT+CMGD=1,4");

delay(10);

sendsms();

Page 85: MANUALLY AND REMOTELY CONTROLLED POWER OUTLETS …

President University 73

delay(10);

checkstate();

}

}

}

}

}

}

}

void sendsms(){

if ((digitalRead(relay1) == HIGH) && (digitalRead(led1) == HIGH) &&

(digitalRead(relay2) == HIGH) && (digitalRead(led2) == HIGH)){

smscontent = "Both outlets are ACTIVE.";

}

else if((digitalRead(relay1) == HIGH) && (digitalRead(led1) == HIGH) &&

(digitalRead(relay2) == LOW) && (digitalRead(led2) == LOW)){

smscontent = "Outlet 1: ACTIVE. Outlet 2: OFF.";

}

else if((digitalRead(relay1) == LOW) && (digitalRead(led1) == LOW) &&

(digitalRead(relay2) == LOW) && (digitalRead(led2) == LOW)){

smscontent = "Both outlets are OFF.";

}

Page 86: MANUALLY AND REMOTELY CONTROLLED POWER OUTLETS …

President University 74

else if((digitalRead(relay1) == LOW) && (digitalRead(led1) == LOW) &&

(digitalRead(relay2) == HIGH) && (digitalRead(led2) == HIGH)){

smscontent = "Outlet 1: OFF. Outlet 2: ACTIVE.";

}

SIM900.print("AT+CMGF=1\r"); //Because we want to send the SMS in text mode

delay(100);

SIM900.print("AT + CMGS = \"");

SIM900.print(phoneno);

SIM900.println("\"");//send sms message

delay(100);

SIM900.println(smscontent);//the content of the message

delay(100);

SIM900.println((char)26);//the ASCII code of the ctrl+z is 26

delay(100);

SIM900.println();

}