Professional Documents
Culture Documents
Lab - Assignment 8 (IOTPP CSE4110) 1
Lab - Assignment 8 (IOTPP CSE4110) 1
ASSIGNMEN
T
Familiarization with Raspberry Pi and
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.
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
Objective 2
Interfacing LED with Raspberry Pi and blinking LED ON and OFF
Circuit/Schematic Diagram:
2.1: write a program for blinking LED ON for 2 seconds and OFF for 2 seconds.
import time
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(14,GPIO.OUT)
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:
3.1: Write a program for interfacing DHT11 with Raspberry Pi and reading temperature and
humidity values
import Adafruit_DHT
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
4.1: write a program for the implementation of interfacing of ultrasonic sensor with raspberry
pi.
import time
GPIO_TRIGGER = 16
GPIO_ECHO = 18
GPIO.setup(GPIO_TRIGGER, GPIO.OUT)
GPIO.setup(GPIO_ECHO, GPIO.IN)
def distance():
GPIO.output(GPIO_TRIGGER, False)
StartTime = time.time()
StopTime = time.time()
# save StartTime
while GPIO.input(GPIO_ECHO) == 0:
StartTime = time.time()
while GPIO.input(GPIO_ECHO) == 1:
StopTime = time.time()
# multiply with the sonic speed (34300 cm/s) and divide by 2, because there and back
return distance
if __name__ == '__main__':
try:
while True:
dist = distance()
time.sleep(1)
except KeyboardInterrupt:
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.