Unit 3 FIoT Notes
Unit 3 FIoT Notes
Introduction:
Generally, prototypes or real-life Internet of Things (IoT) systems have to be designed and
developed swiftly and competently. Whenever this occurs, two activities instantly come to
life: One is to program the IoT devices, and another is to organize a backend to interact with
these devices. In both activities, we can utilize the Python programming language for their
development. Or we can utilize a functional and practical edition of MicroPython in order to
work on devices with small computing resources, and accordingly, at a very low price. In the
following tutorial, we will understand the use of Python in programming Internet of Things
(IoT) devices and create a backend for them to work. But before we get to that, let us briefly
discuss the importance of IoT. Understand the importance of the Internet of Things The term
"Internet of Things" was first coined in the year 1999 by Kevin Ashton. Ever since the
importance and scale of IoT have exploded, one of the chief indicators is that the market size
of the IoT was $151 billion in 2018, with a steady increment year after year. As per the
predictions of marketers, the IoT market could cross the $561 billion mark by 2022. Back in
the day, we could explain IoT with examples as shown below: "We can utilize the phone to
turn a light bulb on and off in the room." Nowadays, hardly anyone would be amazed by a
smart electricity meter that transmits readings of the consumption of the electricity, uploads
that information to the cloud, and produces monthly bills sent directly to the e-mail. IoT is
increasingly utilized across industries in order to streamline processes and make them more
efficient. For instance, manufacturing production lines and agriculture are great examples of
various industries taking benefit of the different features of IoT. In the particular scenario of
agriculture, IoT helps in coordinating harvesters with trucks that have elevators to handle
grains efficiently.
The basic set up for Raspberry Pi includes HDMI cable, monitor, keyboard, mouse, 5volt
power adapter for Raspberry Pi, LAN cable, 2 GB micro-SD card (minimum). The official
operating systems supported are Raspbian and NOOBS. Other third-party operating
systems like Ubuntu mate, Snappy Ubuntu Core, Windows 10 Core, Pinet and Risc OS
are also supported by Raspberry Pi.
Most commonly Pi. used programming languages in Raspberry Pi are Python, C, C++,
Java, Scratch and Ruby
The popular applications developed using Raspberry Pi are media streamer, home
automation,
controlling robot, Virtual Private Network (VPN), light weight Web server with IoT etc.
Pin Configuration
GPIO pins in pins in Raspberry Pi are the general-purpose Input-Output pins. These pins are
to Communicate WITH OTHER circuit such as such as extension boards, custom circuits and
much more.
For getting an output, we can turn a GPIO pin HIGH or LOW.
These pins are a physical interface between the Pi and the outside world. At the
simplest level, we can think of them as switches that you can turn on or off (input) or that
the Pi can turn on or off (output). Seventeen of the 26 pins are GPIO pins. Others are power
or ground pins. Each pin can turn on or off, or go HIGH or LOW in computing terms. When
the pin is HIGH it outputs 3.3 volts (3v3) and when the pin is LOW, it is off.
We can program the pins to interact in amazing ways with the real world. Inputs
don't have to come from a physical switch. It could be input from a sensor or a signal from
another computer or device. The output can also do anything, from turning on an LED to
sending Signal or data to another device. If the Raspberry Pi is on a network, we can control
devices that are attached to it from anywhere and those devices can send data back.
Connectivity and control of physical devices over the Internet is a powerful and exciting
thing and the Raspberry Pi is ideal for this.
Case Studies
we will discuss about 2 example projects using Raspberry Pi. "The first one is is an LED and
the second one is taking a picture using PiCam. The codes for both the examples are written
in Python.
Blinking LED:
Following are the requirements for this experiment.
Raspberry pi
LED
100-ohm resistor
Bread board
Jumper cables
We need to install GPIO Library
Enter the command “sudo apt-get install python-dev” to install python development
Enter the command “sudo apt-get install python-rpi.gpio” to install GPIO library.
Connection:
Raspberry Pi
Raspberry Pi Camera
Raspberry Pi Camera:
Raspberry Pi specific camera module
In the terminal run the command “sudo raspi-config” and press enter.
Capture Image
Python Code:
Import picamera
camera = picamera.PiCamera() camera.capture('image.jpg')
Implementation of loT with Raspberry Pi
For this we need to integrate sensors and actuators interfaced with Raspberry Pi. The data
will be read from the sensor. The actuator will be controlled according to the reading from
the sensor. We will see an example of a Temperature Dependent Auto Cooling System.
Temperature Dependent Auto Cooling System
In this experiment a DHT sensor senses the temperature and when the temperature goes
above 30° C, a fan needs to be automatically turned on.
Requirements
DHT Sensor
Relay
Jumper wires
Raspberry Pi
Mini fan
DHT Sensor
In Digital Humidity and Temperature Sensor (DHT) there are 4 pins: PIN 1, 2, 3, 4 (from left
to right)
o PIN 1- 3.3V-5V Power supply
o PIN 2- Data
o PIN 3- Null
o PIN 4- Ground
Relay
This is a mechanical or electromechanical switch. There are 3 output terminals from left to
right.
NO (normal open):
Common
NC (normal close)
Connection
1. Sensor interface with Raspberry Pi
Connect pin 2 of DHT sensor to any input pins of Raspberry Pi, here we have used
pin 11
Connect the GND (ground) pin of relay to the ground pin of Raspberry Pi
Connect the input/signal pin of Relay to the assigned output pin of Raspberry Pi
(Here we have used pin 7)
3. Fan interface with Raspberry Pi
Adafruit provides a library to work with the DHT22 sensor. Install the library in our Pi. Get
the clone from GIT
Following is the Python code for interfacing DHT22, Relay and Fan with Raspberry Pi.
Result:
The fan is switched on whenever the temperature is above the threshold value set in the code.
Turn on an LED when a Button is pressed