0% found this document useful (0 votes)
56 views9 pages

Lab Assignment 8 (IOTPP CSE4110) 1

This document outlines an experiment involving familiarization with the Raspberry Pi single board computer and interfacing it with LEDs, sensors, and other hardware. The objectives are to: 1) Install an operating system on the Raspberry Pi and write a simple Python program, 2) Interface an LED and blink it on/off, 3) Interface a DHT11 temperature and humidity sensor and read values using Python, and 4) Interface an ultrasonic sensor and measure distances. By completing these objectives, students will gain experience with IoT fundamentals, Raspberry Pi, Python programming, and building IoT hardware systems to connect the analog and digital worlds.

Uploaded by

SAI DTP
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)
56 views9 pages

Lab Assignment 8 (IOTPP CSE4110) 1

This document outlines an experiment involving familiarization with the Raspberry Pi single board computer and interfacing it with LEDs, sensors, and other hardware. The objectives are to: 1) Install an operating system on the Raspberry Pi and write a simple Python program, 2) Interface an LED and blink it on/off, 3) Interface a DHT11 temperature and humidity sensor and read values using Python, and 4) Interface an ultrasonic sensor and measure distances. By completing these objectives, students will gain experience with IoT fundamentals, Raspberry Pi, Python programming, and building IoT hardware systems to connect the analog and digital worlds.

Uploaded by

SAI DTP
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/ 9

IOTPP LAB

ASSIGNMENT
Familiarization with Raspberry Pi and
08 Interfacing with LED and Sensors

Aim:
Familiarization with Raspberry Pi and interfacing with LED and sensors.

Objectives:
1) Introduction to Raspberry Pi, installation and programming with Python in Raspberry Pi.
2) Interfacing LED with Raspberry Pi and blinking LED ON and OFF.
3) Interfacing DHT11 with Raspberry Pi and measure temperature and humidity using programming
with Python.
4) Interfacing Ultrasonic Sensor with Raspberry Pi and measure distance of objects using
programming with Python.

Summary of Experiment - 8 Goals and Outcomes


By the end of this experiment, students will have gained a solid understanding of IoT
fundamentals, Raspberry Pi, Python programming, and practical experience in building and
controlling IoT-related hardware to establish communication between the analog and digital
world. These skills will facilitate as a strong foundation for more complex IoT projects in the
future.

Pre-Lab Questionnaire:
1) What is the difference between Raspberry Pi and Raspberry Pi Pico?
2) What is the video streaming resolution supported by Raspberry Pi?
3) How is OS for the Raspberry Pi installed?
4) How many GPIO pins does Raspberry Pi has?
5) How many I2C channels does Raspberry Pi has? Through which pins is I2C connection
accessible?
6) How many SPI channels does Raspberry Pi has? Through which pins is SPI connection
accessible?
7) How many UART channels does Raspberry Pi has? Through which pins is UART
connection accessible?
8) What is meant by headless installation of OS for Raspberry Pi?
Answers to Pre-Lab Questions
Components/Equipment Required:
Sl. Name of the Specification Quantity
No. Component / Equipment
1) Raspberry Pi Broadcom BCM2711, 1.8 1
GHz, 8 GB
2) Raspberry Pi power cable USB Type C 1
3) Resistors (carbon type) ¼ watt (330 Ω) 1
4) LED 3mm, Red 1
5) Temperature & Humidity DHT11 1
Sensor
6) Ultrasonic Sensor HCSR04 1
7) Breadboard 840 Tie points 1
8) Jumper Wire --------------------------- As per requirement

Objective 1
Installation of OS for Raspberry Pi and writing a simple program for printing “Welcome to IoT
using Python”.

#simpleTest.py

print(“Welcome to IoT using Python”)

Objective 2
Interfacing LED with Raspberry Pi and blinking LED ON and OFF

Circuit/Schematic Diagram:

Figure 1: Circuit diagram for interfacing LED with Raspberry Pi


Code

2.1: write a program for blinking LED ON for 2 seconds and OFF for 2 seconds.

import RPi.GPIO as GPIO

import time

GPIO.setmode(GPIO.BCM)

GPIO.setwarnings(False)

GPIO.setup(14,GPIO.OUT)

while True: # While loop

GPIO.output(14,GPIO.HIGH) # set GPIO14 pin to HIGH

print ("LED is ON") # show message to Terminal

time.sleep(1) # pause for one second

GPIO.output(14,GPIO.LOW) # set GPIO14 pin to HIGH

print ("LED is OFF") # show message to Terminal

time.sleep(1) # pause for one second

Observation

Figure 2: (Hardware based electronic circuit for interfacing LED with Raspberry Pi.)
Objective 3
Interfacing DHT11 with Raspberry Pi and measure temperature and humidity using programming with
Python.
Circuit/Schematic Diagram:

Figure 3: (Circuit diagram for interfacing DHT11 with Raspberry Pi)


Code

3.1: Write a program for interfacing DHT11 with Raspberry Pi and reading temperature and
humidity values

import Adafruit_DHT

sensor = Adafruit_DHT.DHT11 # Sensor should be set to Adafruit_DHT.DHT11,

pin = 4 # connected to GPIO4.

while True:
humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)
print('Temp={0:0.1f}*C Humidity={1:0.1f}%'.format(temperature, humidity))

Observation

Figure 4: (Hardware based electronic circuit for interfacing LED with Raspberry Pi )
Objective 4
Interfacing Ultrasonic Sensor with Raspberry Pi and measure distance of objects using programming with
Python.

Circuit / Schematic Diagram

Figure 5: (Circuit diagram for implementation of interfacing of ultrasonic sensor with


raspberry pi.)
Code

4.1: write a program for the implementation of interfacing of ultrasonic sensor with raspberry pi.

import RPi.GPIO as GPIO

import time

GPIO.setmode(GPIO.BOARD) #GPIO Mode (BOARD / BCM)

#set GPIO Pins

GPIO_TRIGGER = 16

GPIO_ECHO = 18

#set GPIO direction (IN / OUT)

GPIO.setup(GPIO_TRIGGER, GPIO.OUT)

GPIO.setup(GPIO_ECHO, GPIO.IN)
def distance():

GPIO.output(GPIO_TRIGGER, True) # set Trigger to HIGH

time.sleep(0.00001) # set Trigger after 0.01ms to LOW

GPIO.output(GPIO_TRIGGER, False)

StartTime = time.time()

StopTime = time.time()

# save StartTime

while GPIO.input(GPIO_ECHO) == 0:

StartTime = time.time()

# save time of arrival

while GPIO.input(GPIO_ECHO) == 1:

StopTime = time.time()

# time difference between start and arrival

TimeElapsed = StopTime - StartTime

# multiply with the sonic speed (34300 cm/s) and divide by 2, because there and back

distance = (TimeElapsed * 34300) / 2

return distance

if __name__ == '__main__':

try:

while True:

dist = distance()

print ("Measured Distance = %.1f cm" % dist)

time.sleep(1)

# Reset by pressing CTRL + C

except KeyboardInterrupt:

print("Measurement stopped by User")

GPIO.cleanup()
Observation

Figure 6: (Hardware based electronic circuit for interfacing ultrasonic sensor with raspberry pi.)

Conclusion:
The Raspberry Pi single board computer offers a powerful and compact alternative to using
desktops and laptops. It can also be used to control devices. The GPIO can take inputs from
sensors, process and put out the results to output devices. With its built-in Wifi and Bluetooth
modules, the Raspberry PI SBC is able to connect to Internet and hence, can access cloud storage
for providing complete IoT solutions.

Precautions:
1. Complete the connections before powering the raspberry pi board.

2. Double check the connections for short circuit as they may damage the processor.

3. Properly shutdown the raspberry pi board before switching off the power supply.

Post Experiment Questionnaire:


Answer all the Questions in brief with some appropriate examples.
1) How to convert metric to inches?
2) How do we convert between Celsius and Fahrenheit scales?
3) How can we work with raspberry pi if we do not have external monitor, mouse and keyboard for
raspberry pi?
4) What is SSH and how do we connect to raspberry pi using SSH?
Answers to Post-Lab Questions

(Signature of the Faculty) (Signature of the Student)


Name:
Date: Registration No.:
Branch:
Section

You might also like