You are on page 1of 111

Gyan Ganga Institute of Technology & Sciences

Department of
Information Technology

IoT Lab Manual

Subject Code : IT 705

Subject Name : Internet of Things

Roll No. :

Name :

Semester : VIIth Sem

Branch : Information Technology


SESSION : 2021-22
Faculty & Course Details
SEM : VII (odd)

Faculty Details:

Name of the Faculty: Prof. Ratnesh Kumar Jain

Designation: Assistant Professor

Department: Department of Computer Science and Engineering

Course Details:

Name of the Programme : B.Tech. Batch: 2018-22

Branch: Information Technology Semester: VII

Name of Subject: Internet of Things

Subject Code: IT 705

Category of Course: Core Subject


SESSION : 2021-22
Index
SEM : VII (odd)

S. No Topic Page No.


1 Mission and Vision of the Institution 4
2 Mission and Vision of the Department 5
3 Program Education Objectives 6
4 Program Outcomes 7
5 Program Specific Outcomes 8
6 Scheme 9
7 List of Experiment 10
SESSION : 2021-22
Mission and Vision of the
Institution
SEM : VII (odd)

Mission and Vision of the Institution

VISION

Initially to seek autonomy and eventually grow the Institute into a renowned University by:
  Imparting the best technical and professional education to the students of the Institute.
  
Developing all the Departments of the Institute as Centers of Excellence.

 Creating  the most congenial and cordial environment of Teaching, Learning and Research in the
Institute.
 
Conceiving world - class Education, Ethics and Employability for students in global perspective.

MISSION

To explore and ensure the best environment to transform students into creative, knowledgeable,
principled engineers and managers compatible with their abilities in ever-changing socio-
economic and competitive scenario by :
  Imparting intensive teaching and training through latest technology

 Motivating the teachers for higher learning and innovative research activities with social
services.

 Generating maximum opportunities for placement  of students in National, Multi-National
companies and nurturing entrepreneurship quality.


Producing highly intellectual citizens through technical education to constitute an elegant
society and meeting social challenges.
SESSION : 2021-22
Mission and Vision of the
Department
SEM : VII (odd)

Mission and Vision of the Department

Vision

 To be a innovative and research oriented leading education centre in computer science


and engineering.

 To produce skilful and employable computer science graduates to meet upcoming
social challenges with moral and ethics.

Mission



To impart intensive, innovative teaching and training through state of art technology for
 achieving excellence.


for
To associate with industries for identification of social needs and seize opportunities
 software development in live training and sustainable projects of social challenges.

 research, trainings,
Continuous knowledge up-gradation of students, staff,faculty through
 seminars, workshops, conferences, webinars and higher studies.



To impart knowledge of project management, commercial viability and code of conducts
for Engineers.
SESSION : 2021-22
Program Educational
Objectives SEM : VII (odd)

PEO (Program Educational Objectives)

PEO 1 :Graduates will pursue their career in global domain for software development with
proficiency in analysis, design, coding, testing, deployment, maintenance of system and
application software.

PEO 2 :Graduates will demonstrate professionalism with effective communication skills,


leadership qualities, teamwork, ethical, economic, cultural, environmental issues related to
multidisciplinary projects for resolving social issues.

PEO 3 :Graduates will enhance knowledge and skills through higher studies and lifelong
learning new computing technologies for attaining professional excellence and research.

PEO 4 :Graduates will drive scientific and societal advancement through technological
innovation and entrepreneurship.
SESSION : 2021-22
Program Outcomes
SEM : VII (odd)

Program Outcomes:

1. Engineering knowledge: Apply the knowledge of mathematics, science, engineering


fundamentals, and an engineering specialization for the solution of complex engineering problems.
2. Problem analysis: Identify, formulate, research literature, and analyse complex engineering
problems reaching substantiated conclusions using first principles of mathematics, natural
sciences, and engineering sciences.
3. Design/development of solutions: Design solutions for complex engineering problems and
design system components or processes that meet the specified needs with appropriate
consideration for public health and safety, and cultural, societal, and environmental considerations.
4. Conduct investigations of complex problems: Use research based knowledge and research
methods including design of experiments, analysis and interpretation of data, and synthesis of
information to provide valid conclusions.
5. Modern tool usage: Create, select, and apply appropriate techniques, resources, and modern
engineering and IT tools, including prediction and modeling to complex engineering activities, with
an understanding of the limitations.
6. The engineer and society: Apply reasoning informed by the contextual knowledge to assess
societal, health, safety, legal and cultural issues and the consequent responsibilities relevant to the
professional engineering practice.
7. Environment and sustainability: Understand the impact of the professional engineering
solutions in societal and environmental contexts, and demonstrate the knowledge of, and need for
sustainable development.
8. Ethics: Apply ethical principles and commit to professional ethics and responsibilities and norms
of the engineering practice.
9. Individual and team work: Function effectively as an individual, and as a member or leader in
diverse teams, and in multidisciplinary settings
10. Communication: Communicate effectively on complex engineering activities with the
engineering community and with the society at large, such as, being able to comprehend and write
effective reports and design documentation, make effective presentations, and give and receive
clear instructions.
11. Project management and finance: Demonstrate knowledge and understanding of the
engineering and management principles and apply these to one’s own work, as a member and
leader in a team, to manage projects and in multidisciplinary environments.
12. Life-long learning: Recognize the need for, and have the preparation and ability to engage in
independent and life-long learning in the broadest context of technological change.
SESSION : 2021-22
Program Specific
Outcomes SEM : VII (odd)

PSO : Program Specific Outcomes

On successful completion of graduation degree the Computer Science and Engineering


graduates will be able to:

PSO 1- Able to apply the knowledge gained during the course of the program from Mathematics,
Science &Engineering to solve computation task, and ability to understand, analyze, design and
develop computer programs in the areas related to algorithms, system software, multi-media,
web designing, data analytics and networking.

PSO 2- Able to comprehend the technological advancements bylifelong learning and usage of
modern tools foranalysis and design of application and system software with varying complexity.

PSO 3- Able to communicate effectively in oral and written forms with good leadership quality,
team work, managerial skill to work in multi-disciplinary environment,involve in development
ofcommercially viable projects, demonstrating the practice of professional ethics for sustainable
development of society.
SESSION : 2021-22
Course Scheme
SEM : VII (odd)
SESSION : 2021-22
List of Experiment
SEM : VII (odd)

1. Familiarisation with Arduino, Node MCU & Raspberry Pi


2. IoT Sensor Types.
3. Connect & Monitor IoT devices in Cisco Packet Tracer.
4. Adding IoT devices to a Smart Home in Cisco Packet Tracer.
5. Familiarisation with Node Red and perform necessary software installation on Raspbian OS.
6. Home Automation with Node-RED and Raspberry Pi: Control Lights & Read DHT11 Data.
7. Surveillance camera system with Node-Red using Raspberry Pi.
8. Car Plate recognition system with Node-Red using Raspberry Pi.

9. Smart irrigation system with sms & email alert, visualize data on cloud with with Node-
Red using Raspberry Pi.
10. Smart Mirror with Node-Red using Raspberry Pi.
Experiment 1

1. Aim : Familiarisation with Arduino, Node MCU & Raspberry Pi.

Arduino :

Arduino is an 8-bit microcontroller development board with a USB programming interface to connect
to a computer and additional connection sockets to external electronics like sensors, motors speakers,
diodes etc.

It has got both input and output pins, the input pins can be either be digital (0 – 13) or analogue (A0 –
A5), while the output pins are only digital (0 – 13) .

Arduino board design is open source and it also has an open source integrated development
environment which has a cross-compiler, a debugger and a serial monitor to control the inputs and
outputs.

Arduino can either be powered through the USB connection from the computer, from a 9V battery, or
from a power supply .
Raspberry Pi :

Raspberry Pi is a computer-based development board which runs on a Linux distribution referred to as


Raspbian Linux.

It can work and be connected like any computer to a mouse, keyboard, and screen perform computing
functions.

Raspberry Pi B+ board has 32-bit processor, four USB ports, HDMI port, Ethernet port, Audio port,
CSI camera connector, and micro SD card slot.

It also has 40 general-purpose input/output. Raspberry Pi comes in different models, Model 2 lacks an
embedded Wi-Fi but a Wi-Fi adapter can be used via the USB port to get internet connectivity.

New models of Raspberry Pi 3 have integrated Wi-Fi module in its board making it easier to configure
internet connectivity.
Node MCU (ESP8266) :

ESP8266 - Node MCU This is an open source development board with a firmware that runs on
ESP8266 module.

The ESP-8266 module is a wireless programmable microcontroller board.

The ESP8266 WiFi board is a SOC with integrated TCP/IP protocol stack that can give any secondary
microcontroller access to a WiFi network
. The ESP8266 board is capable of either hosting an application or offloading all Wi-Fi networking
functions from another application processor and therefore this is more suitable to be used as a sensing
node that is capable to sense the data from various wirelessly connected IoT sensor nodes and send
data to the central server like.
Experiment 2

Aim : IoT Sensor Types


Sensors are everywhere. They’re in our homes and workplaces, our shopping centers and
hospitals. They’re embedded in smart phones and an integral part of the Internet of Things
(IoT). Sensors have been around for a long time. The first thermostat was introduced in the late
1880s and infrared sensors have been around since the late 1940s.

Broadly speaking, sensors are devices that detect and respond to changes in an environment.
Inputs can come from a variety of sources such as light, temperature, motion and pressure.
Sensors output valuable information and if they are connected to a ne twork, they can share
data with other connected devices and management systems.

1. Temperature Sensors

Temperature sensors measure the amount of heat energy in a source, allowing them to detect
temperature changes and convert these changes to data. Machinery used in manufacturing often
requires environmental and device temperatures to be at specific levels. Similarly, within
agriculture, soil temperature is a key factor for crop growth.

2. Humidity Sensors

These types of sensors measure the amount of water vapor in the atmosphere of air or other
gases. Humidity sensors are commonly found in heating, vents and air conditioning (HVAC)
systems in both industrial and residential domains. They can be found in many other areas
including hospitals, and meteorology stations to report and predict weather.
3. Pressure Sensors

A pressure sensor senses changes in gases and liquids. When the pressure changes, the sensor
detects these changes, and communicates them to connected systems. Common use cases include
leak testing which can be a result of decay. Pressure sensors are also useful in the manufacturing
of water systems as it is easy to detect fluctuations or drops in pressure.

4. Proximity Sensors

Proximity sensors are used for non-contact detection of objects near the sensor. These types of
sensors often emit electromagnetic fields or beams of radiation such as infrared. Proximity
sensors have some interesting use cases. In retail, a proximity sensor can detect the motion
between a customer and a product in which he or she is interested. The user can be notified of
any discounts or special offers of products located near the sensor. Proximity sensors are also
used in the parking lots of malls, stadiums and airports to indicate parking availability. They can
also be used on the assembly lines of chemical, food and many other types of industries.

5. Level Sensors

Level sensors are used to detect the level of substances including liquids, powders and granular
materials. Many industries including oil manufacturing, water treatment and beverage and food
manufacturing factories use level sensors. Waste management systems provide a common use
case as level sensors can detect the level of waste in a garbage can or dumpster.
6. Accelerometers

Accelerometers detect an object’s acceleration i.e. the rate of change of the object’s velocity
with respect to time. Accelerometers can also detect changes to gravity. Use cases for
accelerometers include smart pedometers and monitoring driving fleets. They can also be used as
anti-theft protection alerting the system if an object that should be stationary is moved.

7. Gyroscope

Gyroscope sensors measure the angular rate or velocity, often defined as a measurement of speed
and rotation around an axis. Use cases include automotive, such as car navigation and electronic
stability control (anti-skid) systems. Additional use cases include motion sensing for video
games, and camera-shake detection systems.

8. Gas Sensors

These types of sensors monitor and detect changes in air quality, including the presence of toxic,
combustible or hazardous gasses. Industries using gas sensors include mining, oil and gas,
chemical research andmanufacturing. A common consumer use case is the familiar carbon
dioxide detectors used in many homes.

9. Infrared Sensors

These types of sensors sense characteristics in their surroundings by either emitting or detecting
infrared radiation. They can also measure the heat emitted by objects. Infrared sensors are used
in a variety of different IoT projects including healthcare as they simplify the monitoring of
blood flow and blood pressure. Televisions use infrared sensors to interpret the signals sent from
a remote control. Another interesting application is that of art historians using infrared sensors to
see hidden layers in paintings to help determine whether a work of art is original or fake or has
been altered by a restoration process.

10. Optical Sensors

Optical sensors convert rays of light into electrical signals. There are many applications and use
cases for optical sensors. In the auto industry, vehicles use optical sensors to recognize
signs, obstacles, and other things that a driver would notice when driving or parking. Optical
sensors play a big role in the development of driverless cars. Optical sensors are very common in
smart phones. For example, ambient light sensors can extend battery life. Optical sensors are also
used in the biomedical field including breath analysis and heart -rate monitors.
Experiment 3

Aim : Connect & Monitor IoT devices in Cisco Packet Tracer.

The Smart Home Network

Objectives
Part 1: Add Home Gateway to the Network
Part 2: Connect IoT Devices to the Wireless Network
Part 3: Add End User Device to the Network

Background / Scenario
In this activity you will add a Home Gateway and several IoTdevices to an existing home network
and monitor those devices through the Home Gateway.

Part 1: Connect a Home Gateway to the Network


Step 1: Adding a home gateway
a. Select the Home Gateway device.
Click the Wireless Devices icon in the Device-Type Selection box. Click the Home
Gateway device icon and then click in the Logical workspace to add the device.
b. Connect the Home Gateway to the Cable Modem.

Click the Copper Straight-Through connector icon in the Device-Type Selection box,
then click the Home Gateway to add one end of the cable to the gateway. Next, click the
Cable Modem icon to connect the other end of the cable to the Internet port.

After a few seconds both ends of the cable should have green lights indicating that the link
is up.

Part 2: Connect IoT Devices to the Wireless Network


Step 1: Select wireless devices
a. Click the Home Devices icon in the Device-Type Selection box and add the Fan, the
Door, and the Lamp to the workspace.
Step 2: Add devices to the home wireless network
a. Add a wireless adapter to the Fan device.
Click the Fan icon in the workspace to open the Config tab and then click the Advanced
button in the bottom right corner of the window. Notice that the tabs at the top of the
configuration window change. There are now more tabs.
Click the I/O Config tab and change the Network Adapter type to the PT-IOT-NM-
1W wireless adapter.

b. Change the display name of the Fan device.


Click the Config tab. In the Display Name box, type Ceiling Fan.
c. Verify that the Fan device is connected to the wireless network.
While still in the Config tab, click the Wireless0 interface in the left pane.
In the configuration settings, the HomeGateway network should be listed in the SSID
box. Verify that the DHCP is selected in the IP Configuration settings, the IP address is
192.168.25.100 and the default gateway is 192.168.25.1. This indicates that the fan is
connected to the network and is receiving IP configuration information from the home
gateway.

Close the Ceiling Fan configuration window.

d. Connect the Door and the Lamp to the wireless network following the same steps used
for the fan.
Part 3: Add a Wireless Tablet to the Network
Step 1: Add the wireless tablet to the workspace
a. Click the End Devices icon in the Device-Type Selection box and add the Wireless Tablet
to the workspace.

Step 2: Connect the wireless tablet to the HomeGateway network


a. Change the wireless tablet network settings.
Click the Tablet icon to open the Tablet configuration window.
Click the Config tab and then click the Wireless0 Interface. Change the SSID from Default
to HomeGateway. After the network SSID is changed the Tablet should learn an IP
address through DHCP within a few seconds.

b. Access the home gateway IoT server from the tablet.


Click the Desktop tab and then click the Web Browser icon to open a Web browser.
Type192.168.25.1 (the address of the home gateway) in the URL box and click Go.
At the Home Gateway Login page, enter admin as the username and admin as
the password and click the Submit button to connect to the Home Gateway server.
Note that no devices appear in the Home Gateway IoT Server - Devices list.
Close the Tablet window.

Step 3: Configure IoT devices to register with the Home Gateway server
a. Register the ceiling fan to the home gateway server.
Click the Fan icon in the workspace, click the Config tab, and then click Settings in the left
pane. At the IoT Server options list, click the Home Gateway button.

Close the Ceiling Fan window.


Repeat the steps in 3a to register the Door and the Lamp devices to the home gateway.

b. Verify that the devices are now registered with the Home Gateway server.
Click the Tablet icon in the workspace and open the Web Browser. Connect to the
Home Gateway by typing 192.168.25.1 in the URL box and then click Go. Enter admin
as the username and password and click Submit.
After a few seconds all three devices should be listed in the Home Gateway IoT Server -
Devices list.

Close the Tablet Window.


Experiment : 4

Aim : Adding IoT devices to a Smart Home in Cisco Packet Tracer.

The Smart Home Network

Objectives
Part 1: Explore the Existing Smart Home Network
Part 2: Add Wired IoT Devices to the Smart Home Network
Part 3: Add Wireless IoT Devices to the Smart Home Network

Background / Scenario
In this activity you will open a Packet Tracer file with an existing home network, explore the devices
on the network and then add additional wired and wireless IoT devices.

Part 4: Explore the Existing Smart Home Network


Step 1: Open the Smart_Home_Network.pkt file
a. Open the Smart_Home_Network.pkt file.
b. Save the file to your computer.
Step 2: Explore the Smart Home Network
a. Explore IoT end devices.
At the bottom left corner of the Packet Tracer window, locate and click the [End Devices] icon in
the top row, and the [Home] icon in the bottom row of the Device-Type Selection box.
Across the bottom of the Packet Tracer window, the Device-Specific Selection box displays
the many different Smart Home IoT devices available.
Move the mouse pointer over each device and notice that the descriptive name of the device
is displayed at the bottom of the Device-Specific Selection box. Take a moment to look at
each device type.

b. Explore the Smart Home network.

In the Logical workspace is a pre-built smart home network that consists of many wired
and wireless IoT devices, and network infrastructure devices.
When you place your curser over a device, such as the Smart Fan, an informational window
opens containing basic network information about that device.
To turn on or activate a device, simply hold down the Alt key on the keyboard and then left-
click the device. Try this on each of the smart devices to observe what they do.
The smart home network also consists of infrastructure devices such as a home gateway.
Click the Home Gateway icon to open the Home Gateway window.

The Physical tab is selected by default and shows a picture of the Home Gateway.
Next, click the Config tab and then in the left pane click LAN to view the LAN Settings of
the Home Gateway.
Write down the IP Address of the home network for future reference. ___________________

Click Wireless in the left pane to view the wireless settings of the Home Gateway.

Write down the SSID of the home network _______________ and the WPA2-PSK Pass Phrase
______________ for future reference.
Close the Home Gateway window.

Next, click the Tablet device icon to open the Tablet window.

In the Tablet window, select the Desktop tab and then click the Web Browser icon.
In the Web Browser window, type the IP address of the Home Gateway 192.168.25.1 into the
URL box and click Go. In the Home Gateway Login screen, type admin for both the username
and the password and click Submit.
After you have connected to the Home Gateway web interface, a list of all the connected
IoT devices appears.
When you click a device in the list, the status and settings of that device is displayed.
Close the Tablet window.

Part 5: Add Wired IoT Devices to the Smart Home Network


Step 1: Cable a device to the network
a. In the Device-Specific Selection box, click the Lawn Sprinkler icon and then click in
the workspace where you would like to locate the Lawn Sprinkler.

b. Cable the Fire Sprinkler to the Home Gateway.


In the Device-Type Selection box, click the [Connections] icon (this looks like a lightning bolt).
Click the Copper Straight Through connector type icon in the Device-Specific Selection box.
Then click the Sprinkler icon and connect one end of the cable to the Sprinkler’s
FastEthernet0 interface. Next, click the Home Gateway icon and connect the other end of the
cable to an available Ethernet interface.
Step 2: Configure the sprinkler for network connectivity

c. Click the Lawn Sprinkler device icon in the workspace to open the device window. Notice
that right now the name of the Lawn Sprinkler is a generic IoT0.

The device window will open to the Specification tab which gives information about the
device which can be edited.
d. Click the Config tab to edit the device configuration settings.
In the Config tab, make the following changes to Settings:
 Set the Display Name to Sprinkler1 (notice the window name changes to Sprinkler1)

 Set the IoT Server to Home Gateway
Click FastEthernet0 and change the IP Configuration to DHCP.
Close the Sprinkler1 window.

e. Verify that the sprinker is on the network. Log


into the Home Gateway from the Tablet.

The device Sprinkler 1 should now appear in the IoT Server – Devices list.
Close the Tablet window.

Step 3: Experiment by adding other types of IoT devices to the smart home network.
Add Wireless IoT Devices to the Smart Home Network

Step 1: Add a wireless device to the network


f. In the Device-Specific Selection box click the Wind Detector icon and then click in the
workspace where you would like to locate the Wind Detector.
Device-Specific selection
g. Add wireless module to the Wind Detector.
Click the Wind Detector icon in the workspace to open the IoT device window. In the bottom right
corner of the IoT device window, click the Advanced button. Notice more tabs become visible at
the top of the window. Click the I/O Config tab.

Change the Network Adapter drop down list to PT-IOT-NM-1W, which is a wireless adapter.

h. Configure the Wind Detector for the wireless network.


Click the Config tab.
Change the Display Name to Wind_Detector and change the IoT Server to Home Gateway.
Next click Wireless0 in the left pane. Change the Authentication type to WPA2-PSK and in
the PSK Pass Phrase box type mySecretKey. These are the wireless settings from the Home
Gateway that you recorded in Part 1.
A wireless connection should be formed between the Wind Detector and the Home Gateway.
i. Verify the Wind Detector is on the network. Log
into the Home Gateway from the Tablet.

The device Wind Detector should now appear in the IoT Server – Devices list.
Close the Tablet window.
Step 2: Experiment by adding other types of IoT devices to the smart home
wireless network.
Experiment : 5

Aim : Familiarisation with Node Red and perform necessary software installation on Raspbian OS.

Node-RED is a programming tool for wiring together hardware devices, APIs and online services in
new and interesting ways.
It provides a browser-based editor that makes it easy to wire together flows using the wide range of
nodes in the palette that can be deployed to its runtime in a single-click.

Browser-based flow editing

Node-RED provides a browser-based flow editor that makes it easy to wire together flows using
the wide range of nodes in the palette. Flows can be then deployed to the runtime in a single-
click.

JavaScript functions can be created within the editor using a rich text editor.

A built-in library allows you to save useful functions, templates or flows for re-use.

Built on Node.js

The light-weight runtime is built on Node.js, taking full advantage of its event-driven, non-
blocking model. This makes it ideal to run at the edge of the network on low-cost hardware
such as the Raspberry Pi as well as in the cloud.

With over 225,000 modules in Node's package repository, it is easy to extend the range of
palette nodes to add new capabilities.
Node-RED is built on Node.js, taking full advantage of its event-driven, non-blocking model. This
makes it ideal to run at the edge of the network on low-cost hardware such as the Raspberry Pi
as well as in the cloud.

Running on Raspberry Pi

Installing and Upgrading Node-RED

Running the following command will download and run the script. If you want to review
the contents of the script first, you can view it here.

bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-


installers/master/deb/update-nodejs-and-nodered)

This script will work on any Debian-based operating system, including Ubuntu and Diet-Pi. You
may need to run sudo apt install build-essential git first to ensure npm is able to build any
binary modules it needs to install.

This script will:

 remove the pre-packaged version of Node-RED and Node.js if they are present

install the current Node.js LTS release using the NodeSource. If it detects Node.js is
already installed from NodeSource, it will ensure it is at least Node 8, but otherwise
leave it alone
 install the latest version of Node-RED using npm
 optionally install a collection of useful Pi-specific nodes

 setup Node-RED to run as a service and provide a set of commands to work with
the service

Node-RED has also been packaged for the Raspbian repositories and appears in their list
of 'Recommended Software'. This allows it to be installed using apt-get install nodered
and includes the Raspbian-packaged version of Node.js, but does not include npm.

While using these packages is convenient at first, we strongly recommend using our install
script above instead.
Running locally

As with running Node-RED locally, you can use the node-red command to run Node-RED in a
terminal. It can then be stopped by pressing Ctrl-C or by closing the terminal window.

Due to the limited memory of the Raspberry Pi, you will need to start Node-RED with an
additional argument to tell the underlying Node.js process to free up unused memory sooner
than it would otherwise.

To do this, you should use the alternative node-red-pi command and pass in the max-old-
space-size argument.

node-red-pi --max-old-space-size=256

Running as a service

The install script for the Pi also sets it up to run as a service. This means it can run in
the background and be enabled to automatically start on boot.

The following commands are provided to work with the service:

 node-red-start - this starts the Node-RED service and displays its log output.

Pressing Ctrl-C or closing the window does not stop the service; it keeps running in the
background
 node-red-stop - this stops the Node-RED service
 node-red-restart - this stops and restarts the Node-RED service
 node-red-log - this displays the log output of the service

You can also start the Node-RED service on the Raspbian Desktop by selecting the Menu ->
Programming -> Node-RED menu option.

Autostart on boot

If you want Node-RED to run when the Pi is turned on, or re-booted, you can enable the service
to autostart by running the command:

sudo systemctl enable nodered.service

To disable the service, run the command:

sudo systemctl disable nodered.service


Opening the editor

Once Node-RED is running you can access the editor in a browser.

If you are using the browser on the Pi desktop, you can open
the address: http://localhost:1880.

When browsing from another machine you should use the hostname or IP-address of the
Pi: http://<hostname>:1880. You can find the IP address by running hostname -I on the Pi.

http://192.168.1.1:1880
Experiment : 6

Aim : Home Automation with Node-RED & Raspberry Pi, Control Lights & Read DHT11 Data.
Node-RED is a visual tool for non-programmers to work with the IoT, it can be used to build
applications faster and reduce the “go-to-market” time for IoT products. It can also be used to
easily interface hardware devices, APIs, and other online services together in new and interesting
ways.
Node-RED can directly access data from microcontroller boards like Arduino, Raspberry Pi
using the predefined port number or pin number.
In this lab, we are going to build a Home Automation System that can control lights and can
monitor temperature and humidity graphically on gauge created on the Dashboard.
Components Required for Home Automation using Node-Red

  Raspberry Pi
  Relay Module
  DHT11 Sensor
  AC Bulb
  LED
  Breadboard
 Jumper Wires

Install Node-RED on Raspberry Pi


Node-RED comes pre-installed on the Raspbian Stretch OS. In case you don’t have Node-RED
installed on your Pi, you can use the command given below to install Node.js, npm, and Node-
RED onto a Raspberry Pi. This command can also be used to upgrade an existing installation.

bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-


installers/master/de b/update-nodejs-and-nodered)
The command will do the following things:

1. Remove the old version of Node-RED and Node.js if present.


2. Install the latest Node.js LTS version. If it detects Node.js is already installed, it will
ensure that it is at least Node version 8.
3. Clean out npm cache
4. Install the latest version of Node-RED using npm
5. Ask if you want to install a collection of useful Raspberry Pi nodes
6. Will set up Node-RED to run as a service and provide a set of commands to work with
the service

When the installation completes, you should see the Node-RED icon under the programming
apps list.

Starting Node-RED on Raspberry Pi


Node-RED can be either launched via Pi’s Desktop Interface or via Raspberry Pi terminal
window.
From the Pi’s Desktop Interface: Select Menu -> Programming -> Node-RED

Remotely from your Computer’s Terminal: Run node-red-start in a new Raspberry Pi terminal
window. To launch from the Pi’s Desktop Interface, click on Menu > Programming > Node-
RED.

To launch it from the Raspberry Pi Terminal window, navigate to Terminal and enter the
command given below:

node-red-start
Opening the Node-RED Interface
With Node-RED now installed and started up on Raspberry Pi, we can proceed to access its web
interface. For that, navigate to the browser and write http://your_pi_ip-address:1880 in the
address bar. Raspberry Pi IP address is shown in the first mainline of the Node-RED terminal
as shown below.
After this, you will be greeted with the following screen.
Before we start building the Node-Red flows, we need to install the palette for the Dashboard
and DHT11 sensor in node-red. For that, click the menu icon in the top right corner, and then
click on “Manage Palette”
Go to the Install tab, and then search and install ‘node-red-dashboard’ and 'node-red-contrib-
dht-sensor’ nodes.
Creating a Flow in Node-RED
With all the required nodes installed, we can proceed with creating a Node-red flow to control
an LED and read DHT11 sensor data. The first step is to create a dashboard layout.
In this project, we’ll have two switches to control an LED and bulb; two gauges to display
temperature and humidity values. In the top right corner, click on the dropdown menu icon, and
select the dashboard tab.
Then create a tab called ‘Home Automation’ and inside this tab, create two groups: Office and
DHT, as shown below.
Now, go to the Dashboard tab and drag the Switch node into the flow section.
Now, double-click on the Switch node to edit it. Rename the Switch node as LED. Add Name of
Group “Home Automation” for grouping the node.
Then go to the Raspberry Pi tab and drag the ‘rpi gpio out’ node into the flow section.
Then double-click on the node, select the GPIO18 pin, and select ‘Digital Output’ as the output
type.
Follow the same procedure for adding another switch.
Now in the next step, add nodes to read DHT11 sensor data. For that, go to the Common node
palette and drag the inject node to the flow. Double click on the inject node and then set the
interval to every 1 second.

Then go to the Raspberry Pi tab and drag the rpi-dht22 node to the flow.
Double click on the rpi-dht22 node and then select the DHT11 as sensor module and 4 in a pin
number.

Now, in the next step, go to the Function tab and drag two functions nodes to the flow as shown
below.
Double click on the function, rename it to Temperature, and then add a line to get only
temperature data. Do the same for the second function node to get humidity data.

Now, in the next step, go to the Dashboard tab and drag two gauge nodes to the flow as shown
below.
Double click on nodes to configure them. You can specify the following, as seen in the picture
here:

The final flow will look like this:


With this done, we are now ready to deploy the project. Click the Deploy button in the top right
corner.

Now, to see how the Node RED dashboard looks, go to http://your-pi-ip-address/ui.


Raspberry Pi Home Automation using Node-Red
Circuit Diagram
The circuit diagram for Node-RED Home Automation is given below:
The LED is connected to the GPIO18 pin while the input pin of the relay is connected to the
GPIO24 pin of Raspberry Pi. The data pin of DHT 11 is connected to GPIO4.
With this done, go to Node-RED Dashboard to control the LED and Bulb.
This is how you can turn on lights and monitor sensors on Raspberry Pi using Node-RED.
Experiment : 7

Aim : Surveillance camera system with Node-Red using Raspberry Pi.

Raspberry Pi Board
Raspberry Pi Camera V2 Module
MicroSD Card – 16GB Class10
Raspberry Pi Power Supply (5V 2.5A)


Connect the Raspberry Pi Camera Module

With the Pi shutdown, connect the camera to the Pi CSI port as shown in the following
figure. Make sure the camera is connected in the right orientation with the ribbon blue
letters
 facing up.



















Enable the camera
To use the Raspberry Pi Camera module, you need to enable the camera software in
your Raspberry Pi. In the Desktop environment, go to the Raspberry Pi Configuration
window under the Preferences menu, open the Interfaces tab and enable the Camera
as shown in figure below.

Or, in the Terminal window, type the following command:


pi@raspberry:~ $ sudo raspi-config
You should see the Raspberry Pi software configuration tool. Select the Interfacing
Options:

Enable the camera and reboot your Pi:


Installing the Raspberry Pi Camera node

To install the Raspberry Pi Camera node on Node-RED, enter the following command:

pi@raspberry:~ $ sudo npm install -g node-red-contrib-camerapi

Choosing the photos directory

You need to chose a directory where the photos will be temporarily saved. For that you
need to edit the settings.js file. Try one of the following commands because your
Node-RED directory installation may be different.
pi@raspberry:~ $ sudo nano /root/.node-
red/settings.js or

pi@raspberry:~ $ sudo nano ~/.node-red/settings.js

Then, scroll down the file, find the httpStatic setting, uncomment and type your desired
directory to store the Raspberry Pi Camera photo. Take a look at the figure below.
httpStatic: '/home/pi/Pictures/',
When you’re done, exit and save the changes.

Start Node-RED

To start Node-RED, enter the following in the Terminal window:


pi@raspberry:~ $ sudo node-red start
To access Node-RED, open a tab in any browser on the local network and type the
following:

http://Your_RPi_IP_address:1880
You should replace Your_RPi_IP_address with your Raspberry Pi IP address. If you
don’t know your Raspberry Pi IP address, in the Terminal enter:
pi@raspberry:~ $ hostname -I

Node-RED Dashboard

You need to create a tab and a group on Node-RED to add your dashboard widgets.
Follow the next instruction to create a tab and a group (see figure below):

 On top right corner of the Node-RED window you have a tab called dashboard.
 Select that tab (1). To add a tab to the user interface click on the +tab button (2).
 Once created, you can edit the tab by clicking on the edit button (3).
You can edit the tab’s name and change its icon:

 Name: you can call it whatever you want


 Icon: you should use a name accordingly to the icon’s names in this
link: https://klarsys.github.io/angular-material-icons

Creating the Node-RED Flow

Before creating the flow, make sure you have the camerapi takephoto node, as show
in the figure below. If you don’t have the node, check that you’ve followed the
instructions above in the Installing the Raspberry Pi Camera node section.
First, drag 3 nodes into the flow: template, camerapi takephoto and debug.

Template node
Then, edit the template node, as shown in the figure below – copy and paste the
template code below the figure.
<script>

var value = "1";

// or overwrite value in your callback function ...


this.scope.action = function() { return value; }

function updateF() {

var source = '/photo1.JPEG',

timestamp = (new Date()).getTime(),

newUrl = source + '?_=' + timestamp;

document.getElementById("photo").src = newUrl;

</script>

<md-button ng-click="send({payload:action()})" onclick="setTimeout(updateF,


2500);" style="padding:40px; margin-bottom: 40px;" >

<ui-icon icon="camera"></ui-icon>

Take a photo<br>

</md-button>

<div style="margin-bottom:40px;">

<img src="/photo1.JPEG" id="photo" width="100%" height="100%">

</div>

This JavaScript code automatically updates the Node-RED page when a new photo is
taken.

Camerapi Takephoto node


Finally, edit the camerapi takephoto node with the following properties:
Note 1: don’t forget to add the right File Path to your node including the last
forward slash – /home/pi/Pictures/
Note 2: every time you open the camerapi takephoto node, it will change
the file default path to yes. So, make sure you select the right properties,
every time you open the node.
Note 3: when you take a new photo, it will be saved on your chosen directory with the
name photo1.JPEG. Every time you take a new photo, Node-RED overwrites the
existing photo because they have the same name.

Wiring the nodes


Connect the nodes as shown in the figure below.

Lastly, press the Deploy button to save all the changes.

Node-RED UI

Your Node-RED application is ready. To access the UI, you can use any browser
in your local network when you type:

http://Your_RPi_IP_address:1880/ui
Troubleshooting
1) If your image is not being displayed on the Node-RED UI, you can go the following
URL and see if your httpStatic path was set properly:

http://Your_RPi_IP_address:1880/photo1.JPEG
2) If the Pi Camera is not taking photos, double-check that the camera ribbon is well
connected to your Pi’s CSI port. Also confirm that it’s enabled in your Pi’s raspi-config
menu.

3) Open the camerapi takephoto node and ensure that it has the right file path.
Experiment : 8

Aim : Car Plate recognition system with Node-Red using Raspberry Pi.

In this lab you are going to learn how to build a car recognition system using a Raspberry Pi and
Node-RED. For this lab we will be using a software called OpenALPR (Automatic License Place
Recognition) that has an API you can use to identify car plates and car models based on an
image.

Overview

This project is divided into two parts.

1. First, we’ll identify a car using OpenALPR and Node-RED;


2. Then, we’ll trigger an event based on the detected car (for example, open the garage
when it detects that your car arrived home);
The following image shows how the detection process will work:
In this example, we use a PIR motion sensor to detect that the car arrives home. There are
other sensors that may be more suitable to detect a car, for example:

 Hall effect sensor: senses changes in magnetic field when the car is near;
  Ultrasonic sensor: detects distance to an object;
 Active infrared detectors: detects the presence of an object by detecting the reflection
of infrared light.
When the sensor detects motion, the Raspberry Pi camera takes a photo. After that, the Pi sends a
request to OpenALPR with the car photo to be identified. Then, the OpenALPR API returns the
car details like: plate number, model, color, and the confidence of the results.

After identifying a car, we’ll do some verifications, and if we found an authorized car, we’ll
trigger an event (that can be open the garage, for example). The following image contains a
flowchart showing the process.
Here’s what happens: after the car has been identified by OpenALPR, we’ll check if the license
plate and the car model match. If they match, we’ll check if the car is in the list of authorized
vehicles. If it is, we’ll trigger an event. For example: open the garage. After that, we wait a
determined period of time until the car enters the garage. Then, you need to add several
verifications to check if the car has already entered the garage. If yes, you can close the garage.
 Raspberry Pi Board
Raspberry Pi Camera V2 Module
MicroSD Card – 16GB Class10
Raspberry Pi Power Supply (5V 2.5A)
Mini PIR Motion Sensor or PIR Motion Sensor
LED
Resistor (220 or 330 ohms should work)
Breadboard
Jumper wires


Connect the Raspberry Pi Camera Module

With the Pi shutdown, connect the camera to the Pi CSI port as shown in the following figure.
Make sure the camera is connected in the right orientation with the ribbon blue letters facing
up (you need to enable the camera in your Raspbian OS).
You should also have Node-RED installed in your Pi and the node-red-contrib-camerapi node
Installed:

Schematics

Assemble the circuit to test this project. Follow these next schematic diagram:
After having your Raspberry Pi prepared and Node-RED software configured, you can continue
with this project.

OpenALPR
OpenALPR is an open source Automatic License Plate Recognition library written in C++ with
bindings in C#, Java, Node.js, Go, and Python. They also have the OpenALPR Cloud API which
is a web service running in the cloud that analyzes images of vehicles and responds with license
plate, model, color and much more. OpenALPR Cloud API has a free service that allows up to
2000 free recognitions per month.
Note: instead of using their Cloud API that is limited to only 2000 recognitions per month, you
can install their Open Source software and use their Python integration to write Python scripts to
analyse unlimited images. That way you don’t need to use their cloud service and you aren’t
restricted to 2000 requests per month.

Supported countries
Creating a free account
To get started with OpenALPR Cloud API, you can create a free account. After completing
your account creation, you should have access to the following page:

Open the Cloud API tab to access your Secret Key. You need it to make requests to the API.
In my case, the secret key is: sk_8081041caedd50a———
Save your secret key in a safe place, because you’ll need it in just a moment.

Testing the Camera and OpenALPR Service

First, you should start by identifying your car using the Pi Camera and the OpenALPR service.
So, start with the provided sample flow that takes a photo and makes a request to the OpeALPR
Cloud API to identify your car.

Next, in the Node-RED window, at the top right corner, select the menu, and go
to Import > Clipboard.
Then, paste the code provided and click Import. The next nodes should show up in your flow:

Configuring the test flow


After importing the flow, you need to make some changes to make it work for you. Open
the Take Photo node:

Edit the node to have the same settings as shown in the next figure:

 File Name: car-photo.jpeg


 File default path: No
 File Path: /home/pi/Pictures/
Important: sometimes the previous node might overwrite the default setting. Make sure
you double-check that it has the right settings. Then, click the deploy button.

Preparing your OpenALPR Cloud API request


Double-click the cURL POST node:

Then, change the Command field to include your Secret Key and country code:

By default, it should have this command:

sudo curl -X POST


"https://api.openalpr.com/v2/recognize?secret_key=YOUR_SECRET_KEY&recognize_vehicl
e=1&country=YOUR_COUNTRY_CODE&return_image=0&topn=10" -F
image=@/home/pi/Pictures/car-photo.jpeg
Add your secret key that you’ve retrieved earlier and your country code:

sudo curl -X POST "https://api.openalpr.com/v2/recognize?secret_key=sk_8081041caedd50a---


------&recognize_vehicle=1&country=eu&return_image=0&topn=10" -F
image=@/home/pi/Pictures/car-photo.jpeg
Note: EU is not a country, but if you live in any country in Europe, you use the EU country
code.
Copy and paste your exact command in the in the Command field of the cURL POST node
and press the Deploy button in your Node-RED software for all the changes to take effect:
Testing the flow
After deploying the flow, let’s test the car identification process. Move your car to a place
that you can take a photo with your Raspberry Pi:

Point the camera to the car and tap the square next to the timestamp node to trigger the flow.

That should take a photo with your Pi Camera, save it at /home/pi/Pictures/car-photo.jpeg and
make a request to the cloud API to identify your car plate and model. It should print the JSON
response in the Debug window.

Understanding the response


Open the debug window, and you should see an object with all the details about the JSON
response. The results array should have at least one result (array[1]), otherwise it might
be analyzing a photo without a car or it couldn’t identify the car (make sure the Pi Camera
is pointed to the car while you take the photo).
Click the arrow next to the results: array[1] to expand the object. You should see a plate object
with your car plate. Save the car plate in the format retrieved by the API. In my case it’s
“61CP– “. You’ll need it later to identify your car:
Expand the vehicle object > make_model > 0: object and you should see the name of your car
and how the API identified the car model. In our case it identified the car as a Toyota Yaris
with 77,2% confidence. We should save the exact string “toyota_yaris” retrieved by the API,
because we need it for the next flow. Save your car model in the format retrieved by the API.
Experiment : 9

Aim : Smart irrigation system with Node-Red using Raspberry Pi.


 industry in the world; however it also poses one of the biggest threats
Agriculture is the largest
to the environment.


According to the World Wildlife Foundation (WWF), agriculture wastes 60% or 1,500 trillion

  trillion litres of water it uses each year- which is 70% of the world‟s
litres, of the 2,500
accessible water.
 
One of the main culprits is inefficient water irrigation systems.

Smart Agriculture irrigation system can :

- simplify home lawn and agriculture fields irrigation.

- reduce water consumption help farmers get the most out of their crops.

- With the help of our system we can check or adjust irrigation at anytime - from home, work
station or away.

- Receive alerts.

- Schedules for rain, snow or seasonal changes.

The main aim of the Smart Irrigation System are:


To develop a smart irrigation systemin order to reduce the time & consumption of water used
to irrigate the gardens/Farmfield’s


  irrigation scheduling system with its unique Soil-Moisture Model for optimal water
Intelligent
use.
 
To develop a system in order to reduce the manual efforts.



Easy-to-use Smartphone and Web Apps to support crop irrigation decisions with real-time
data.
The Smart Agriculture system fulfils the following performance objectives, to ensure its
widespread uptake by growers and irrigators:

- Intelligent irrigation scheduling system with its unique Soil-Moisture Model for optimal water
use.

- The system is modular and flexible

- The system is cost effective to ensure its widespread uptake by farmers, Lower operating costs.

Solution :

- The sensors that measure soil water content , environmental parameters and send readings
across a IoT gateway (Raspberry Pi 3) which sends all of this data to a central web service .

- Central web service which uses an intelligent software application to automatically analyse
the data and act upon it by selectively activating irrigation nodes only in the areas required.

- This data is fed into an intelligent software package that uses intelligent agents in order to
act upon the information they are receiving from the sensors. The outputs and irrigation
recommendations are presented to the user on a Smartphone App or Web Browser.
Architecture
In this lab we are using raspberry pi as gateway, The gateway is a key component of every IoT
solution. An IoT gateway device bridges the communication gap between IoT devices, sensors,
equipment, systems and the cloud.

Raspberry Pi 3 :
 
Irrigation performed at a given date and time through web or mobile application.


Automated irrigation with a fixed duration, 
when soil moisture, humidity sensors value
get low at the programmed threshold level.

Irrigation controller with weather

forecasting. How Module works :
 
 Step 1: Start.
 
 Step 2: Initialize the system on Raspberry Pi.


Step 3: The soil moisture sensor checks the soil moisture level & temperature andhumidity
 checks the temperature and humid values constantly & feeds to the raspberry pi
 
 Step 4: Raspberry pi compare the sensor input and the threshold value


 get
Step 5: If the sensors input value is less than given threshold values, plants
watered(for 30 minutes) or else it continues to read the sensor values


 the temperature and humidity of the field
Step 5: The DHT11 sensor constantly senses
 and updates the data in the web server.


  surveillance
Step 6: The USB camera installed with the Raspberry Pi gives the complete
of the field and this can be monitored in the internal network system.
 
Step 7: If the step 5 is completed, it will go to the step 3.
Experiment : 10
Aim : Magic Mirror
Magic Mirror is an open source modular smart mirror platform. With a growing list of installable modules, the
Magic Mirror allows you to convert your hallway or bathroom mirror into your personal assistant.

Requirements :

Hardware

Magic Mirror is developed to run on a Raspberry Pi 3.

Operating System : Raspbian

Installation :

1. Download and install the latest Node.js version:

 curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -


 sudo apt install -y nodejs

2. Clone the repository and check out the master branch: git clone
https://github.com/MichMich/MagicMirror
3. Enter the repository: cd MagicMirror/
4. Install the application: npm install
5. Make a copy of the config sample file: cp config/config.js.sample config/config.js
6. Start the application: npm run start
For Server Only use: npm run server .

Enable VNC

Install x11vnc:

sudo apt-get install x11vnc


Set VNC password:

x11vnc -storepasswd
Create an auto-start file:

cd ~/.config
mkdir autostart
cd autostart
nano x11vnc.desktop
Modules

The following modules are installed by default :

Clock
Calendar
Current Weather
Weather Forecast
News Feed
Compliments
Hello World
 Alert

You might also like