Download as pdf or txt
Download as pdf or txt
You are on page 1of 29

CONTENTS

PROGRAM DESCRIPTION PAGE NO


NO
1 Transmit A String Using UART 01-04

2 Point-To-Point Communication of Two 05-09


Motes Over the Radio Frequency

3 Multi-Point to Single Point 10-14


Communication of Motes Over the Radio
Frequency

4 I2C Protocol Study 15-19

5 Read Temperature and Relative Humidity 20-23


Value from Sensor
INTERNET OF THINGS

INTRODUCTION

INTERNET OF THINGS

IOT is the networking of physical objects that contain electronics embedded within their
architecture in order to communicate and sense interactions amongst each other or with respect
to the externa environment. In the upcoming years, IOT-based technology will offer advanced
levels of services and practically change the way people lead their daily lives. Advancements in
medicine, power, gene therapies, agriculture, smart cities. and smart homes are just a very few of
the categoricalexamples
where IOT is strongly established.
There are four main components used in lot:
I. Low-power embedded systems: Less battery consumption, high performance are the inverse
tactorsthat play a significant role during the design of electronic systems.
2. Cloud computing: Data collected through IOT devices is massive and this data has to be stored
on areliable storage server.
3. Availability of big data: We know that IOT relies heavily on sensors, especially in real time
4. Networking connection: In order to communicate, internet connectivity is a must where each
physical object is represented by an IP address.

1.2 CHARACTERISTICS OF IT

• Massively scalable and efficient.


• IP-based addressing will no longer be suitable in the upcoming future
• An abundance of physical objects is present that do not use IP, so loT is made possible.
• Devices typically consume less power. When not in use, they should be automatically
programmedto
sleep.
• A device that is connected to another device right now may not be connected in another instant
oftime.
• Intermittent connectivity - IOT devices aren't always connected. In order to save bandwidth and
battery consumption, devices will be powered off periodically when not in use.

Dept. of CSE, VKIT 2022-2023 Page 1


INTERNET OF THINGS

1.3 MODERN APPLICATIONS


1. Smart Grids and energy saving
2. Smart cities
3. Smart hones
4. Healthcare
5. Earthquake detection
6. Radiation detection hazardous gas detection
7. Smartphone detection
8. Water How monitoring
9. Traffic monitoring
10. Wear

Dept. of CSE, VKIT 2022-2023 Page 2


INTERNET OF THINGS
PROGRAM 1

TRANSMIT A STRING USING


UART

UART: A universal asynchronous receiver-transmitter (UART) is a computer hardware


device for asynchronous serial communication in which the data format and transmission
speeds are configurable. It sends data bits one by one, from the least significant to the most
significant, framed by start and stop bits so that precise timing is handled by the
communication channel. The electric signaling levels are handled by a driver circuit external
to the UART. Two common signal levels are RS-232, a 12-volt system, and RS-485, a 5-volt
system. Early teletypewriters used current loops. It was one of the earliest computer
communication devices, used to attach teletypewriters for an operator console. It was also an
early hardware system for the Internet. A UART is usually an individual (or part of an)
integrated circuit (IC) used for serial communications over a computer or peripheral device
serial port. One or more UART peripherals are commonly integrated in microcontroller chips.
Specialized UARTs are used for automobiles, smart cards and SIMs. A related device, the
universal synchronous and asynchronous receiver-transmitter (USART) also supports
synchronous operation.

Transmitting and Receiving Serial data: The universal asynchronous receiver-


transmitter (UART) takes bytes of data and transmits the individual bits in a
sequential fashion. At the destination, a second UART re-assembles the bits into
complete bytes. Each UART contains a shift register, which the fundamental method
of conversion between serial and parallel forms. Serial transmission of digital
information (bits) through a single wire or other medium is less costly than parallel
transmission through multiple wires. The UART usually does not directly generate or
receive the external signals used between different items of equipment. Separate
interface devices are used to convert the logic level signals of the UART to and from
the external signaling levels, which may be standardized voltage levels, current levels,
or other signals.

Communication may be 3 modes:

• simplex - in one direction only, with no provision for the receiving device to
sendinformation back to the transmitting device.
• full duplex - both devices send and receive at the same time)
Dept. of CSE, VKIT 2022-2023 Page 3
INTERNET OF THINGS

• half duplex - devices take turns transmitting and receiving)

Receiver: All operations of the UART hardware are controlled by an internal clock
signal which runs at a multiple of the data rate, typically 8 or 16 times the bit rate. The
receiver tests the state of the incoming signal on each clock pulse, looking for the
beginning of the start bit. If the apparent start bit lasts at least one-half of the bit time,
it is valid and signals the start of a new character. If not, it is considered a spurious
pulse and is ignored. After waiting a further bit time, the state of the line is again
sampled and the resulting level clocked into a shift register. After the required number
of bit periods for the character length (5 to 8 bits, typically) have elapsed, the contents
of the shift register are made available (in parallel fashion) to the receiving system.
The UART will set a flag indicating new data is available, and may also generate a
processor interrupt to request that the host processor transfers the received data.
Communicating UARTs have no shared timing system apart from the communication
signal. Typically, UARTs resynchronize their internal clocks on each change of the
data line that is not considered a spurious pulse. Obtaining timing information in this
manner, they reliably receive when the transmitter is sending at a slightly different
speed than it should. Simplistic UARTs do not do this; instead they resynchronize on the
falling edge of the start bit only, and then read the centerof each expected data bit, and
this system works if the broadcast data rate is accurate enough to allow the stop bits to
be sampled reliably. It is a standard feature for a UART tostore the most recent
character while receiving the next. This "double buffering" gives a receiving computer
an entire character transmission time to fetch a received character. Many UARTs have a
small first-in, first-out (FIFO) buffer memory between the receiver shift register and the
host system interface. This allows the host processor even more timeto handle an
interrupt from the UART and prevents loss of received data at high rates.
Transmitter: Transmission operation is simpler as the timing does not have to be
determined from the line state, nor is it bound to any fixed timing intervals. As soon as
the sending system deposits a character in the shift register (after completion of the
previous character), the UART generates a start bit, shifts the required number of data
bits out to the line, generates and sends the parity bit (if used), and sends the stop bits.
Since full-duplex operation requires characters to be sent and received at the same
time, UARTS use two different shift registers for transmitted and received characters.
High performance UARTs

Dept. of CSE, VKIT 2022-2023 Page 4


INTERNET OF THINGS

could contain a transmit FIFO (first in first out) buffer to allow a CPU or DMA
controller to deposit multiple characters in a burst into the FIFO rather than have to
deposit one character at a time into the shift register. Since transmission of a single or
multiple characters may take a long time relative to CPU speeds, a UART maintains a
flag showing busy status so that the host system knows if there is at least one character
in the transmit buffer or shift register: "ready for next character(s)" may also be
signaled with an interrupt.

Code:
void setup ()
{
// put your setup code here to run
onceSerial.begin(9600);
}
void loop (
{
//put your main code here to run repeatedly
Serial.println("HELLO WORLD");
delay (500);
}

Explanation:

• setup() and loop(): After creating a setup() function, which initializes and sets the
initial values, the loop() function does precisely what its name suggests, and loops
consecutively, allowing your program to change and respond. Use it to actively control
the Arduino board.
• serial.begin() and serial.println(): Serial begin is used to establish serial
communication. Serial communication is one way to allow devices to talk to each
other. Most often, you'll be using serial begin when you want to print something out to
your computer screen from your Arduino. This would also require the serial print
function.
• delay(): allows you to pause the execution of your Arduino program for a specified
period. For that purpose, the method requires you to supply it with a whole number
that specifies how many milliseconds the program should wait.

Dept. of CSE, VKIT 2022-2023 Page 5


INTERNET OF THINGS

Output snapshot:

Dept. of CSE, VKIT 2022-2023 Page 6


INTERNET OF THINGS

PROGRAM 2

POINT-TO-POINT COMMUNICATION OF TWO MOTES


OVER THE RADIOFREQUENCY

Point-to-Point Communication: Two nodes directly communicating with each other without
any relay or compression of communication data are no longer the norm. While a simple
phone call can still be defined as a point-to-point communication, a VoIP call via. WhatsApp
or skype can technically be considered point to multipoint communication, as your data input
is first received by a cloud or gateway, which then encrypts and broadcasts your data to its
final destination. Understanding the meaning of point to point communication makes it easier
to understand the (oftentimes blurred, but fundamental) differences between M2M and IoT
networks In the context of telecommunication, a point to point communication (also known as
P2P) is an established connection between two nodes that can be used to communicate back
and forth. The most prominent example of point to point communication is a simple
telephone call, where one phone is connected with another, and both nodes can send and
receive audio. Early on in the advent of telecommunication, these P2P connections were
established using circuit-switched landlines. However, nowadays point to point
communication in modem networks is made possible by complex fiber-optic networks.
Different types of P2P connections can transmit different types of information, be it digital or
analog signals. A mote is a wireless transceiver that also acts as a remote sensor. The ability
to log onto a network from a distant location. Generally, this implies a computer, a modem,
and some remote access software to connect to the network.

Radio Frequency (RF): Radio frequency (RF) is the oscillation rate of an alternating electric
current or voltage or of a magnetic, electric or electromagnetic field or mechanical system in
the frequency range from around 20 kHz to around 300 GHz. This is roughly between the
upper limit of audio frequencies and the lower limit of infrared frequencies; these are the
frequencies at which energy from an oscillating current can radiate off a conductor into space
as radio waves. Different sources specify different upper and lower bounds for the frequency
range. Medical applications of radio frequency (RF) energy, in the form of electromagnetic
waves (radio waves) or electrical currents, have existed for over 125 years, and now include
diathermy, hyperthermy treatment of cancer, electrosurgery scalpels used to cut and cauterize
in operations, and radiofrequency

Dept. of CSE, VKIT 2022-2023 Page 7


INTERNET OF THINGS

ablation. Magnetic resonance imaging (MRI) uses radio frequency waves to generate images
of the human body. Radio frequencies are used in communication devices such as
transmitters, receivers, computers, televisions, and mobile phones, to name a few. Radio
frequencies are also applied in carrier current systems including telephony and control
circuits. The MOS integrated circuit is the technology behind the current proliferation of
radio frequency wirelesstelecommunications devices such as cellphones.

Frequency Wavelength ITU designation


range range IEEE
Full name Abbreviation bands
Below 3 Hz >10 km Tremendously low TLF N/A
frequency
3-30 Hz 10-10 km Extremely low ELF N/A
frequency
30-300 Hz 10-10 km Super low frequency SLF N/A

300-3000 Hz 10-100 km Ultra low frequency ULF N/A

3-30 kHz 100-10 km Very low frequency VLF N/A

30-300 kHz 10-1 km Low frequency LF N/A

300 kHz- 3 MHz 1 km-100 Medium frequency MF N/A

3-30 MHz 100-10 m High frequency HF N/A

Code:
Sender--
//HC-12 messenger send/receive

#include
SoftwareSerialmy Serial (2,3);
//RXTX void setup ()

Dept. of CSE, VKIT 2022-2023 Page 8


INTERNET OF THINGS

{
Serial.begin(9600);
my
Serial.begin(9600);
}
void loop()
{
If (Serial.available() > 0)
{
//Read from serial monitor and send over
HC-12String input = Serial.readString();
mySerial.println(input);
}
if(my Serial.available() > 1)
{
//Read from HC-12and
String input=mySerial.readString();
Serial.println(input);
}
delay(20);
}

Receiver
//HC-12 messenger send/receive

#include
SoftwareSerialmy Serial(2, 3);
//RX, TX void setup() {
Serial.begin(9600);
mySerial.begin(9600);
}
void loop () {
if (Serial.available() > 0){//Read from
serialmonitorandsend over HC-12
String input = Serial readString();
mySerial.println(input);
Dept. of CSE, VKIT 2022-2023 Page 9
INTERNET OF THINGS

} if (my Serial.available() > 1)


{//Readfrom HC-12and
send toserialmonitorString
input my
Serial.readString();
Serial.println(input);
}
delay(20);
}

Explanation:

• setup() and loop(): After creating a setup() function, which initializes and sets the
initial values, the loop() function does precisely what its name suggests, and loops
consecutively, allowing your program to change and respond. Use it to actively control
the Arduino board.
• serial.begin() and serial.println(): Serial begin is used to establish serial
communication. Serial communication is one way to allow devices to talk to each
other. Most often, you'll be using serial begin when you want to print something out to
your computer screen from your Arduino. This would also require the serial print
function.
• delay(): allows you to pause the execution of your Arduino program for a specified
period. For that purpose, the method requires you to supply it with a whole number
that specifies how many milliseconds the program should wait.
• SoftwareSerial Header: The SoftwareSerial library allows serial communication on
other digital pins of an Arduino board, using software to replicate the functionality
(hence the name "SoftwareSerial"). It is possible to have multiple software serial ports
with speeds up to 115200 bps. A parameter enables inverted signaling for devices
which require that protocol. Serial.available(): Get the number of bytes (characters)
available for reading from the serial port. This is data that's already arrived and stored
in the serial receive buffer (which holds 64 bytes). Serial.available() inherits from the
Stream utility class.
• Serial.readString(): It reads characters from the serial buffer into a String. The
function terminates if it times out (see setTimeout()). Serial.readString() inherits from
the Stream utility class.

Dept. of CSE, VKIT 2022-2023 Page 10


INTERNET OF THINGS

Output:

Dept. of CSE, VKIT 2022-2023 Page 11


INTERNET OF THINGS

PROGRAM 3

MULTI-POINT TO SINGLEPOINTCOMMUNICATION
OF MOTES OVER THERADIO FREQUENCY

Multi-Point to Single-Point Communication: In telecommunications, point-to-multipoint


communication (P2MP, PTMP or PMP) is communication which is accomplished via a
distinct type of one-to-many connection, providing multiple paths from a single location to
multiple locations. Point-to-multipoint telecommunications is typically used in wireless
Internet and IP telephony via gigahertz radio frequencies. P2MP systems have been designed
with and without a return channel from the multiple receivers. A central antenna or antenna
array broadcasts to several receiving antennas and the system uses a form of time-division
multiplexing to allow for the return channel traffic. In contemporary usage, the term point-to-
multi point wireless communications relates to fixed wireless data communications for
Internet or voice over IP via radio or microwavefrequencies in the gigahertz range.

Point-to-multipoint is the most popular approach for wireless communications that have a
large number of nodes, end destinations or end users. Point to Multipoint generally assumes
there is a central base station to which remote subscriber units or customer premises
equipment (CPE) (a term that was originally used in the wired telephone industry) are
connected over the wireless medium. Connections between the base station and subscriber
units can be either line-of sight or, for lower-frequency radio systems, non-line-of-sight where
link budgets permit. Generally, lower frequencies can offer non- line-of-sight connections.
Various software planning tools can be used to determine feasibility of potential connections
using topographic data as well as link budget simulation. Often the point to multipoint links
are installed to reduce the cost of infrastructure and increase the number of CPE's and
connectivity. The telecommunications signal in a point-to- multipoint system is typically bi-
directional, TDMA or channelized. Systems using frequency- division duplexing (FDD) offer
full- duplex connections between base station and remote sites, and time-division duplex
(TDD) systems offer half-duplex connections.

The base station may have a single omnidirectional antenna or multiple sector antennas, the
latter of which allowing greater range and capacity. The most common network type in which
backhaul is implemented is a mobile network. A backhaul of a mobile network, also referred
to as mobile-

Dept. of CSE, VKIT 2022-2023 Page 12


INTERNET OF THINGS

backhaul connects a cell site towards the core network. The two main methods of mobile
backhaul implementations are fiber-based backhaul and wireless point-to-point backhaul. [2]
Other methods, such as copper-based wireline, satellite communications and point- to-
multipoint wireless technologies are being phased out as capacity and latency requirements
become higher in4G and 5G networks.

In both the technical and commercial definitions, backhaul generally refers to the side of the
network that communicates with the global Internet, paid for at wholesale commercial access
rates to or at an Internet exchange point or other core network access location. Sometimes
middle mile networks exist between the customer's own LAN and those exchanges. This can
be a local WAN connection. Cell phones communicating with a single cell tower constitute a
local subnetwork; the connection between the cell tower and the rest of the world begins with a
backhaul link to the core of the internet service provider's network (via a point of presence). A
backhaul may include wired, fiber optic and wireless components. Wireless sections may
include using microwave bands and mesh and edge network topologies that may use a high-
capacity wireless channel to get packets tothe microwave or fiber links.

Radio Frequency (RF): Radio frequency (RF) is the oscillation rate of an alternating electric
current or voltage or of a magnetic, electric or electromagnetic field or mechanical system in
the frequency range from around 20 kHz to around 300 GHz. This is roughly between the
upper limit of audio frequencies and the lower limit of infrared frequencies; these are the
frequencies at which energy from an oscillating current can radiate off a conductor into space
as radio waves. Different sources specify different upper and lower bounds for the frequency
range. Medical applications of radio frequency (RF) energy, in the form of electromagnetic
waves (radio waves) or electrical currents, have existed for over 125 years, and now include
diathermy, hyperthermy treatment of cancer, electrosurgery scalpels used to cut and cauterize
in operations, and radiofrequencyablation. Magnetic resonance imaging (MRI) uses radio
frequency waves to generate images of the human body. Radio frequencies are used in
communication devices such as transmitters, receivers, computers, televisions, and mobile
phones, to name a few. Radio frequencies are also applied in carrier current systems including
telephony and control circuits. The MOS integrated circuit is the technology behind the current
proliferation of radio frequency wireless telecommunications devices such as cellphones.

Dept. of CSE, VKIT 2022-2023 Page 13


INTERNET OF THINGS

Dept. of CSE, VKIT 2022-2023 Page 14


INTERNET OF THINGS

Code:

// This sketch tests the standard 7-bit addresses


// Devices with higher bit address might not be seen properly.
#include
void setup()
{

Dept. of CSE, VKIT 2022-2023 Page 15


INTERNET OF THINGS

Wire.begin();
Serial.begin(96
00);while
(!Serial);
monitorSerial.println("\nI2C Scanner");
}
void loop0
{
byte error
address;int
nDevices;
Serial.println("Scanning...");
nDevices = 0;
for (address=1; address<127; address++)
{
Wire.beginTransmission(addre
ss);error =
Wire.endTransmission();
if(error == 0)
{
Serial.print("I2C device
found ataddress Ox")
if(address<1
6)
Serial.print("
0");
Serial.print(address,HE
X);Serial.println("!");
nDevices++; }

Dept. of CSE, VKIT 2022-2023 Page 16


INTERNET OF THINGS

else if
(error=
=4)
{
Serial.print("Unkown error address
0x");if(address<16)
Serial.print("0");
Serial.println(address,HE
X);
}}
if(nDevices==0)
Serial.println("No 12C devices
found\n");Else
Serial.println("done\n");
delay(5000); //wait 5 seconds for next scan
}
Explanation:

• setup() and loop(): After creating a setup() function, which initializes and sets the
initialvalues, the loop() function does properly what its name suggests, and loops
consecutively, allowing your program to change and respond. Use it to actively
control the Arduino board.
• delay(): allows you to pause the execution of your Arduino program for a specified
period. For that purpose, the method requires you to supply it with a whole number
thatspecifies how many milliseconds the program should wait.
• serial.begin() and serial.println(): Serial begin is used to establish serial
communication. Serial communication is one way to allow devices to talk to each
other.Most often, you'll be using serial begin when you want to print something out
to your computer screen from your Arduino. This would also require the serial print
function.
• wire header: This library allows you to communicate with I2C/TWI devices. On the
Arduino boards with the R3 layout (1.0 pinout), the SDA (data line) and SCL (clock
line)are on the pin headers close to the AREF pin. The Arduino Due has two
I2C/TWI interfaces SDA1 and SCL1 are near to the AREF pin and the additional one
is on pins 20
Dept. of CSE, VKIT 2022-2023 Page 17
INTERNET OF THINGS

and 21.
• beginTransmission(): This function begins a transmission to the 12C peripheral
devicewith the given address. Subsequently, queue bytes for transmission with the
write() function and transmit them by calling endTransmission().
• end Transmission(): This function ends a transmission to a peripheral device that
was begun by beginTransmission() and transmits the bytes that were queued by
write(). As ofArduino 1.0.1, endTransmission() accepts a boolean argument changing
its behavior for compatibility with certain I2C devices. If true, endTransmission()
sends a stop message after transmission, releasing the 12C bus. If false,
endTransmission() sends a restart message after transmission. The bus will not be
released, which prevents another controller device from transmitting between
messages. This allows one controller deviceto send multiple transmissions while in
control. The default value is true.
• Error address: A target address is written to a memory in an electronic system
and subsequently output on an address path through which the memory is
addressable. Anaddressing error is detected by determining whether the target
address output on the address path is detected at the memory.

Output Snapshot:

Dept. of CSE, VKIT 2022-2023 Page 18


INTERNET OF THINGS

PROGRAM 4

12C PROTOCOL
STUDY

12C stands for Inter-Integrated Circuit. It is a bus interface connection protocol incorporated
into devices for serial communication. It was originally designed by Philips Semiconductor in
1982. Recently, it is a widely used protocol for short-distance communication. It is also
known as Two Wired Interface (TWI).

Working of I2C Communication Protocol: It uses only 2 bi-directional open-drain lines for
datacommunication called SDA and SCL. Both these lines are pulled high.
• Serial Data (SDA) - Transfer of data takes place through this pin.
• Serial Clock (SCL) - It carries the clock
signal.12C operates in 2 modes -
• Master mode
• Slave mode
Each data bit transferred on SDA line is synchronized by a high to the low pulse of each
clock onthe SCL line.

According to I2C protocols, the data line cannot change when the clock line is high, it can
change only when the clock line is low. The 2 lines are open drain, hence a pull-up resistor is
required so that the lines are high since the devices on the 12C bus are active low. The data is
transmitted in
Dept. of CSE, VKIT 2022-2023 Page 19
INTERNET OF THINGS

the form of packets which comprises 9 bits.

The sequence of these bits are-


• Start Condition - 1 bit
• Slave Address - 8 bit
• Acknowledge - 1 bit

Start and Stop Conditions:


START and STOP can be generated by keeping the SCL line high and changing the level of
SDA. To generate START condition the SDA is changed from high to low while keeping the
SCL high. To generate STOP condition SDA goes from low to high while keeping the SCL
high, as shown in the figure below.

Repeated Start Condition:


Between each start and stop condition pair, the bus is considered as busy and no master can
take control of the bus. If the master tries to initiate a new transfer and does not want to
release the bus before starting the new transfer, it issues a new START condition. It is called a
REPEATED START condition.

Read/Write Bit:
A high Read/Write bit indicates that the master is sending the data to the slave, whereas a low
Read/Write bit indicates that the master is receiving data from the slave.

Dept. of CSE, VKIT 2022-2023 Page 20


INTERNET OF THINGS

ACK/NACK Bit:
After every data frame, follows an ACK/NACK bit. If the data frame is received successfully
thenACK bit is sent to the sender by the receiver.

Addressing:
The address frame is the first frame after the start bit. The address of the slave with which the
master wants to communicate is sent by the master to every slave connected with it. The slave
thencompares its own address with this address and sends ACK.

12C Packet Format:


In the 12C communication protocol, the data is transmitted in the form of packets. These
packets are 9 bits long, out of which the first 8 bits are put in SDA line and the 9th bit is
reserved for ACK/NACK i.e. Acknowledge or Not Acknowledge by the receiver.

Code:
#include
int ADXLAddress = 0x3C;
#define X_Axis_Register_DATAX0 0X0D
#define X_Axis_Register_DATAXI 0x0E
#define X_Axis_Register_DATAX0 0X0D
#define Y_Axis_Register_DATAX1 0x0E
#define Z_Axis_Register_DATAX2 0x0F
#define X_Axis_Register_DATAX1 0x0E
#define Power_Register 0x2D
X0,X1,X2,X_out;void setup()
{
Wire.begin();
Serial.begin(96
00);
delay(5000);
Wire.beginTransmission (A
DXLAddress);
Wire.write(Power_Register);
(00001000)
Wire.write(8);
Dept. of CSE, VKIT 2022-2023 Page 21
Wire.endTransmission
();}
INTERNET OF THINGS

void loop()
{
Wire.beginTransmission(ADXLAddre
ss);
Wire.write(X_Axis_Register_DATA
X0);
Wire.write(Y_Axis_Register_DATA
XI);
Wire.write(Z_Axis_Register_DATA
X2);

Wire.endTransmission();
Wire.requestFrom(ADXLAddress
,3);if(Wire.available()<=3)
{
XO=Wire.read();
registerX1=Wire.rea
d();X2
Wire.read();}
Serial.print("X0=");
Serial.print(X0);
Serial.print("X1=");
Serial.println(X1);
Serial.print("X2=");
Serial.println(X2);
}

Explanation:

setup() and loop(): After creating a setup() function, which initializes and sets the initial
values, the loop() function does precisely what its name suggests, and loop consecutively,
allowing your program to change and respond. Use it to actively control the Arduino board.

delay(): allows you to pause the execution of your Arduino program for a specified period.
For
Dept.that purpose,
of CSE, VKIT the method requires you to2022-2023
supply it with a whole number that specifies
Page 22
how many milliseconds the program should wait.
INTERNET OF THINGS
serial.begin() and serial.println(): Serial begin is used to establish serial communications.
Serial communication is one way to allow devices to talk to each other. Most often, you'll be
using serial

Dept. of CSE, VKIT 2022-2023 Page 23


INTERNET OF THINGS

begin when you want to print something out to your computer screen from your Arduino.
This would also require the serial print function.

wire header: This library allows you to communicate with I2C/TWI devices. On the Arduino
boards with the R3 layout (1.0 pinout), the SDA (data line) and SCL (clock line) are on the
pin headers close to the AREF pin. The Arduino Due has two I2C/TWI interfaces SDA1 and
SCL1 are near to the AREF pin and the additional one is on pins 20 and 21.

begin Transmission(): This function begins a transmission to the I2C peripheral device with
the given address. Subsequently, queue bytes for transmission with the write() function and
transmit them by calling endTransmission().

end Transmission(): This function ends a transmission to a peripheral device that was begun
by beginTransmission() and transmits the bytes that were queued by write(). As of Arduino
1.0.1, endTransmission() accepts a boolean argument changing its behavior for compatibility
with certain I2C devices. If true, endTransmission() sends a stop message after transmission,
releasing the I2C bus. If false, end Transmission() sends a restart message after transmission.
The bus will not be released, which prevents another controller device from transmitting
between messages. This allows one controller device to send multiple transmissions while in
control. The default value is true.

Output of Snapshot:

Dept. of CSE, VKIT 2022-2023 Page 24


INTERNET OF THINGS

PROGRAM 5

READING TEMPERATURE AND RELATIVE HUMIDITY VALUE


FROM THE SENSOR

Temperature: It is a physical quantity that expresses hot and cold or a measure of the
average kinetic energy of the atoms or molecules in the system. It is the manifestation of
thermal energy, present in all matter, which is the source of the occurrence of heat, the flow of
energy from a hotter body in contact with a colder body. Temperature is measured with a
thermometer, are calibrated in various temperature scales that historically have used various
reference points and thermometric substances for definition. The most common scales are the
Celsius scale (formerly called "centigrade", denoted as °C), the Fahrenheit scale (denoted as
°F), and the Kelvin scale (denoted as K), the last of which is predominantly used for scientific
purposes by conventions of the International System of Units (SI). The lowest theoretical
temperature is absolute zero, at which no more thermal energy can be extracted from a body.
Experimentally, it can only be approached very closely (100 pK), but not reached, which is
recognized in the third law of thermodynamics.

Relative Humidity: Relative humidity of air is defined as the ratio of the vapor pressure of
air to its saturation vapor pressure. The equilibrium relative humidity (ERH) of a food product
is defined as relative humidity of the air surrounding the food that is in equilibrium with its
environment. When the equilibrium is obtained, the ERH (in percent) is equal to the water
activity multiplied by 100, i.e. ERH (%) = aw 100. When a food is exposed to a constant
humidity, the product will gain or lose moisture until the ERH is reached. The moisture
migration significantly affects the physical and chemical properties of the food, as previously
described.
Working of temperature and humidity sensor: Temperature and humidity sensors have
two different ways of collecting data and measuring humidity and temperature. One type
measure Relative Humidity (also known as RH) and the other type measures Absolute
Humidity (also known as AH) smaller purposes and larger ones are usually used for industrial
applications. Some of these sensors are interfaced with a micro-controller for measuring the
related data instantaneously. For example, the DHT11 temperature and humidity sensor is
one of these digital temperature and humidity sensor with Arduino as its interface. It can also
Dept.other
use of CSE, VKITcontrollers such as Raspberry2022-2023
micro- Page 25
Pi, etc. These sensors have capacitive humidity
sensing elements as
INTERNET OF THINGS

well as a thermistor which is used to sense the environment's temperature. There are two
electrodes in the humidity sensing element (capacitor) and a moisture holding substrate works
as a dielectric between these two electrodes. Whenever there is a change in the humidity
levels, changes occur to the capacitance value accordingly. There's an integrated IC in the unit
that receives the measured data and processes the resistance values that have been changed
due to the change in humidity, and converts the data into a digital form for the readers. So,
this is how digital temperature and humidity sensors such as DHT11 measure humidity.

The easiest explanation would be that these sensors use a negative temperature coefficient
thermistor for measuring temperature. When there's an increase in the temperature of the
environment, this element would cause a decrease in its resistance value. Moreover, some
temperature and humidity sensors with display have been designed which provide visual
reporting of the humidity and the temperature and create a better experience for those using
such sensors. Some of the newer temperature and humidity sensors with Wi-Fi have become
popular these days as well that connects over Wi-Fi (or Bluetooth) enabling you to remotely
monitor the humidity and the temperature of the place you've placed the sensor in with the
help of an app that you can install on your phone. These sensors are great for when you are
away and need to monitor the temperature and the humidity of the place. They have pretty
good accuracy too.

Humidity and Sensor applications: As we mentioned above, these sensors can be found in
many devices and they have a wide variety of applications! They can even help the patients
who have trouble breathing by enabling them to keep the humidity and the temperature of the
place at the optimum level. To predict weather conditions, weather stations use these sensors
too. They can be used in heating systems, ventilation systems and even air conditioning
systems. These sensors can also be used for greenhouses where the humidity values should be
checked constantly. Museums can benefit from them as well since the artifacts and the
objects in these places should be kept under certain conditions.

Code:
#includ
e dht
DHT;
#define
DHT11_PIN 7void
Dept. of CSE, VKIT 2022-2023 Page 26
setup()
INTERNET OF THINGS

{
Serial.begin(96
00);void loop()
{
int chk-DHT.read11
(DHT11_PIN);
Serial.print("Temperature = ");
Serial.println(DHT.temperature)
; Serial.print("Humidity = ");
Serial.println(DHT.hmidity);
delay(1000);

Explanation:

setup() and loop(): After creating a setup() function, which initializes and sets the initial
values,the loop() function does precisely what its name suggests, and loops consecutively,
allowing your program to change and respond. Use it to actively control the Arduino board.

delay(): allows you to pause the execution of your Arduino program for a specified period.
For that purpose, the method requires you to supply it with a whole number that specifies
how manymilliseconds the program should wait.

serial.begin() and serial.println(): Serial begin is used to establish serial communication.


Serialcommunication is one way to allow devices to talk to each other. Most often, you'll be
using serial begin when you want to print something out to your computer screen from your
Arduino. This would also require the serial print function.

DHT header: It has all the functions needed to get the humidity and temperature readings
fromthe sensor.

Dept. of CSE, VKIT 2022-2023 Page 27


INTERNET OF THINGS

Output Snapshot:

Dept. of CSE, VKIT 2022-2023 Page 28

You might also like