0% found this document useful (0 votes)
9 views12 pages

Unit 3 FIoT Notes

This document introduces Python programming for Internet of Things (IoT) systems, emphasizing its application in programming IoT devices and creating backends. It discusses the Raspberry Pi, a low-cost computer ideal for IoT projects, detailing its architecture, GPIO pin configuration, and examples of projects such as blinking an LED and capturing images with a camera. Additionally, it covers the implementation of a Temperature Dependent Auto Cooling System using a DHT sensor and a fan, showcasing practical applications of Raspberry Pi in IoT.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views12 pages

Unit 3 FIoT Notes

This document introduces Python programming for Internet of Things (IoT) systems, emphasizing its application in programming IoT devices and creating backends. It discusses the Raspberry Pi, a low-cost computer ideal for IoT projects, detailing its architecture, GPIO pin configuration, and examples of projects such as blinking an LED and capturing images with a camera. Additionally, it covers the implementation of a Temperature Dependent Auto Cooling System using a DHT sensor and a fan, showcasing practical applications of Raspberry Pi in IoT.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

UNIT-3

INTRODUCTION TO PYTHON PROGRAMMING

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.

Programming with Raspberry Pi


 Raspberry Pi is a low cost, credit-card sized computer that plugs into a
computer monitor TV and uses a standard keyboard and mouse.
 It is a little device that enables people of all ages to explore computing.
 Programs are written in languages like Scratch and Python.
 It is capable of doing everything we expect from a desktop computer. We can
browse the Internet, play high-definition video, to make spreadsheets, word-
processing and playing games.
 There are several generations of Raspberry Pi like Raspberry Pi 3 model B,
Raspberry Pi 2 model B, Raspberry Pi zero.
Architecture

(Basic Architecture of Raspberry Pi)

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

Installing GPIO library:


 Open terminal

 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:

 Connect the negative terminal of the LED to the ground pin of Pi

 Connect the positive terminal of the LED to the output pin of Pi


Capture Image using Raspberry Pi Requirement:

 Raspberry Pi
 Raspberry Pi Camera

Raspberry Pi Camera:
 Raspberry Pi specific camera module

 Dedicated CSI slot in Pi for connection


 The cable slot is placed between Ethernet port and HDMI

port Connection: Boot the Pi once the camera is connected to Pi

Configuring Pi for Camera

 In the terminal run the command “sudo raspi-config” and press enter.

 Navigate to “Interfacing Options” option and press enter.

 Navigate to “Camera” option.

 Enable the camera.

 Reboot Raspberry pi.

Capture Image

 Open terminal and enter the

command- raspistill -o image.jpg

 This will store the image as ‘image.jpg’


PiCam can also be processed using Python camera module python-picamera

sudo apt-get install python-picamera

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

 4.7K ohm resistor

 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 1 of DHT sensor to the 3.3V pin of Raspberry Pi

 Connect pin 2 of DHT sensor to any input pins of Raspberry Pi, here we have used
pin 11

 Connect pin 4 of DHT sensor to the ground pin of the Raspberry Pi


2. Relay interface with Raspberry Pi

 Connect the VCC pin of relay to the 5V supply pin of Raspberry Pi

 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

 Connect the Li-Po battery in series with the fan.


 NO terminal of the relay is connected to the positive terminal of the fan.
 Common terminal of the relay is connected to positive terminal of the battery.
 Negative terminal of the battery is connected to the negative terminal of the fan.

Adafruit provides a library to work with the DHT22 sensor. Install the library in our Pi. Get
the clone from GIT

git clone https://github.com/adafruit/Adafruit_Python_DHT.g...


Go to folder Adafruit_Python_DHT
cd Adafruit_Python_DHT

Install the library

sudo python setup.py install

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

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy