You are on page 1of 14

Room Monitoring via Web

Jessel Serrano

Final Draft
27 November 2013

CNT 4104 Software Project in Computer Networks


Instructor: Dr. Janusz Zalewski
Computer Science & Software Engineering Programs
Florida Gulf Coast University
Ft. Myers, FL 33965
2

1. Introduction
Security is becoming an increasing issue with the progress of technology, but at the same
time technology contributes to the progress of security. The pyroelectric sensor is a piece of
technology that utilizes motion to detect human presence. They are inexpensive, consume low
power and are efficient. This is because the sensor detects changes in low-level radiation,
producing an output of high or low. It is also known as the Passive Infrared sensor (PIR) (Figure
1).

Figure 1: HC-SR501 Human Sensor Module Pyroelectric Infrared

With the PIR sensor, it is possible to detect and monitor when a human (or something
that emits enough radiation) enters or leaves a room. However, when monitoring the data, one’s
presence may skew the data from the PIR sensor. This project involves remote viewing of the
room by sending the data through the Web, thereby allowing a controlled monitoring of the
room.
This will be done using an Arduino Uno microcontroller, an Arduino Ethernet Shield,
and a Human Sensor Module Pyroelectric Infrared. By having the Arduino become its own web
server through the use of the Ethernet Shield, the microcontroller board can read the signals
given off by the PIR sensor, upload them to the Internet and be accessed by a remote client
computer. This client computer will read the signal from the PIR sensor and be able to tell when
someone enters or leaves the room.
3

2. Definition of the Problem


This project involves the creation of a room monitoring web server. This will be
accomplished by using an Arduino Uno Microcontroller in addition to an Arduino Ethernet
Shield in order to host the webserver (Figure 2).

Figure 2: Arduino Uno Microcontroller Board

The shield simply attaches to the Arduino Uno by placing it on top of the board (Figure 3). Then,
an Arduino Uno can be programmed to become a web server, allowing other computers to access
it remotely by entering the Uno’s IP address.

Figure 3: Arduino Uno & Ethernet Shield


4

Once the web server is running, a PIR sensor can be attached to the Arduino module in
order to detect the presence of humans in a room. This PIR sensor would have to be connected
via wires and resistors using a breadboard, and programmed so as to output a signal to the
Arduino every time motion is detected via infrared. The Arduino must then be programmed to
read the change in the output of the sensor in order to interpret movement. This interpretation
will then be accessed via a client that goes through the Internet and connects directly to the
Arduino module using the Arduino’s IP address. The Arduino will be connected to the Internet
via an Ethernet cable connected to a router, which connects to the Internet from there (Figure 4).

Router

PIR + Arduino
Server

Client

Figure 4: Diagram of Networking between Arduino & Client


5

Once the web server is set up and the PIR sensor is outputting data, the client will be able
to see if there is someone in the room where the PIR sensor is located without being in the room
itself. However, in order to access that data remotely, the router in which the Arduino Ethernet
shield connects to will need to have a port forwarded (whatever port is arbitrarily assigned in the
code). Once the port is forwarded and information can flow freely from the router to the Internet,
a client can easily surf to the Arduino server and see a simple interface that shows if the room
contains a moving human presence or not.
6

3. Design Solution
In order for the room monitoring web server to function, a coalescence of both hardware
and software will need to work in unison.
3.1 Hardware
The hardware consists of:
1. An Arduino Uno Microcontroller,
2. An Arduino Ethernet Shield,
3. A Pyroelectric Sensor (PIR),
4. A Client Computer.
The Uno Microcontroller and Ethernet Shield both constitute the computing and processing part
of the project. It reads a signal emitted by the PIR sensor through direct circuitry. This project
utilizes the HC-SR501 Human Sensor Module Pyroelectric (Figure 5). There are three pins on
the PIR sensor: voltage (a), digital out (b), and ground (c). For this project, the PIR sensor’s
digital out pin will be connected to PIN2, which is a digital PIN that reads a signal of 1 or 0. The
voltage pin and the ground pin will be connected to the 5V and GND pin slots, respectively. A
diagram of the PIN setup can be seen in Figure 6.
The PIR sensor is, by default, always in a HIGH state. When movement is detected, the
sensor sends out a LOW signal. The Arduino will process that signal and interpret the results. The
results will then be hosted on the web using the Ethernet Shield’s computing capabilities and, as
such, can be accessed remotely by the client computer. The web page will be programmed using
HTML, which will be discussed in the Software section below.

Figure 5: HC-SR501 Figure 6: PIN Connections


7

3.2 Software
The software portion of this project is limited only to the program that runs the whole
project. This one program loops infinitely while it constantly checks for a LOW state. If such a
state is found, it will print a statement that says “Movement Detected” on the web page. The
basic version of the program, written in C++, is shown in Figure 7. This code will print to the
serial monitor every time movement is detected and when there is no detection.
void setup() {
Serial.begin(9600); //setting the baud rate
pinMode(2, INPUT); //reading slot 2 as an input
}

//the program loops infinitely


void loop() {
// read the input pin:
PIRstate = digitalRead(2);
if (PIRstate == HIGH) { // PIR sensor detected movement
Serial.println("Detected");
}
else { // No movement is detected
Serial.println("No movement thus far...");
}

delay(1); // delay in between reads for stability


}
Figure 7: Basic Loop for Movement Detection
The program will also contain code to make the Arduino Uno/Ethernet Shield combo become its
own HTML web server. Many of the procedures are borrowed from Arduino’s Ethernet library
[1], such as server() and begin(). A section illustrating the creation of a server using these
methods is displayed in Figure 8. In order to create a server, three bare minimums are needed: an
available IP address, a port, and the MAC address of the Ethernet Shield. The port is defaulted to
80 so as to allow HTTP requests, while the MAC address is found on the Ethernet Shield itself.
The IP address should be a static IP address, so the Arduino can be the only one to utilize it. For
this project, the MAC address can be found in Figure 8, while the IP address is in Section 4.
EthernetServer server = Server(80); //http defaults to 80
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0E, 0xD0, 0xE6 };

void setup() {
Ethernet.begin(mac, ip);
server.begin();
}
Figure 8: Ethernet Hosting on Arduino
8

In addition to Arduino Ethernet classes and libraries, the Arduino will also host the web
page in HTML. This web page will display whether or not the PIR sensor is detecting motion or
not, as well as contain two buttons for turning the PIR sensor on and off. When programming the
web page, the Arduino will need to write to the client the HTML language for displaying the web
page. It will begin by writing to the client a standard HTTP request, and then construct the page
using HTML tags. This is demonstrated in Figure 9. An example of a simple web page can be
found on Arduino’s website [1].
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();

Serial.println();

// auto reload webpage every 5 second


client.println("<META HTTP-EQUIV=REFRESH CONTENT=1 URL=>");

// webpage title
client.println("<center><p><h1>Room Monitoring Web
Server</h1></p><center><hr><br />");
Figure 9: Building the HTML web page on Client
3.3 Design Diagram
In the diagram below, all the hardware components and the software are displayed and
linked to each other in the appropriate fashion. This is a diagrammatic model of how the room
monitoring web server functions.

Client reading
results via

PIR detects
person walking

Software is
programmed on
Arduino boards

Connected via
Ethernet
9

4. Implementation
The room monitoring web server has two basic components that allow it to function.
They are:
1. PIR Digital Signal Reading
2. Ethernet Shield Server Hosting
4.1 PIR Digital Signal
When the PIR sensor detects movement, it sends a HIGH signal, also represented with
the number 1, to the microcontroller. The programmer interprets it and the result can be
displayed, used to trigger an event, or sent via the Internet through the Ethernet Shield. In Figure
10, code for interpreting the digital signal from the PIR sensor is demonstrated. When the signal
is HIGH, the Uno will print to the client “Movement Detected” in red font. When the signal is
LOW, it will print “No Movement” in green font. This project has also implemented an LED add-
on, which is connected to PIN7 on the Arduino. When movement is detected, the LED will turn
off, and vice versa. The Arduino will send a digital signal to an LED that is either HIGH (LED
ON) or LOW (LED OFF).
PIRstate = digitalRead(2);
if (PIRstate == HIGH) { // PIR sensor detected movement
client.println("<p><h2><font color=red>Motion
Detected!</font></h2></p>");
digitalWrite(LED, HIGH);
}
else { // No movement is detected
client.println("<p><h2><font color=green>No
Movement</font></h2></p>");
digitalWrite(LED, LOW);
}
Figure 10: PIR Sensor and LED Signaling
4.2 Ethernet Shield Server
Once the PIR sensor is able to send a signal to the Uno microcontroller, the
microcontroller can print to the serial monitor when it is detecting movement and when it is not.
With the Ethernet Shield, the microcontroller can print to a web server instead of the serial
monitor using Client.print()instead of Serial.print().Client.print()will be used
to send information to the client’s computer. This information will be used to build a web page
as well as display the data from the PIR sensor. This is accomplished through the use of HTML
tags encoded in the messages to the client.
10

In the web page that the Arduino hosts there will be a standard web title, a couple
headers, two buttons, and a footer. The two buttons will allow the client to turn the motion
sensing off or on. These buttons will also indirectly control how the LED behaves, because the
LED will turn on only if the PIR sensor detects motion. Figure 11 demonstrates how the buttons
will control the sensing of the PIR. The code in Figure 11 loops infinitely, constantly updating
whether the on-off switch is on or off.
int onOffSwitch = 0;

...
if (onOffSwitch = HIGH) {
// code for motion detection
// see Figure 10
}

...
// button functions
client.println("<form method=get name=form>");
client.println("<button name=b value=1 type=submit>Sense Motion
On</button>");
client.println("<button name=b value=2 type=submit>Sense Motion
Off</button>");
client.println("</form><br />");

...
if (!strcmp(command, "1")) {
onOffSwitch = 1;
}
else if (!strcmp(command, "2")) {
onOffSwitch = 0; }
Figure 11: Code for On-Off Buttons
It should also be noted that the web page is a static web page, instead of a dynamic or
active web page. This has implications in the overall implementation. In order to update the
client on any movement in the room, the Arduino will constantly have to refresh the page. This
project is implemented so as to refresh the page every 0.5 seconds.

4.3 Experiments
4.3.1 Local Operation
In experimenting with the PIR sensor, there are some physical limitations to the device.
First is the range of detection with the device. The sensor’s range is limited to approximately two
meters in any direction, as long as the sensor is facing upwards. This is the default range setting
for the specific device used in this experiment.
11

Another limitation that may originate with the device comes from a lag whenever the
sensor gives off a signal. If the signal remains 0 for a brief moment, the detection of movement
will prompt the signal to 1 at once. Once movement subsides, the signal will go back to 0.
However, if movement is made immediately after, the sensor does not seem to read the
movement or output the correct signal for a couple of seconds. That or the Arduino Uno is not
interpreting the signal immediately after the sensor changes its signal output. One would then
have to wait a couple of seconds and then the sensor begins to output a 1 again. It appears there
is a ‘restoration’ period with the PIR sensor and it’s signal output.
After researching this problem, it was recommended to implement a resistor into the
circuitry that connects the digital out pin of the HR-501 sensor to the PIN2 sensor on the
Arduino. The resistor helps to “pull up” the signal, thereby eliminating some lag. The
implementation of this can be seen in Figure 6. Upon implementing this, the lag time of the
sensor has been much improved. However, there is still some slight lag.
4.3.2 Web-Based Operation
In testing the Arduino Ethernet shield, it has performed well. When coded successfully,
the web page is displayed well. All titles, headers and buttons perform as intended. When
connected on a local network, the connection speed is excellent. In the Room Monitoring Web
Server program, the program is designed to refresh every 0.5 seconds so as to update the status
of the motion detector. Because the information to pass to the client is very small, refreshing
every 0.5 seconds does not put too much strain on the Arduino, the client, or the network. Figure
12 displays screenshots on a client computer that shows the three different states of the web
page.
In addition to having a client computer connect remotely, multiple client computers can
also connect to the Arduino, simultaneously. During testing, it was discovered that each of these
clients had the ability to turn on or off the motion sensing for their respective web page. Only
when all clients have turned off the motion sensing did the PIR sensor remain inactive. However,
if only one client turns on the motion sensing while others have turned it off, the Arduino will
still make the PIR sensor detect motion and report the results to the one client who has turned it
on.
12

Figure 12: Web Page Results


13

5. Conclusion
The Room Monitoring Web Server is an Arduino program that utilizes the Arduino
Ethernet Shield to host a web page that displays whether or not there is movement in a certain
room. It does this by utilizing a motion detecting unit, HR-501, also known as a PIR sensor. This
sensor is wired to the Arduino Ethernet Shield that sits atop the Arduino microcontroller.
Whenever it detects motion it sends a digital signal to the Arduino. This signal is then interpreted
by the Room Monitoring Web Server program on the Arduino and then transmitted to a client
computer that connects to the Arduino remotely, using the Arduino’s IP address. On the client
computer, the Arduino will display a static web page that displays if there is motion being
detected or not.
In implementing this project, some difficulty was met with the PIR sensor module. When
detecting motion, the program would encounter lag. Motion would be detected seconds after
actual motion occurred. Similarly, the digital signal would switch back to 0 (or no motion)
seconds after motion actually stopped. This was somewhat fixed by using a resistor in series with
the pin connections. The resistor helps to “pull up” the signal given off by the sensor. It was
connected in series with the digital-out pin of the PIR sensor module. A 220k-ohm resistor was
used.
Despite this obstacle, the Room Monitoring Web Server successfully hosts a web page
accessible by anyone with an Internet connection. Using the IP address, 69.88.163.52, one can
directly connect to the Arduino and pull up a page that displays whether there is motion being
detected or not. Additionally, one can click one of two buttons to turn the motion sensing off or
on.
Future extensions of this project can be to add several other sensors and modules to the
Arduino so as to have a full security detail on a room. The Arduino could also be programmed
remotely using the Arduino’s IP address. This way, one could create their own security or
monitoring program that utilizes all possible sensors in different ways. However, in order to
implement this, a second Arduino microcontroller will be needed, in addition to the Arduino
Ethernet Shield + Arduino combo. This is because one Arduino needs to have the arduino-
tftpboot bootloader, which loads a sketch onto the actual Arduino that holds the program.
Implementing this also requires a static IP address as well as additional networking. (See
reference 5).
14

5. References
[1] "Arduino - Ethernet." Arduino. Arduino, n.d. Web. 07 October 2013.
<http://arduino.cc/en/Reference/Ethernet>.

[2] Boxall, J. Arduino Workshop. San Francisco, CA: no starch press, 2013.

[3] Gertz, E., and P. Di Justo. Environmental Monitoring with Arduino. Sebastopol, CA: O'Reilly
Media, 2012.

[4] Meyer, Adam. Did It Move? Detecting Motion with PIR + Arduino. Bildr. Web 07 November
2013. <http://bildr.org/2011/06/pir_arduino/>.

[5] Lindsay, Philip. How to Upload A Sketch To Your Arduino Via A Network. Freetronics. Web
07 November 2013. < http://www.freetronics.com/pages/how-to-upload-a-sketch-to-your-
arduino-via-a-network#.UqVdSaWhDwI>.

You might also like