You are on page 1of 6

Internet of Things based Smart Environmental

Monitoring using the Raspberry-Pi Computer

Mohannad Ibrahim, Abdelghafor Elgamri, Sharief Babiker, Ahmed Mohamed
Department of Electrical & Electronic Engineering
University of Khartoum
Khartoum, Sudan,,,

AbstractThis paper proposes an approach to build a costeffective standardized environmental monitoring device using the
Raspberry-Pi (R-Pi) single-board computer. The system was
designed using Python Programming language and can be
controlled and accessed remotely through an Internet of Things
platform. It takes information about the surrounding
environment through sensors and uploads it directly to the
internet, where it can be accessed anytime and anywhere through
internet. Experimental results demonstrated that the system is
able to accurately measure: temperature, humidity, light level
and concentrations of the carbon monoxide harmful air
pollutant. It's also designed to detect earthquakes through an
assembled seismic sensor.
Keywords GPIO; IoT; monitoring; Raspberry-Pi; Sensor;



Tracking the environmental parameters variation is

essential in order to determine the quality of our environment.
The collected data encompass important details for a variety of
organizations and agencies. With the results of monitoring,
governments can make informed decisions about how the
environment will affect the society and how the society is
affecting the environment. Outside the governments and other
organizations, the information is used by many people, because
of the weather's effect on a wide range of human's activities,
such as: agriculture, transportation and leisure time. The
information can be used by municipal engineers to design flood
control systems or public health experts to design effective
policies. Timely and effective responses to environmental
emergencies, such as spills, are impossible without adequate

Fig. 1. GPIO connector pins with the BCM2835 pin designations.

applications, services and reach common goals. The IoT

applications are boundless, few examples are; smart cities,
smart energy and the smart grids, smart transportation and
enabling traffic management and control [10].
Environmental monitoring applications of the IoT normally
exploit sensors to aid in environmental protection by
monitoring parameters like air or water quality and
atmospheric or soil conditions. Furthermore, it can even
include areas like monitoring the wildlife and their habitats.
Development of Resource-Constrained Devices connected to
the Internet also means that other applications like earthquake
or tsunami early-warning systems can also be used by
emergency services to provide more effective aid. IoT devices
in this application typically span a large geographic area and
can also be mobile [6]. The use of modern technologies such as
single-board computers can facilitate and provide even more
functionalities to IoT.

Unfortunately, data provided by agencies are sometimes

overwhelmingly ambiguous and un-confined to the
environment, with samples generally sparsely taken across
large regions despite that some environment parameters
variance occurs across smaller areas. Therefore this data might
not be very helpful on a personal level.

The R-Pi, is a linux-based, low cost, credit-card sized

single-board computer that can be directly used in electronics
projects because it has general purpose input/output (GPIO)
pins right on the board [7]. The GPIO connector has 26 pins
where up to 17 GPIO pins (8 existing GPIO + 9
reconfigurable) are available for hardware interfacing as shown
in Fig. 1.

Internet of Things (IoT) is a concept and a paradigm that

considers pervasive presence in the environment of a variety of
things/objects that through wireless and wired connections and
unique addressing schemes are able to interact with each other
and cooperate with other things/objects to create new

The system is comprised of several subsystems; each will

be explained in detail in this section. The design process
included designing the basic units for sensing the: air quality,

ISBN: 978-1-4673-6832-22015 IEEE




Fig. 3. LDR's output voltage.

Fig. 2. A schematic diagram of the system.

weather and earthquake parameters. The raspberry's processing

responsibilities includes: uploading, monitoring, displaying and
interpreting the data from the units. Fig. 2 shows the schematic
diagram containing the main components and the functional
units of the system.
A. Sensing
The purpose of this unit is to detect (sense) all the
parameters desired using a collection of sensors that were
chosen carefully to achieve the best performance. Digital
sensors will give a digital output suitable for the R-Pi's (digital
only input), while analog sensors will need analog to digital
1) Air Quality
The samples absorbed by the electro-catalytic sensing electrode
contain gas molecules. Next, they pass through a diffusion
medium and electrochemically react to an appropriate sensing
electrode potential. The electric current generated by the
reaction is directly proportional to the gas concentration. This
current is converted to voltage for a meter or recorder readout
The diffusion limited current, ILim, is directly proportional
to the gas concentration according to the simplified equation:

ILim =



where ILim is the diffusion limited current in amps, F is the

Faraday constant (96,500 coulombs), A is the reaction
interfacial area in cm2, n is the number of electrons per mole
reactant, D is the diffusion path length, C is the gas
concentration in mol/cm3, and delta is the gas diffusion
constant, representing the product of the permeability and
solubility coefficients of the gas in the diffusion medium [11].
2) Weather
a) Temperature
The core of the temperature sensor is a band gap core that
comprises four transistors: Q1, Q2, Q3 and Q4. Transistors Q1
and Q2 are biased by Q3 to approximately 8 A. The band gap
core operates both Q1 and Q2 at the same collector current
level; however, because the emitter area of Q1 is 10 times that
of Q2, the VBE of Q1 and the VBE of Q2 are not equal [4].
The results is scaled using two resistors; to produce the
output voltage transfer characteristic of each temperature

ISBN: 978-1-4673-6832-22015 IEEE

sensor and, simultaneously, the resistors are used to scale the

VBE of Q1 as an offset term in VOUT. The band gap core is
buffered by the output voltage of the temperature sensor that is
available at the emitter of Q4. The short-circuit current limit of
the devices is set to 250 A by the current gain of Q4 [4].
b) Humidity
Most of the currently available humidity sensors are
constructed based on a porous sintered body structure ceramics
and utilize the ionic type humidity-sensing principle. By water
adsorption on the ceramic surfaces, their electrical properties
would change and this change encompasses the resistance,
capacitance or electrolytic conduction depending upon the
sensor type [1]. In ionic type sensing elements, by increasing
the humidity, the conductivity increases and thus the dielectric
constant increases [2]. The R-Pi's digital-only input makes
digital sensors the best choice for our system.
c) Light level
Figure 3 shows the equivalent circuit of a light-dependent
resistor. The amount of voltage drop across series resistor, R2 is
determined by the resistive value of the light dependent
resistor, RLDR. As known, the current through a series circuit is
common and as the LDR changes its resistive value due to the
light intensity, the voltage present at VOUT will be determined
by the voltage divider formula. An LDRs resistance, RLDR can
vary from about 100 s in the sun light, to over 10 Ms in
absolute darkness with this variation of resistance being
converted into a voltage variation at VOUT [8].
3) Earthquake
Figure 4 is a basic diagram illustrating the classic design
for the inverted-pendulum seismic sensor. A vertical mass is
suspended from a horizontal-hinge assembly, and tracings are
recorded in a vertical direction, as shown in Fig. 4 [3].
The modified inverted-pendulum design used in this project
is very responsive to low-frequency seismic vibrations and is
fairly inexpensive to construct. It's an extremely simple design,
yet highly capable of detecting low-frequency seismic waves.
The sensor produces an analog voltage representation of the
seismic wave in lieu of a mechanical tracing, as is the case in
the classical design.
An operational amplifier (op-amp) that operates from a single
power supply of 3 V is added to the circuit to amplify the low
seismic signal. The op-amp is configured as a non-inverting
amplifier as shown in Fig. 5. The 11X gain is fixed by resistors
R1 and R2 with R1 resistance of 100 K, and R2 resistance of


IoT. Thus, it enables people to tag and share real time sensor
data from objects, devices and spaces around the world [12].
D. Data Interpretation
This section is about transferring the data from some
sensors into meaningful information [9]. At Table 1, the CO
sensor is taken as an example due to the difficulties in
understanding the values associated to its concentration.


A. Hardware materials

Fig. 4. Inverted pendulum seismic sensor.

10 K. The gain is calculated using the non-inverting gain


Gain=1+ R1


B. Computer processing (Raspberry Pi)

This is the most important unit and the core of the system.
It handles all the processing and controlling needed for the
system to function. It receives the sensing information,
processes it, returns the corresponding values, and generates
the necessary controls to guide the data to the desired
1) Serial protocols
There are several serial protocols shown in the pin
descriptions that the chip uses to deal with the peripherals
(sensors) connected to it. These protocols are: Serial Peripheral
Interface (SPI), Inter-Integrated Circuit interface or I2C and
standard Universal Asynchronous Receiver Transmitter
(UART). All three serial protocols described in this section are
implemented in hardware, i.e. there is actual silicon dedicated
to performing the protocol functions, which is the most
efficient and fastest way to provide these serial interfaces
2) Connect to sensors
Each of the system's sensors is connected to the R-Pi's
GPIO pins in different configurations that will be shown in
detail in section III. The main concept of the wiring is that
digital sensors are connected directly to the R-Pi's GPIO, while
analog sensors are connected to an analog to digital converter,
which in turn is directly connected to the R- Pi.
3) Software Design
Before writing the code for the system, several software
dependencies must be installed. These dependencies add more
functionality to the use of Python on the R-Pi and make the
software design process easier. For example, some
dependencies allow Python to use the R-Pi's interfaces or
interface with its GPIO pins. The installation of dependencies
requires internet connection. The code necessary to run the
system was then installed on the R-Pi to operate the system.
C. Uploading
EEML, is a protocol implemented for sharing sensor data
between remote environments, both physical and virtual.
Additionally, tt can be used to facilitate direct connections
between any two environments and (many-to-many)
connections as implemented by the web services that support

ISBN: 978-1-4673-6832-22015 IEEE

1) Sensors
a) Temperature
The temperature sensor was chosen to be TMP36. The
reason for this decision is the sensor's wide temperature range
and doesn't require a negative voltage to read sub-zero
b) Humidity
The humidity sensor was chosen to be DHT22, which is a
basic, low-cost digital temperature and humidity sensor that
uses a capacitive humidity sensor and a thermistor. It provides
the measure in a digital form, and therefore, no analog input
pins are needed. Hence, it's fairly simple to use, but requires
careful timing for data capturing.
c) Light Level
Photo-resistor is a resistor which made of semi-conductor
material and the conductance changes with luminance
variation. Performances and Features: Coated with epoxy,
Good Reliability, High Sensitivity, Small Volume, Fast
Response and Good Spectrum Characteristic.
d) CO Concentration
The sensor was chosen to be MQ-7, which can detect COgas concentrations anywhere from 20 to 2000 ppm in an easyto-use method. The sensor's detection range can be altered
using a potentiometer.
a) Earthquake
Figure 6 shows the sensor assembly that consists of a thin
brass strip bolted to a thin-film-piezoelectric sensor that, in
turn, is attached to a circuit board. The brass strip is 1/4 inch
wide by 1/32 inch thick and 9 inches long. There is a 1/16-inch
diameter hole drilled 1/8 inch on center from one end. The
brass strip is bolted to the sensor using a fine-threaded #80 nut
and bolt set. A drop of adhesive should be used, such as blue
Loctite, on the nut to ensure that it does not loosen. As seen in
Fig. 6, the sensor will need some amplification to detect weak
seismic signals. The op-amp's gain will be fixed by resistors R1
and R2, with R1 resistance of 100 K, and R2 resistance of 10
K [2].
The thin-film-piezoelectric sensor is chosen to be LDT0028K model and is added only in the Fritzing simulator.
2) Analog to Digital Converter
As the R-Pi only handles digital inputs, an ADC is needed.
MCP3008 has been used; this chip will add 8 channels of 10bit digital input to the R-Pi. It's easy to use, and uses SPI, so
only 4 pins are required. This chip has been chosen as a great


Fig. 6. Seismic sensor assembly





Fig. 5. Seismic amplifier circuit.


Install python modules easily

accompaniment to the R-Pi computer for many reasons, most

importantly; it operates over a broad voltage range (2.7V-5.5V).
Low-current design permits operation with typical standby
currents of only 5 nA and typical active currents of 320 A.
Features: 10-bit resolution, Analog inputs programmable as
single-ended or pseudo-differential pairs, low power CMOS
technology and 500 A max active current at 5V.


The latest & greatest version of Python


Connect the Pi to Xively


Interface with the Pi's GPIO pins


Let Python use the Pi's I2C interfaces


Download code from GitHub easily

3) Connection to the Internet

R-Pi comes only with a wired network; it can be useful to
get it wifi ready. It requires a compatible WIFI DONGLE. Wifi
dongle features: low power consumption, works automatically
with (Raspbian) and have a small size, and low cost.
B. Software materials
There are many software materials like compilers and
simulators that have been used during the development of the
system. Some of them will be listed in this section.
1) Libraries
The libraries (dependencies) listed in Table 2 were required
before writing the code. Each one of these libraries benefits
either Python or the R-Pi differently [11].
2) Fritzing
Fritzing is an open source software initiative to support
designers and artists ready to move from physical prototyping
to actual product.




35 ppm

Exposure for a period of 6-8 hours causes

headache and dizziness.

100 ppm (0.01%)

Health threatening and causes slight headache

if exposed to in two to three hours.

200 ppm

It causes slight headache and loss of judgment

within 2 to 3 hours exposure.

400 ppm

Frontal headache within one to two hours

1,600 ppm

Headache, tachycardia, dizziness, and nausea

within 20 min; death in less than 2 hours

3,200 ppm

5 10 minutes exposure causes nausea and

dizziness. It causes death within 30 minutes.

12,800 ppm

Unconsciousness after 2-3 breaths. Death in

less than three minutes.

ISBN: 978-1-4673-6832-22015 IEEE

3) Xively
Xively (formerly known as Cosm and Pachube) offers an
IoT platform as a service, business services, and partners that
enable businesses to quickly connect products and operations
to the Internet.
4) Putty
PuTTY is a free and open-source terminal emulator, serial
console and network file transfer application. It supports
several network protocols, including SCP, SSH, Telnet, rlogin,
and raw socket connection.
C. Hardware implementation
The following steps have been followed in order to have a
complete functioning system (as shown in Fig. 8):
x The R-Pi was connected to the Breadboard; the 5V,
3.3V, and GND GPIO pins.
x The ADC was connected.
x The TMP36 temperature sensor, LDR light level sensor
were connected to the circuit through the ADC. The
DHT22 digital humidity sensor was connected directly.
x The MO-7 sensor was connected; the scheme used to
add the sensor is shown in Fig. 7.
x The seismic sensor isn't a part of the real system and is
added to the final circuit as a simulation.
D. Software Implementation
1) Running the raspberry Pi headless
The software (PuTTy) was used to communicate the
raspberry pi without the need for hardware peripherals like
screen, keyboard or mouse. It was done by connecting the
raspberry pi to the internet using the Wifi-Dongle and then
providing PuTTy with the R-Pi's IP address. The reason behind
running the raspberry pi headless is the power that is consumed
by the raspberry pi's peripherals. Hence, by using this method,
the pi's power limitations were reduced in order to have a more
efficient and reliable system.


Fig. 7. Connecting the MQ-7.

FEED = 1170656994
API_URL = '/v2/feeds/{feednum}.xml' .format(feednum = FEED)
pac = eeml.Pachube(API_URL, API_KEY)
pac.update([eeml.Data(0, temp, unit=eeml.Celsius())])
pac.update([eeml.Data(1, light_level,)])
pac.update([eeml.Data(2, h,)])
pac.update([eeml.Data(3, CO_level,)])
Fig. 10. Code to upload data to the IoT platform (Xively).

calibration and make the best use of open source. The libraries
are: MCP3008, AQSensor, LightSensor.
For the analog sensors, two more functions were
implemented, ConvVol(); which is used to convert sensors data
to voltage levels rounded to a specified number of decimal
places, and ConvTemp(); to calculate temperature from TMP36
using the converted voltage from the previous function. The
function AQSensor() was imported which helped in calibrating
the sensor using a 10K pull-up resistor. A delay of 30
seconds was defined between readings which is suitable for the
application and for the pi's processing power.
Figure 10 shows the code responsible of uploading data to
the internet through our Xively Account using the API KEY
and FEED ID; which are codes provided by the platform's
Application Programming Interface to identify the requesting
program and its user to the site. Each sensor's data is updated
through pac.update() providing the number associated with
sensor, name and unit.
The system was tested using unit and integration testing
methods and proved to function accurately.


Figure 11 (a) shows the temperature (in Celsius) and the

light level (in Lux) when sensors were placed in a room. In
Fig. 8. Circuit simulation using Fritzing software.

Fig. 11. Light and temperature when light is ON (a), Light is OFF (b).
Fig. 9. Commands to install some libraries to the R-Pi.

2) Installing required dependencies

The installation required internet connection, and was done
using the RPi's LXTerminal which used Linux commands. The
process is shown in Fig. 9.
The methods needed to transform some sensors' readings
into real-time measures were implemented and full code can be
found at [5].
Three more libraries were installed to facilitate the sensors

ISBN: 978-1-4673-6832-22015 IEEE

Fig. 12. Temperature, light and humidity.


implementation process:

Fig. 13. CO Concentration.

The R-Pi's special characteristics such as the digitalonly input and power limitation narrowed the options
of compatible components.
The poly-fuse and the current draw in the R-Pi limit
the current to the 5V GPIO pin, which limits the
number of sensors that could be connected to that pin
(Gas sensors). Connecting too many components to
that pin can also result in permanent damage to the
device. Running the R-Pi headless (with no keyboard,
mouse and a screen) helped in reducing the current
draw but it was still not enough.
Difficulties in calibrating the carbon monoxide sensor
due to the need of a controlled and contained chemical
reaction that produces the gas.


The environmental monitoring system might offer several

potential benefits; It provides monitoring services for remote
areas and for ad hoc applications that are normally not
available from larger monitoring systems owned by
governments and big agencies. Its' earthquake detection
capability can help saving millions of lives. The total life-cycle
cost of the system is minimized and could theoretically run for
months on end entirely without the need for human
intervention. Due to its ability to automatically upload to the
internet, one correctly placed system can provide easilyaccessible weather data for the whole community. It can be
used to predict the onset of bad weather using signs such as
changing temperature and humidity. Raising the awareness of
how society is affected the region's environmental policies and
have the knowledge basis to push for the change.

Fig. 14. Xively's interface (1).


Fig. 15. Xively's interface (2).

-order to test the LDR, the light was switched ON to take the
Figure 11 (b) shows outputs for the same parameters at the
same environment (room) but with the light switched OFF.
The third result (shown in Fig. 12) shows the temperature, light
level and Humidity (in RH) after adding the DHT22 sensor.
Figure 13 shows concentration of CO gas (in p.p.m), the
sensor was tested alone first as a unit testing step and to insure
the safety of the raspberry pi board; as this sensor draws more
power from the board.
The fifth result (shown in Fig. 14) shows the Xively's
interface that is used to present the sensors' readings. This
interface (website) can be accessed by multiple users from
different locations by using devices that support internet
browsing. Figure 15 shows additional features provided by
Xively that adds more functionality to the system; such as
google maps, which tells the exact location of the system.


Traversa, E., Ceramic sensors for humidity detection: The state-of-theart and future developments, Sens. Actuators B Chem. 1995.
[2] Rahman Wagiran and Mohd Nizar Hamidon Hamid Farahani,
"Humidity sensors principle, mechanism, and fabrication technologies,
A comprehensive review," Sensors, 2014.
[3] Donald Norris, Raspberry pi projects for the evil genius, McGraw-Hill
Education, 2014.
[4] Analog Devices Inc., "Low voltage temperature sensors
(TMP35/TMP36/TMP37) datasheet".
[5] Mohannad M. Ibrahim, Abdelghafour Elgamri and Ahmed Mohamed,
Environmental monitoring using the raspberry-pi (En-Pi-ronment),
Appendix A, 2014.
[6] Wikipedia, [Online],
[7] Raspberry Pi Foundation, [Online],
at- is-a-raspberry-pi/.
[8] Electronics tutorials, [Online].
[9] AirPi air quality & weather project, [Online],
[10] Ovidiu Vermesan, Peter Friess, Internet of Things: Converging
Technologies for Smart Environments and Integrated Ecosystems.
[11] Interscan
[12] Extended

Some technical problems have been faced during the

ISBN: 978-1-4673-6832-22015 IEEE