0% found this document useful (0 votes)
27 views20 pages

Iot Practical

The document provides a comprehensive guide on practical projects using Raspberry Pi, covering topics such as interfacing with LEDs, RFID, Telegram bots, and visitor monitoring systems. Each practical includes setup instructions, required components, and sample code for implementation. Additionally, it discusses the integration of the ADS1115 ADC module to enhance the Raspberry Pi's capabilities for handling analog inputs.
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)
27 views20 pages

Iot Practical

The document provides a comprehensive guide on practical projects using Raspberry Pi, covering topics such as interfacing with LEDs, RFID, Telegram bots, and visitor monitoring systems. Each practical includes setup instructions, required components, and sample code for implementation. Additionally, it discusses the integration of the ADS1115 ADC module to enhance the Raspberry Pi's capabilities for handling analog inputs.
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/ 20

Internet Of Things

Practical’s
Index
PRAC.N
TOPIC DATE SIGN
O
Starting Raspbian OS, Familiarising with Raspberry Pi
1 Components and interface, Connecting to ethernet,
Monitor, USB.

2 Displaying different LED patterns with Raspberry Pi.

Displaying time over 4-Digit 7-Segment Display using


3
Raspberry Pi.

4 Interfacing Raspberry Pi with RFID.

5 Controlling Raspberry Pi with Telegram Bot.

6 Visitor Monitoring with Raspberry Pi and Pi Camera.

7 ADS1115
PRACTICAL NO - 01

Install Raspberry Pi OS using Raspberry Pi


Imager

Click on download for windows


PRACTICAL NO - 02

Displaying different LED patterns with Raspberry Pi.

Solderless breadboard; Jumper wires for easy hookup; Resistor pack; Red LED;
Multimeter (optional)
$ sudo apt-get install python-rpi.gpio python3-rpi.gpio

import time import RPi.GPIO as


GPIO
GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)
GPIO.setup(10,GPIO.OUT)
GPIO.setup(8,GPIO.OUT) while 1:
print ("LED on")
GPIO.output(8,GPIO.HIGH)
time.sleep(1) print ("LED
off")
GPIO.output(8,GPIO.LOW)
time.sleep(1) print ("LED
on")
GPIO.output(10,GPIO.HIGH)
time.sleep(1) print ("LED off")
GPIO.output(10,GPIO.LOW)
time.sleep(1)

Blinking 4 LED:

import time import RPi.GPIO as


GPIO led1=17 led2=18 led3=22
led4=23 GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(led1,GPIO.OUT)
GPIO.setup(led2,GPIO.OUT)
GPIO.setup(led3,GPIO.OUT)
GPIO.setup(led4,GPIO.OUT)
while(1):

GPIO.output(led1,GPIO.HIGH)
GPIO.output(led2,GPIO.HIGH)
GPIO.output(led3,GPIO.HIGH)
GPIO.output(led4,GPIO.HIGH)
time.sleep(1)
GPIO.output(led1,GPIO.LOW)
GPIO.output(led2,GPIO.LOW) GPIO.output(led3,GPIO.LOW)
GPIO.output(led4,GPIO.LOW)
time.sleep(1)
GPIO.output(led1,GPIO.HIGH)
GPIO.output(led2,GPIO.LOW)
GPIO.output(led3,GPIO.LOW)
GPIO.output(led4,GPIO.LOW)
time.sleep(1)
GPIO.output(led1,GPIO.LOW)
GPIO.output(led2,GPIO.HIGH)
GPIO.output(led3,GPIO.LOW)
GPIO.output(led4,GPIO.LOW)
time.sleep(1)
GPIO.output(led1,GPIO.LOW)
GPIO.output(led2,GPIO.LOW)
GPIO.output(led3,GPIO.HIGH)
GPIO.output(led4,GPIO.LOW)
time.sleep(1)
GPIO.output(led1,GPIO.LOW)
GPIO.output(led2,GPIO.LOW)
GPIO.output(led3,GPIO.LOW)
GPIO.output(led4,GPIO.HIGH)
time.sleep(1)
GPIO.output(led1,GPIO.HIGH)
GPIO.output(led2,GPIO.LOW)
GPIO.output(led3,GPIO.HIGH)
GPIO.output(led4,GPIO.LOW)
time.sleep(1)
GPIO.output(led1,GPIO.LOW)
GPIO.output(led2,GPIO.HIGH)
GPIO.output(led3,GPIO.LOW)
GPIO.output(led4,GPIO.HIGH)
time.sleep(1)
GPIO.output(led1,GPIO.HIGH)
GPIO.output(led2,GPIO.HIGH)
GPIO.output(led3,GPIO.HIGH)
GPIO.output(led4,GPIO.LOW)
time.sleep(2) print ("LED off")
GPIO.output(led1,GPIO.LOW)
GPIO.output(led2,GPIO.LOW)
GPIO.output(led3,GPIO.LOW)
GPIO.output(led4,GPIO.HIGH)
time.sleep(2)
PRACTICAL NO - 03

Displaying Time over 4-Digit 7-Segment Display using


Raspberry Pi
A few of the code examples and projects on this site use modules containing the
Tm1638 driver chip, I was interested in this one which is the TM1637 which
appears to be a more basic version which can only control a display, the other
one can also control LEDs, buttons and two displays at the same time.

This is a common anode 4-digit tube display module which uses the TM1637
driver chip; Only 2 connections are required to control the 4-digit 8-segment
displays

Here is the module

Module in which the


output will appear

Features of the module


● Display common anode for the four red LED
● Powered supply by 3.3V/5V
● Four common anode tube display module is driven by IC TM1637
● Can be used for Arduino devices, two signal lines can make the MCU control 4 8
digital tube. Digital tube 8 segment is adjustable
Here is how to hook the module upTM 1637 for raspberry pi

Board Pin Name Remarks RPi Pin Rpi Function


1 GND Ground 2 5V0

2 VCC +5V Power 6 GND

3 DIN Data In 38 GPIO 20

4 CLK Clock 40 GPIO 21


Installation:

This project is available through pip. Make sure that you are using python 3

$ pip3 install raspberrypi-tm1637

$ pip3 install raspberrypi-tm1637

Code for display

Import tm1637
tm = tm1637.TM1637(clk=21, dio=20)
tm.write([127, 255, 127, 127])
tm.write([0, 0, 0, 0])
tm.write([63, 6, 91, 79])
tm.write([0b00111001, 0b00111111, 0b00111111, 0b00111000])
tm.show('help') tm.hex(0xdead) tm.hex(0xbeef)
tm.numbers(12, 59) tm.number(-123) tm.temperature(24)
PRACTICAL N0 - 04

Interfacing Raspberry Pi with RFID.

How to setup a Raspberry Pi RFID RC522 Chip

In this Raspberry Pi RFID RC522 tutorial, I will be walking you through the steps on how
to set up and wire the RFID RC522 chip with your Raspberry Pi. This project is a cool
circuit to play around with and opens you up to quite a wide variety of different projects
from using it as an attendance system to using it to open a lock.
The RFID RC522 is a very low-cost RFID (Radio-frequency identification) reader and
writer that is based on the MFRC522 microcontroller. This microcontroller provides its
data through the SPI protocol and works by creating a 13.56MHz electromagnetic field
that it uses to communicate with the RFID tags.

Make sure that the tags you purchase for your RFID RC522 operate on the 13.56MHz
frequency otherwise we will fail to read them.
We will be showing you how to wire up the RC522 as well as showing you how to write
Python scripts to interact with the chip so you can both read and write your RFID Tags.
You can extend this tutorial to use something like a 16×2 LCD for the Raspberry Pi,
handy if you want to show some information.

Equipment List:
Raspberry Pi; Micro SD Card; Power Supply; RC522 RFID Reader;
Breadboard; Breadboard Wire Optional:
Raspberry Pi Case; Ethernet Network Connection or Wifi dongle (The Pi 3
has WiFi inbuilt)
Wiring the RFID RC522

● DA connects to Pin 24.


● SCK connects to Pin 23.
● MOSI connects to Pin 19.
● MISO connects to Pin 21.
● GND connects to Pin 6.
● RST connects to Pin 22.
● 3.3v connects to Pin 1S.

Setting up Raspbian for the RFID RC522


● sudo raspi-config
● sudo reboot
● lsmod | grep spi (to check if spi_bcm2835 is listed.)
● sudo nano /boot/config.txt (if spi module is not activated)
● “dtparam=spi=on“ (if there is # just remove it)If you can’t find the line
at all, add
● “dtparam=spi=on” to the bottom of the file. [ you can press Ctrl + X
then pressing Y and then Enter to save the changes.]

Getting Python ready for the RFID RC522


● sudo apt-get update
● sudo apt-get upgrade
● sudo apt-get install python2.7-dev

cd ~ (cloning the source code)


git clone https://github.com/lthiery/SPI-Py.git
cd ~/SPI-Py sudo python
setup.py install cd ~
git clone (https://github.com/pimylifeup/MFRC522-python.git)
cd ~/MFRC522-python sudo nano Write.py
import PRi.GPIO as GPIO(ask for text to
input) import simpleMFRC522 reader =
SimpleMFRC522.SimpleMFRC522()

Writing with the RFID RC522

import RPi.GPIO as GPIO


import SimpleMFRC522

reader = SimpleMFRC522.SimpleMFRC522()

try:
text = raw_input('New data:')
print("Now place your tag to
write") reader.write(text)
print("Written")
finally:
GPIO.cleanup()

Reading with the RFID RC522


import RPi.GPIO as GPIO
import SimpleMFRC522

reader = SimpleMFRC522.SimpleMFRC522()

try:
id, text =
reader.read() print(id)
print(text)
finally:
GPIO.cleanup()
PRACTICAL NO - 05

Controlling Raspberry Pi with Telegram Bot

Controlling Raspberry Pi GPIO Pins using Telegram App


Telegram is an optimal application to combine with Raspberry Pi for all our mobile
control purpose. It has very good developer support and lots of features are being
planned to be released soon to enhance the performance of Telegram Bots. In our
previous tutorial we learnt how we can set up a telegram bot for raspberry pi and
also learnt have to have a chat with it and share images, documents and Audio files.
Now, we will proceed to next step by learning How we can control the GPIO pins
on Raspberry Pins using Telegram, so that we provide some hardware support
for our bot. In this tutorial we will Connect four LEDs to Raspberry Pi GPIO pins
and toggle them using natural language (chatting like) from Telegram. Sounds
interesting right? Let us get started.

Materials Required:
● Four LED (any color)
● Raspberry Pi (with internet connection)
● Breadboard
● Connecting wires

Step 1: Installing Telegram on your Mobile:


The first step would be to install Telegram on your Mobile.

Step 2: Talk to Bot Father:


The next step would be to request the Bot Father to create us a new Bot. On the
top right corner of the Home screen there will be a search icon, click on it to search
for the name “botfather”. Botfather is a Bot by itself, it will guide you to create a new
bot for you. Click on start and select /newbot

Step3: Getting your token for access


I have named bot as circuitdigest and the username as circuitdigestBot. After this
process the botfather will give you a Token for access. This is like the password for
your bot, people can control program your bot using this token key.

Installing Telegram in RPi


● Sudo raspi-config if config
● now type pi@192...(ip address)It ask for username and password.

● Now install Telepot in RPi


● sudo apt-get install python-pip
● sudo pip3 install teleport
Circuit Diagram:
The circuit Diagram for Controlling LEDs using Raspberry Pi and Telegram
Android App is nothing more than four LEDs and some connecting wires. We will
not need the current limiting resistors since the Raspberry Pi GPIO pins work on
3.3V TTL. Follow the circuit below and connect your LED.

Led Terminal Pin Number GPIO Number


Green Anode Pin 31 GPIO 6
Red Anode Pin 33 GPIO 13
Yellow Anode Pin 35 GPIO 19
White Anode Pin 37 GPIO 26
Cathode of all four Pin 39 Ground
First install telegram from play store then make a id with BOTFATHER you
will get a token.

PYTHON PROGRAM:

import sys
import time
import random
import datetime
import telepot import
RPi.GPIO as GPIO

GPIO.setmode(GPIO.BOARD)
GPIO.setup(11, GPIO.OUT)
Pin = 11
def on(pin):
GPIO.output(pin,GPIO.HIGH)
return
def off(pin):
GPIO.output(pin,GPIO.LOW)
return
def handle(msg):
chat_id = msg['chat']['id']
command = msg['text']
print('Got command: %s' % command)
if command == 'on':
bot.sendMessage(chat_id, on(11))
elif command =='off':
bot.sendMessage(chat_id, off(11))
bot = telepot.Bot('Bot Token')
bot.message_loop(handle) print('I am
listening...') while 1: time.sleep(10)

PRACTICAL NO - 06

Visitor Monitoring with Raspberry Pi and Pi Camera.


Components Required:
● Raspberry Pi
● Pi camera
● 16x2 LCD
● DC Motor
● IC L293D
● Buzzer
● Bread Board
● Resistor (1k, 10k)

The Raspberry Pi Monitoring System efficiently manages visitor access through a


combination of a Pi camera, a DC motor gate, and user inputs. Upon pressing the
button, the system captures an image, opens the gate momentarily, and signals
readiness with an LED indicator while alerting users with a buzzer. This seamless
integration ensures security and ease of use for managing entries.
Circuit explanation: Circuit of this Raspberry Pi Visitor Surveillance System is
very simple. Here a Liquid Crystal Display (LCD) is used for displaying Time/Date
of visitor entry and some other messages. LCD is connected to Raspberry Pi in 4-
bit mode. Pins of LCD namely RS, EN, D4, D5, D6, and D7 are connected to
Raspberry Pi GPIO pin number 18, 23, 24, 16, 20 and 21. Pi camera module is
connected at camera slot of the Raspberry Pi. A buzzer is connected to GPIO pin
26 of Raspberry Pi for indication purpose. LED is connected to GPIO pin 5
through a 1k resistor and a push button is connected to GPIO pin 19 with respect
to ground, to trigger the camera and open the Gate. DC motor (as Gate) is
connected with Raspberry Pi GPIO pin 17 and 27 through Motor Driver IC
(L293D).

Program:

sudo apt-get install python-picamera


sudo apt-get install pyhton3-picamera

sudo raspi-config
sudo reboot

CAMERA:
from picamera import
PiCamera from time import
sleep camera = PiCamera()
camera.start_preview()
sleep(20)
camera.stop_preview()

CAPTURE:
import picamera from time import
sleep camera =
picamera.PiCamera()
camera.brightness = 60
camera.start_preview()
camera.annotate_text = 'Hey
Pritam' sleep(10)
camera.capture('/home/pi/ggg.jpg')
camera.stop_preview()
PRACTICAL NO - 07

ADS1115

Integrating the ADS1115 16-bit ADC module with the Raspberry Pi significantly
enhances the Pi's ability to handle analog inputs, which is otherwise a limitation
due to its lack of a built-in ADC. The ADS1115 provides high-resolution analog-
todigital conversion with a precision of up to 76uV, making it ideal for projects
involving sensors or devices that output analog signals. For even greater
precision, the ADS1220 24-bit ADC module can be considered, offering resolution
down to 0.3uV. This integration opens up new possibilities for more accurate data
acquisition in Raspberry Pi-based projects.

1. Connect the VCC pin of the ADS1115 to the 3.3V pin of the
Raspberry Pi.
2. Connect the GND pin of the ADS1115 to any GND pin on the
Raspberry Pi.
3. Connect the SDA pin of the ADS1115 to the SDA pin of the
Raspberry Pi.
4. Connect the SCL pin of the ADS1115 to the SCL pin of the
Raspberry Pi.
sudo pip3 install adafruit-circuitpython-ads1x15

Python Code to read Analog:

import board import time import busio import


adafruit_ads1x15.ads1115 as ADS from
adafruit_ads1x15.analog_in import AnalogIn i2c
= busio.I2C(board.SCL, board.SDA) ads =
ADS.ADS1115(i2c) channel = AnalogIn(ads,
ADS.P0) while True:
print("Analog Value: ", channel.value, "Voltage: ", channel.voltage)
time.sleep(0.2)

Python code to read multiple analog:

import board import busio import


adafruit_ads1x15.ads1115 as ADS from
adafruit_ads1x15.analog_in import AnalogIn
import time i2c = busio.I2C(board.SCL,
board.SDA) ads = ADS.ADS1115(i2c) channel0
= AnalogIn(ads, ADS.P0) channel1 =
AnalogIn(ads, ADS.P1) channel2 =
AnalogIn(ads, ADS.P2) channel3 =
AnalogIn(ads, ADS.P3) while True:
print("Analog Value 0: ", channel0.value,
"Voltage 0: ", channel0.voltage)
print("Analog Value 1: ", channel1.value, "Voltage 1: ", channel1.voltage)
print("Analog Value 2: ", channel2.value, "Voltage 2: ", channel2.voltage)
print("Analog Value 3: ", channel3.value, "Voltage 3: ", channel3.voltage)
time.sleep(1)

You might also like