0% found this document useful (0 votes)
32 views

iotlabclm_2025

The document is a laboratory manual for the IoT Lab at Vivekananda College of Engineering & Technology, detailing the course structure, prerequisites, outcomes, and experiments for the B.E. EC program for the academic year 2024-25. It includes a list of required resources, evaluation schemes, and specific experiments involving interfacing various components with Raspberry Pi and Arduino. The manual aims to provide students with practical knowledge and skills in IoT technologies and programming.

Uploaded by

rashmith2
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)
32 views

iotlabclm_2025

The document is a laboratory manual for the IoT Lab at Vivekananda College of Engineering & Technology, detailing the course structure, prerequisites, outcomes, and experiments for the B.E. EC program for the academic year 2024-25. It includes a list of required resources, evaluation schemes, and specific experiments involving interfacing various components with Raspberry Pi and Arduino. The manual aims to provide students with practical knowledge and skills in IoT technologies and programming.

Uploaded by

rashmith2
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/ 30

Vivekananda College of Engineering & Technology TCP03

[A Unit of Vivekananda Vidyavardhaka Sangha Puttur ®] Rev 1.2


Affiliated to Visvesvaraya Technological University EC
Approved by AICTE New Delhi & Recognised by Govt of Karnataka 05/02/25
COURSE LABORATORY MANUAL
A. LABORATORY OVERVIEW
Degree: B.E Programme: EC
Semester: VI Academic Year: 2024-25
Laboratory Title: IoT (Internet of Things) Lab Laboratory Code: BEC657C
L-T-P-S: 0-0-2-0 Duration of SEE: 3 Hrs
Total Contact Hours: 24 SEE Marks: 50*
Credits: 1 CIE Marks: 50
Sign
Lab Manual Author: Shivaprasad Dt :5/2/25
Sign
Checked By: Nithin Dt : 5/2/25
*The SEE will be conducted for 100 marks and proportionally reduced to 50 marks.

B. DESCRIPTION
1. PREREQUISITES:
• DSP (BEC502, Python tool was used to simulate in DSP experiments)
• Microcontrollers (BEC405A)
• Microcontrollers Lab (BECL456A)
• Computer Organization and Architecture (BEC306C)

2. BASE COURSE:
• Embedded C Basics(21EC481)

3. COURSE OUTCOMES:
At the end of the course, the student will be able to;
1. Understand internet of Things and its hardware and software components
2. Interface I/O devices, sensors & communication modules
3. Remotely monitor data and control devices
4. Develop real life IoT based projects

4. RESOURSES REQUIRED:
• Raspberry Pi 4, Broadcom BCM2711, Quad core Cortex-A72 (ARM v8) 64-bit SoC @
1.8GHz, SDRAM-4GHz, 40pin GPIO
• LED, Switch, Relay, Motor, Bluetooth, DHT11, OLED
• Python Interpreter, Thonny IDE
• Adafruit package, Thingspeak cloud, MQTT broker, SQLite DB

Prepared by:Shivaprasad Checked by:Nithin HOD

Nehru Nagar, Puttur - 574 203, DK, Karnataka State – INDIA.


Phone:+91-8251-235955, 234555 Fax: 236444, Web: www.vcetputtur.ac.in, E-Mail: [email protected]
Vivekananda College of Engineering & Technology TCP03
[A Unit of Vivekananda Vidyavardhaka Sangha Puttur ®] Rev 1.2
Affiliated to Visvesvaraya Technological University EC
5/2/25
Approved by AICTE New Delhi & Recognised by Govt of Karnataka
COURSE LABORATORY MANUAL
5. RELEVANCE OF THE COURSE:
• Sensors and Actuators(21EC655)
• Network Security(21EC732)

6. GENERAL INSTRUCTIONS:
• -

7. CONTENTS:
Expt
Title of the Experiments RBT CO
No.
1 (i)To interface LED/Buzzer with Arduino/Raspberry Pi and write a L3 CO2
program to ‘turn ON’ LED for 1 sec after every 2 seconds.
(ii) To interface Push button/Digital sensor (IR/LDR) with
Arduino/Raspberry Pi and write a program to ‘turn ON’ LED when
push button is pressed or at sensor detection.
2 (i)To interface DHT11 sensor with Arduino/Raspberry Pi and write a L3 CO2
program to print temperature and humidity readings.
(ii)To interface OLED with Arduino/Raspberry Pi and write a program
to print temperature and humidity readings on it
3 To interface motor using relay with Arduino/Raspberry Pi and write a L3 CO2
program to ‘turn ON’ motor when push button is pressed
4 To interface Bluetooth with Arduino/Raspberry Pi and write a program L3 CO2
to send sensor data to smartphone using Bluetooth
5 To interface Bluetooth with Arduino/Raspberry Pi and write a program L3 CO2
to turn LED ON/OFF when '1'/'0' is received from smartphone using
Bluetooth
6 Write a program on Arduino/Raspberry Pi to upload temperature and L3 CO1,CO3
humidity data to thingspeak cloud. ,CO4
7 Write a program on Arduino/Raspberry Pi to retrieve temperature and L3 CO1,CO3
humidity data from thingspeak cloud.
8 To install MySQL database on Raspberry Pi and perform basic SQL L3 CO2
queries.
9 Write a program on Arduino/Raspberry Pi to publish temperature data L3 CO1,CO2
to MQTT broker. CO3,CO4
10 Write a program to create UDP server on Arduino/Raspberry Pi and L3 CO2
respond with humidity data to UDP client when requested.
11 Write a program to create TCP server on Arduino/Raspberry Pi and L3 CO2
respond with humidity data to TCP client when requested.
12 Write a program on Arduino/Raspberry Pi to subscribe to MQTT L3 CO1
broker for temperature data and print it
13 Open ended experiment – 1 L3 CO2,CO3
14 Open ended experiment – 2 L3 CO2,CO3

8. REFERENCE:
1. Vijay Madisetti, Arshdeep Bahga, Internet of Things. "A Hands on Approach", University
Press
2. Dr. SRN Reddy, Rachit Thukral and Manasi Mishra, "Introduction to Internet of Things: A

Nehru Nagar, Puttur - 574 203, DK, Karnataka State – INDIA.


Phone:+91-8251-235955, 234555 Fax: 236444, Web: www.vcetputtur.ac.in, E-Mail: [email protected]
Vivekananda College of Engineering & Technology TCP03
[A Unit of Vivekananda Vidyavardhaka Sangha Puttur ®] Rev 1.2
Affiliated to Visvesvaraya Technological University EC
5/2/25
Approved by AICTE New Delhi & Recognised by Govt of Karnataka
COURSE LABORATORY MANUAL
practical Approach", ETI Labs

-
C. EVALUATION SCHEME
For CBCS 2021 scheme:
1. Laboratory Components: 38 Marks (Observation Writeup – 4 Marks + Lab Conduction –
15 Marks + Viva-Voce – 4 Marks + Record Writing – 15 Marks).

2. Laboratory IA tests: 12 Marks


(Minimum 1 IA test is mandatory. IA test shall be conducted for 50 Marks; for the final
IA test marks shall be converted to maximum of 12).
3. Continuous Internal Evaluation (CIE) = 38 + 12 = 50 Marks.
4. SEE : 50* Marks
(*The SEE will be conducted for 100 marks and proportionally reduced to 50 marks)

-
D1. ARTICULATION MATRIX
Mapping of CO to PO
POs
COs 1 2 3 4 5 6 7 8 9 10 11 12
1.Understand internet of Things and its 2 2 2 2 2 - - - 2 - 1 2
hardware and software components
2.Interface I/O devices, sensors & 2 2 2 2 2 - - - 2 - 1 2
communication modules
3.Remotely monitor data and control 2 2 2 2 2 - - - 2 - 1 2
devices
4.Develop real life IoT based projects 2 2 2 2 2 - - - 2 - 1 2

D2. ARTICULATION MATRIX CO v/s PSO


Mapping of CO to PSO
PSOs
COs 1 2
1.Understand internet of Things and its 2 1
hardware and software components
2.Interface I/O devices, sensors & 2 1
communication modules
3.Remotely monitor data and control 2 1
devices
4.Develop real life IoT based projects 2 1
-
E. EXPERIMENTS
1. EXPERIMENT NO:1
2. TITLE:
i) To interface led/buzzer with Arduino/Raspberry pi and write a program to ‘turn on’ led for 1 sec
after every 2 seconds.
ii) To interface push button/digital sensor (ir/ldr) with arduino/raspberry pi and write a program to
‘turn on’ led when push button is pressed or at sensor detection
3. LEARNING OBJECTIVES:

Nehru Nagar, Puttur - 574 203, DK, Karnataka State – INDIA.


Phone:+91-8251-235955, 234555 Fax: 236444, Web: www.vcetputtur.ac.in, E-Mail: [email protected]
Vivekananda College of Engineering & Technology TCP03
[A Unit of Vivekananda Vidyavardhaka Sangha Puttur ®] Rev 1.2
Affiliated to Visvesvaraya Technological University EC
5/2/25
Approved by AICTE New Delhi & Recognised by Govt of Karnataka
COURSE LABORATORY MANUAL
• To impart necessary and practical knowledge of components LED and Switch
• To program LED and Switch module using Rpi GPIO Python package
4. AIM:
• To interface led/buzzer with Arduino/Raspberry pi and write a program to ‘turn on’ led for 1
sec after every 2 seconds.
• To interface push button/digital sensor (ir/ldr) with arduino/raspberry pi and write a program
to ‘turn on’ led when push button is pressed or at sensor detection
5. MATERIAL / EQUIPMENT REQUIRED:
• Raspberry pi-4
• LED, Switch module
• Python Interpreter, Thonny IDE
6. THEORY / HYPOTHESIS:
• The Raspberry Pi 4 is a credit card-sized single-board computer developed by the Raspberry
Pi Foundation. It was released in June 2019 and offers significant improvements over its
predecessors. Here are some key features and specifications of the Raspberry Pi 4:
• Processor: The Raspberry Pi 4 is powered by a Broadcom BCM2711 quad-core Cortex-
A72 (ARM v8) 64-bit processor running at 1.5 GHz.
• Memory: It is available in three different RAM configurations: 2GB, 4GB, and 8GB
LPDDR4 RAM.
• Video Output: The Pi 4 supports dual-display output with resolutions up to 4K via two
micro HDMI ports.
• USB Ports: It has two USB 3.0 ports and two USB 2.0 ports, offering faster data transfer
rates compared to previous models.
• Network Connectivity: The Raspberry Pi 4 comes with Gigabit Ethernet for wired
network connections and has built-in dual-band Wi-Fi (802.11ac) and Bluetooth 5.0 for
wireless connectivity.
• Storage: MicroSD card slot for storage, where you can install the operating system and
store data.
• GPIO Pins: The Pi 4 retains the 40-pin GPIO (General Purpose Input/Output) header,
allowing for hardware interfacing and DIY electronics projects.
• Power Supply: It requires a USB-C power supply, providing more power than previous
models.
• Operating System: The Raspberry Pi 4 supports various operating systems, including
Raspbian (now known as Raspberry Pi OS), a Debian-based Linux distribution customized
for Raspberry Pi.
• Cooling: The Pi 4 tends to generate more heat than its predecessors, so users often use
heatsinks or fans for passive or active cooling.
• Use Cases: The Raspberry Pi 4 is suitable for a wide range of applications, including
desktop computing, media center (using software like Kodi or Plex), retro gaming
emulation, home automation, and various DIY projects

7. FORMULA / CALCULATIONS:

Nehru Nagar, Puttur - 574 203, DK, Karnataka State – INDIA.


Phone:+91-8251-235955, 234555 Fax: 236444, Web: www.vcetputtur.ac.in, E-Mail: [email protected]
Vivekananda College of Engineering & Technology TCP03
[A Unit of Vivekananda Vidyavardhaka Sangha Puttur ®] Rev 1.2
Affiliated to Visvesvaraya Technological University EC
5/2/25
Approved by AICTE New Delhi & Recognised by Govt of Karnataka
COURSE LABORATORY MANUAL
8. PROGRAM:
#1.a. To interface led/buzzer with Arduino/Raspberry pi and write a program to ‘turn on’ led
#for 1 sec after every 2 seconds.
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(18,GPIO.OUT)
while True:
print ("LED on")
GPIO.output(18,GPIO.HIGH)
time.sleep(1)
print ("LED off")
GPIO.output(18,GPIO.LOW)
time.sleep(2)
#1.b. To interface push button/digital sensor (ir/ldr) with arduino/raspberry pi and write a program
#to ‘turn on’ led when push button is pressed or at sensor detection
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(17,GPIO.IN,pull_up_down=GPIO.PUD_UP)
GPIO.setup(18,GPIO.OUT)
while True:
state= GPIO.input(17)
if state == False:
print('Button pressed')
GPIO.output(18,GPIO.HIGH)
time.sleep(2)
else:
print('Button not pressed')
GPIO.output(18,GPIO.LOW)
time.sleep(1)

9. CIRCUIT DIAGRAM :

FIG.1. RASPBERRY PI-4 LED INTERFACE

Nehru Nagar, Puttur - 574 203, DK, Karnataka State – INDIA.


Phone:+91-8251-235955, 234555 Fax: 236444, Web: www.vcetputtur.ac.in, E-Mail: [email protected]
Vivekananda College of Engineering & Technology TCP03
[A Unit of Vivekananda Vidyavardhaka Sangha Puttur ®] Rev 1.2
Affiliated to Visvesvaraya Technological University EC
5/2/25
Approved by AICTE New Delhi & Recognised by Govt of Karnataka
COURSE LABORATORY MANUAL

FIG.2. RASPBERRY PI-4 LED, SWITCH INTERFACE

10. OBSERVATION TABLE / LOOKUP TABLE / TRUTH TABLE:


• -
11. GRAPHS / OUTPUTS:
• -
12. RESULTS & CONCLUSIONS:
• Led is driven high for 1 second and low for 2 seconds
• Led is turned on for 2 seconds upon button press.
13. LEARNING OUTCOMES :
• Understand python program basics to drive led and interface switch using Rpi package
• Understand Programming GPIO pins for I/O operation
14. APPLICATION AREAS:
• -
15. REMARKS:
• -

-
1. EXPERIMENT NO:2
2. TITLE:
(i)To interface DHT11 sensor with Arduino/Raspberry Pi and write a program to print temperature
and humidity readings.
(ii)To interface OLED with Arduino/Raspberry Pi and write a program to print temperature and
humidity readings on it
3. LEARNING OBJECTIVES:
• To understand the working of DHT11 sensor
• To understand I2C communication
4. AIM:
• To interface DHT11 sensor with Arduino/Raspberry Pi and write a program to print
temperature and humidity readings
• To interface OLED with Arduino/Raspberry Pi and write a program to print temperature and
humidity readings on it

Nehru Nagar, Puttur - 574 203, DK, Karnataka State – INDIA.


Phone:+91-8251-235955, 234555 Fax: 236444, Web: www.vcetputtur.ac.in, E-Mail: [email protected]
Vivekananda College of Engineering & Technology TCP03
[A Unit of Vivekananda Vidyavardhaka Sangha Puttur ®] Rev 1.2
Affiliated to Visvesvaraya Technological University EC
5/2/25
Approved by AICTE New Delhi & Recognised by Govt of Karnataka
COURSE LABORATORY MANUAL
5. MATERIAL:
• Raspberry pi-4
• DHT11 module, OLED module
• Adafruit_DHT, oled_text(External Python packages)
• Python Interpreter, Thonny IDE
6. THEORY / HYPOTHESIS:
• The DHT11 is a low-cost, digital temperature and humidity sensor. It is commonly used in
various electronic projects to measure environmental conditions.
• To read data from the DHT11 sensor, you need to send a start signal and then receive a
response from the sensor. After the response, the sensor sends a 40-bit data stream
containing temperature and humidity information.

Fig1.a DHT11 sensor


• An OLED (Organic Light-Emitting Diode) display is a type of display technology that uses
organic compounds to emit light when an electric current is applied. The "I2C" part refers to
the communication protocol used for interfacing with the display, specifically the I2C
(Inter-Integrated Circuit) protocol.
• When you have asn OLED display with I2C support, it typically means that the display can
be connected to a microcontroller or other devices using I2C communication protocol. This
makes it easier to interface with the display using few wires.

Fig.1.b OLED display

7. FORMULA / CALCULATIONS:
• -
8. PROGRAM:
#2.a
import Adafruit_DHT
sensor = Adafruit_DHT.DHT11
pin = 18#GPIO 18 of Rpi
# Try to grab a sensor reading. Use the read_retry method which will retry up
# to 15 times to get a sensor reading (waiting 2 seconds between each retry).
while True:
humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)
print('Temp={0:0.1f}*C Humidity={1:0.1f}%'.format(temperature, humidity))

Nehru Nagar, Puttur - 574 203, DK, Karnataka State – INDIA.


Phone:+91-8251-235955, 234555 Fax: 236444, Web: www.vcetputtur.ac.in, E-Mail: [email protected]
Vivekananda College of Engineering & Technology TCP03
[A Unit of Vivekananda Vidyavardhaka Sangha Puttur ®] Rev 1.2
Affiliated to Visvesvaraya Technological University EC
5/2/25
Approved by AICTE New Delhi & Recognised by Govt of Karnataka
COURSE LABORATORY MANUAL
#2.b.
from board import SCL, SDA
import busio
from oled_text import OledText
import Adafruit_DHT
sensor = Adafruit_DHT.DHT11
pin = 18#GPIO 18 of Rpi
i2c = busio.I2C(SCL, SDA)
# Create the display, pass its pixel dimensions
oled = OledText(i2c, 128, 64)
for i in range(5):
humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)
print('Temp={0:0.1f}*C Humidity={1:0.1f}%'.format(temperature, humidity))
# Write to the oled
oled.text('Temp={0:0.1f}*C'.format(temperature), 1) # Line 1
oled.text('Humid={0:0.1f}%'.format(humidity), 2) # Line 2

9. BLOCK / CIRCUIT / MODEL DIAGRAM / REACTION EQUATION

Fig.2.a Interface between dht11 and rpi

Fig.2.b Interface between Rpi, DHT11 and OLED

Nehru Nagar, Puttur - 574 203, DK, Karnataka State – INDIA.


Phone:+91-8251-235955, 234555 Fax: 236444, Web: www.vcetputtur.ac.in, E-Mail: [email protected]
Vivekananda College of Engineering & Technology TCP03
[A Unit of Vivekananda Vidyavardhaka Sangha Puttur ®] Rev 1.2
Affiliated to Visvesvaraya Technological University EC
5/2/25
Approved by AICTE New Delhi & Recognised by Govt of Karnataka
COURSE LABORATORY MANUAL

10. OBSERVATION TABLE / LOOKUP TABLE / TRUTH TABLE:
• -
11. GRAPHS / OUTPUTS:
• -
12. RESULTS & CONCLUSIONS:
• Real time temperature and humidity is displayed on the python command prompt
• Real time temperature and humidity is displayed on OLED using I2C communication
13. LEARNING OUTCOMES :
• Understand the DHT11 temperature basics
• Understand I2C communication
14. APPLICATION AREAS:
• Automatic Irrigation system using Raspberry-pi
15. REMARKS:
• -

-
1. EXPERIMENT NO:3
2. TITLE: TO INTERFACE MOTOR USING RELAY WITH ARDUINO/RASPBERRY PI AND
WRITE A PROGRAM TO ‘TURN ON’ MOTOR WHEN PUSH BUTTON IS PRESSED
3. LEARNING OBJECTIVES:
• Understand the working of Relay module
• Drive DC motor using relay module
4. AIM:
• To interface motor using Relay with Raspberry Pi and turn Motor on when push button is
pressed
5. MATERIAL / EQUIPMENT REQUIRED:
• Raspberry pi-4
• Switch module, Relay, DC motor, Regulated Power Supply(5V,3A)
• Python Interpreter, Thonny IDE
6. THEORY:
• Relay:An electro mechanical device which acts as dynamic path selectors for signals and
power.The Relay unit contains a relay coil made up of insulated wire on a metal core and a
metal armature with one or more contacts. Relay works on electromagnetic principle. When
a voltage is applied to the relay coil, current flows through the coil, which in turn generates
a magnetic field. The magnetic field attracts the armature core and moves the contact point.
The movement of the contact point changes the power/signal flow path.

Nehru Nagar, Puttur - 574 203, DK, Karnataka State – INDIA.


Phone:+91-8251-235955, 234555 Fax: 236444, Web: www.vcetputtur.ac.in, E-Mail: [email protected]
Vivekananda College of Engineering & Technology TCP03
[A Unit of Vivekananda Vidyavardhaka Sangha Puttur ®] Rev 1.2
Affiliated to Visvesvaraya Technological University EC
5/2/25
Approved by AICTE New Delhi & Recognised by Govt of Karnataka
COURSE LABORATORY MANUAL

Fig.1. Relay module

7. FORMULA / CALCULATIONS:
• -
8. PROGRAM:
import time
import RPi.GPIO as GPIO
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(17,GPIO.IN,GPIO.PUD_UP)
GPIO.setup(18,GPIO.OUT)
while True:
state=GPIO.input(17)
if state==False:
GPIO.output(18,GPIO.HIGH)
time.sleep(2)
GPIO.output(18,GPIO.LOW)
time.sleep(1)
else:
GPIO.output(18,GPIO.LOW)
time.sleep(1)

9. BLOCK / CIRCUIT / MODEL DIAGRAM / REACTION EQUATION:

Nehru Nagar, Puttur - 574 203, DK, Karnataka State – INDIA.


Phone:+91-8251-235955, 234555 Fax: 236444, Web: www.vcetputtur.ac.in, E-Mail: [email protected]
Vivekananda College of Engineering & Technology TCP03
[A Unit of Vivekananda Vidyavardhaka Sangha Puttur ®] Rev 1.2
Affiliated to Visvesvaraya Technological University EC
5/2/25
Approved by AICTE New Delhi & Recognised by Govt of Karnataka
COURSE LABORATORY MANUAL

Fig.2. Interface diagram relay, motor and Rpi

10. OBSERVATION TABLE / LOOKUP TABLE / TRUTH TABLE:


• -
11. GRAPHS / OUTPUTS:
• -
12. RESULTS & CONCLUSIONS:
• Upon Button press the DC motor is driven using relay
13. LEARNING OUTCOMES :
• Write Python program to drive DC motor using Relay in Raspberry pi system
14. APPLICATION AREAS:
• Develop Remote controller based Robot.
15. REMARKS:
• -

1. EXPERIMENT NO:4
2. TITLE: TO INTERFACE BLUETOOTH WITH ARDUINO/RASPBERRY PI AND WRITE A
PROGRAM TO SEND SENSOR DATA TO SMARTPHONE USING BLUETOOTH
3. LEARNING OBJECTIVES:
• To interface Bluetooth device with Rpi and communicate with smartphone
• Understand serial communication between Rpi and HC-05
4. AIM:
• To interface Bluetooth with Raspberry pi and write a program to send sensor data to
smartphone using Bluetooth
5. MATERIAL / EQUIPMENT REQUIRED:
• Raspberry pi-4
• HC-05

Nehru Nagar, Puttur - 574 203, DK, Karnataka State – INDIA.


Phone:+91-8251-235955, 234555 Fax: 236444, Web: www.vcetputtur.ac.in, E-Mail: [email protected]
Vivekananda College of Engineering & Technology TCP03
[A Unit of Vivekananda Vidyavardhaka Sangha Puttur ®] Rev 1.2
Affiliated to Visvesvaraya Technological University EC
Approved by AICTE New Delhi & Recognised by Govt of Karnataka 5/2/25
COURSE LABORATORY MANUAL
• Python Interpreter, Thonny IDE
6. THEORY / HYPOTHESIS:
• UART stands for Universal Asynchronous Receiver/Transmitter. It is a hardware
communication protocol used for serial communication between devices. UART is
commonly used to connect different electronic devices and peripherals, such as
microcontrollers, sensors, and other embedded systems.
• The UART frame format includes start bit, stop bit, data bits and parity bit.

Fig.1. UART module

Fig.2. UART Frame

• The HC-05 is a popular Bluetooth module that allows wireless communication between
devices. Here are some key points about the HC-05 Bluetooth module
• The HC-05 is designed for serial communication and is often used to enable Bluetooth
connectivity in electronic projects. It can be used for wireless communication between
microcontrollers, Arduino boards, and other devices
• The HC-05 can operate in two main modes: AT command mode and transparent
communication mode. In AT command mode, you can configure the module using AT
commands sent through a serial interface. In transparent mode, the module acts as a bridge,
transmitting data between connected devices
• Pins: Vcc, Gnd, Tx, Rx, State, En
• The default baud rate for communication with the HC-05 is usually 9600 bps, but it can be
configured using AT commands.
• The HC-05 can be paired with other Bluetooth devices such as smartphones, tablets, or other
Bluetooth-enabled devices. Once paired, data can be exchanged wirelessly.
• You can configure the HC-05 using AT commands to change settings such as the device
name, PIN code, and baud rate

Nehru Nagar, Puttur - 574 203, DK, Karnataka State – INDIA.


Phone:+91-8251-235955, 234555 Fax: 236444, Web: www.vcetputtur.ac.in, E-Mail: [email protected]
Vivekananda College of Engineering & Technology TCP03
[A Unit of Vivekananda Vidyavardhaka Sangha Puttur ®] Rev 1.2
Affiliated to Visvesvaraya Technological University EC
5/2/25
Approved by AICTE New Delhi & Recognised by Govt of Karnataka
COURSE LABORATORY MANUAL

Fig.3. HC-05 module

7. FORMULA / CALCULATIONS:
• -
8. PROGRAM:
import time
import serial
ser = serial.Serial('/dev/ttyS0', baudrate = 9600, parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE, bytesize=serial.EIGHTBITS, timeout=1)
counter=0
while True:
ser.write(b'Write counter: %d \n'%(counter))
print('Printed')
time.sleep(1)
counter += 1
9. BLOCK / CIRCUIT / MODEL DIAGRAM / REACTION EQUATION:

Fig.4. Bluetooth and Rpi interface

10. OBSERVATION TABLE / LOOKUP TABLE / TRUTH TABLE:

Nehru Nagar, Puttur - 574 203, DK, Karnataka State – INDIA.


Phone:+91-8251-235955, 234555 Fax: 236444, Web: www.vcetputtur.ac.in, E-Mail: [email protected]
Vivekananda College of Engineering & Technology TCP03
[A Unit of Vivekananda Vidyavardhaka Sangha Puttur ®] Rev 1.2
Affiliated to Visvesvaraya Technological University EC
5/2/25
Approved by AICTE New Delhi & Recognised by Govt of Karnataka
COURSE LABORATORY MANUAL
• -
11. GRAPHS / OUTPUTS:
• -
12. RESULTS & CONCLUSIONS:
• Data generated in Python is transmitted using serial Tx pin to Bluetooth Rx pin with a Baud
rate of 9600 bps and displayed on bluetooth terminal app installed in Smart phone.
13. LEARNING OUTCOMES :
• Understand the communication between HC-05 and RPi
• Transfer data from Rpi in wireless mode over short range to Smart phone
14. APPLICATION AREAS:
• Home automation using Bluetooth device
15. REMARKS:
• -

1. EXPERIMENT NO:5
2. TITLE: TO INTERFACE BLUETOOTH WITH ARDUINO/RASPBERRY PI AND WRITE A
PROGRAM TO TURN LED ON/OFF WHEN '1'/'0' IS RECEIVED FROM SMARTPHONE
USING BLUETOOTH
3. LEARNING OBJECTIVES:
• To interface Bluetooth device with Rpi and communicate with smartphone
• Understand serial communication between Rpi and HC-05
4. AIM:
• To interface Bluetooth with Arduino/Raspberry Pi and write a program to turn LED
ON/OFF when '1'/'0' is received from smartphone using Bluetooth
5. MATERIAL / EQUIPMENT REQUIRED:
• Raspberry pi-4
• HC-05, Led Module
• Python Interpreter, Thonny IDE
6. THEORY / HYPOTHESIS:
• The HC-05 is a popular Bluetooth module that allows wireless communication between
devices. Here are some key points about the HC-05 Bluetooth module
• The HC-05 is designed for serial communication and is often used to enable Bluetooth
connectivity in electronic projects. It can be used for wireless communication between
microcontrollers, Arduino boards, and other devices
• The HC-05 can operate in two main modes: AT command mode and transparent
communication mode. In AT command mode, you can configure the module using AT
commands sent through a serial interface. In transparent mode, the module acts as a bridge,
transmitting data between connected devices
• Pins: Vcc, Gnd, Tx, Rx, State, En
• The default baud rate for communication with the HC-05 is usually 9600 bps, but it can be
configured using AT commands.
• The HC-05 can be paired with other Bluetooth devices such as smartphones, tablets, or other
Bluetooth-enabled devices. Once paired, data can be exchanged wirelessly.
• You can configure the HC-05 using AT commands to change settings such as the device
name, PIN code, and baud rate

Nehru Nagar, Puttur - 574 203, DK, Karnataka State – INDIA.


Phone:+91-8251-235955, 234555 Fax: 236444, Web: www.vcetputtur.ac.in, E-Mail: [email protected]
Vivekananda College of Engineering & Technology TCP03
[A Unit of Vivekananda Vidyavardhaka Sangha Puttur ®] Rev 1.2
Affiliated to Visvesvaraya Technological University EC
5/2/25
Approved by AICTE New Delhi & Recognised by Govt of Karnataka
COURSE LABORATORY MANUAL
7. FORMULA / CALCULATIONS:
• -
8. PROGRAM:
import serial
import Rpi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(18,GPIO.OUT)
ser = serial.Serial('/dev/ttyS0',baudrate = 9600, parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE, bytesize=serial.EIGHTBITS, timeout=1)
while True:
if ser.in_waiting>0:
if ser.readline().decode('utf-8').rstrip()=='1':
GPIO.output(18,GPIO.HIGH)
elif ser.readline().decode('utf-8').rstrip()=='0':
GPIO.output(18,GPIO.LOW)
9. BLOCK / CIRCUIT / MODEL DIAGRAM / REACTION EQUATION:

Fig.2. Interface Rpi, HC-05 and Led

10. OBSERVATION TABLE / LOOKUP TABLE / TRUTH TABLE:


• -
11. GRAPHS / OUTPUTS:
• -
12. RESULTS & CONCLUSIONS:
• Sensors or actuators connected to Rpi is controlled using Smartphone with HC-05 module
13. LEARNING OUTCOMES :
• Understand how to read data sent from Smartphone to Rpi and control the peripherals
attached
• Serial Communication between Rpi and HC-05 module
14. APPLICATION AREAS:
• Bluetooth based Robot control.
15. REMARKS:
• -

Nehru Nagar, Puttur - 574 203, DK, Karnataka State – INDIA.


Phone:+91-8251-235955, 234555 Fax: 236444, Web: www.vcetputtur.ac.in, E-Mail: [email protected]
Vivekananda College of Engineering & Technology TCP03
[A Unit of Vivekananda Vidyavardhaka Sangha Puttur ®] Rev 1.2
Affiliated to Visvesvaraya Technological University EC
5/2/25
Approved by AICTE New Delhi & Recognised by Govt of Karnataka
COURSE LABORATORY MANUAL
-

1. EXPERIMENT NO:6
2. TITLE: WRITE A PROGRAM ON ARDUINO/RASPBERRY PI TO UPLOAD
TEMPERATURE AND HUMIDITY DATA TO THINGSPEAK CLOUD
3. LEARNING OBJECTIVES:
• Understand thingspeak cloud platform
• Understand how to publish sensor data into thingspeak cloud using python and thingspeak
write API key.
4. AIM:
• Read DT11 sensor data into python environment
• Publish DHT11 sensor data to thingspeak cloud using python program and write API key
5. MATERIAL / EQUIPMENT REQUIRED:
• Raspberry pi-4
• DHT-11
• Python Interpreter, Thonny IDE, Thingspeak cloud
6. THEORY:
• ThingSpeak is an Internet of Things (IoT) platform that allows users to collect, analyze, and
visualize data from sensors or other devices. It provides a platform for building IoT
applications and services without requiring extensive programming knowledge. ThingSpeak
is often used in projects involving home automation, environmental monitoring, and various
other IoT applications.
Features of thingspeak
• Channels: Data is organized into channels, where each channel represents a set of data from
a particular source or device
• Fields: Each channel has multiple fields that correspond to different data parameters. For
example, in a weather monitoring project, you might have fields for temperature, humidity,
and pressure
• APIs: ThingSpeak provides APIs (Application Programming Interfaces) that allow
developers to interact with the platform programmatically. This enables the integration of
ThingSpeak with various hardware platforms and programming languages

7.FORMULA / CALCULATIONS:
• -
8. PROGRAM:
import sys
import urllib.request as urllib2
from time import sleep
import Adafruit_DHT
sensor = Adafruit_DHT.DHT11
pin = 4#GPIO 4 of Rpi
myAPI = 'XXXXXX'
baseURL = 'https://api.thingspeak.com/update?api_key=%s' % myAPI
def DHT11_data():
# Reading from DHT22 and storing the temperature and humidity
humi, temp = Adafruit_DHT.read_retry(sensor, pin)
return humi, temp

Nehru Nagar, Puttur - 574 203, DK, Karnataka State – INDIA.


Phone:+91-8251-235955, 234555 Fax: 236444, Web: www.vcetputtur.ac.in, E-Mail: [email protected]
Vivekananda College of Engineering & Technology TCP03
[A Unit of Vivekananda Vidyavardhaka Sangha Puttur ®] Rev 1.2
Affiliated to Visvesvaraya Technological University EC
5/2/25
Approved by AICTE New Delhi & Recognised by Govt of Karnataka
COURSE LABORATORY MANUAL
while True:
try:
humi, temp = DHT11_data()
print(humi,temp)
if isinstance(humi, float) and isinstance(temp, float):
humi = '%.2f' % humi
temp = '%.2f' % temp
conn = urllib2.urlopen(baseURL + '&field1=%s&field2=%s' % (temp, humi))
print(conn.read())
# Closing the connection
conn.close()
else:
print('Error')
sleep(20)
except:

break
9. BLOCK DIAGRAM:

FIG.1. DHT11 AND RASPBERRY-PI 4 INTERFACE

10. OBSERVATION TABLE / LOOKUP TABLE / TRUTH TABLE:


• -

11. GRAPHS / OUTPUTS:


• -
12. RESULTS & CONCLUSIONS:
• Sensor data in the local machine is pushed on to the thingspeak cloud
13. LEARNING OUTCOMES :
• Understand how to write python script to connect to the thingspeak cloud and publish
sensor data
• Understand the use of write API key during publishing sensor data
14. APPLICATION AREAS:
• Home automation using IoT
15. REMARKS:
• -

Nehru Nagar, Puttur - 574 203, DK, Karnataka State – INDIA.


Phone:+91-8251-235955, 234555 Fax: 236444, Web: www.vcetputtur.ac.in, E-Mail: [email protected]
Vivekananda College of Engineering & Technology TCP03
[A Unit of Vivekananda Vidyavardhaka Sangha Puttur ®] Rev 1.2
Affiliated to Visvesvaraya Technological University EC
5/2/25
Approved by AICTE New Delhi & Recognised by Govt of Karnataka
COURSE LABORATORY MANUAL

1. EXPERIMENT NO:7
2. TITLE: WRITE A PROGRAM ON ARDUINO/RASPBERRY PI TO RETRIEVE
TEMPERATURE AND HUMIDITY DATA FROM THINGSPEAK CLOUD
3. LEARNING OBJECTIVES:
• Understand thingspeak cloud platform
• Understand how to read published sensor data into python environment using thingspeak
read API keys
4. AIM:
• To write python program to read sensor data from the thingspeak cloud and display the
same on the python command prompt
5. MATERIAL / EQUIPMENT REQUIRED:
• Raspberry pi-4
• Python Interpreter, Thonny IDE, Thingspeak cloud
6. THEORY:
• ThingSpeak is an Internet of Things (IoT) platform that allows users to collect, analyze, and
visualize data from sensors or other devices. It provides a platform for building IoT
applications and services without requiring extensive programming knowledge. ThingSpeak
is often used in projects involving home automation, environmental monitoring, and various
other IoT applications
7. FORMULA / CALCULATIONS:

8. PROGRAM:
import urllib.request as urllib2
import json
web=urllib2.urlopen('https://api.thingspeak.com/channels/XXXX/feeds.json?
api_key=XXXXX&results=2')
j=web.read().decode()
data=json.loads(j)
print(data)
print(data['feeds'][0]['field1'])#first temp entry
print(data['feeds'][0]['field2'])#first hum entry
9. BLOCK / CIRCUIT / MODEL DIAGRAM / REACTION EQUATION:
• -
10. OBSERVATION TABLE / LOOKUP TABLE / TRUTH TABLE:
• -
11. GRAPHS / OUTPUTS:
• -
12. RESULTS & CONCLUSIONS:
• Sensor data in the thingspeak cloud is read into the local machines python command prompt
13. LEARNING OUTCOMES :
• Understand the use of thingspeak read API key
14. APPLICATION AREAS:
• -
15. REMARKS:
• -

Nehru Nagar, Puttur - 574 203, DK, Karnataka State – INDIA.


Phone:+91-8251-235955, 234555 Fax: 236444, Web: www.vcetputtur.ac.in, E-Mail: [email protected]
Vivekananda College of Engineering & Technology TCP03
[A Unit of Vivekananda Vidyavardhaka Sangha Puttur ®] Rev 1.2
Affiliated to Visvesvaraya Technological University EC
5/2/25
Approved by AICTE New Delhi & Recognised by Govt of Karnataka
COURSE LABORATORY MANUAL

-
1. EXPERIMENT NO:8
2. TITLE: TO INSTALL SQLITE3 DATABASE ON RASPBERRY PI AND PERFORM BASIC
SQL QUERIES.
3. LEARNING OBJECTIVES:
• To install sqlite3 database in Raspberry-pi
• To understand basic SQL queries including creating DB, creating table, inserting records,
dropping table etc.
• To push random data created using random package into the database using python script
• To read the random data present in DB using python script
4. AIM:
• To install sqlite3 database on Raspberry pi and perform basic operations
• To write python script to perform basic SQL queries
• To read DB content using python scripts
5. MATERIAL / EQUIPMENT REQUIRED:
• Raspberry pi-4
• Python Interpreter, Thonny IDE, sqlite3
6. THEORY:
• SQLite3 is a lightweight, embedded relational database management system (RDBMS) that
is widely used in various applications and software development projects. It is known for its
simplicity, ease of use, and self-contained nature, making it a popular choice for mobile
apps, desktop applications, and embedded systems.
• Command to install sqlite3 in RPI:Open the terminal in RPI and type the following
command
• pi@raspberry: sudo apt-get install sqlite3
• Open the terminal and follow the Commands to create DB, Table and insert records in
sqlite3 DB:
# Open or create a new database file
• sqlite3 mydatabase.db
# Create a table
• CREATE TABLE users (name TEXT, age INTEGER);
# Insert data
• INSERT INTO users (name, age) VALUES ('John Doe', 30);
# Query data
• SELECT * FROM users;
# Exit the SQLite shell
.quit
7. FORMULA / CALCULATIONS:
• -
8. PROGRAM:
#Python program to create database and push random data into the database
import sqlite3
import random
def dht11():
t=random.randint(28,35)
h=t+30
return t,h

Nehru Nagar, Puttur - 574 203, DK, Karnataka State – INDIA.


Phone:+91-8251-235955, 234555 Fax: 236444, Web: www.vcetputtur.ac.in, E-Mail: [email protected]
Vivekananda College of Engineering & Technology TCP03
[A Unit of Vivekananda Vidyavardhaka Sangha Puttur ®] Rev 1.2
Affiliated to Visvesvaraya Technological University EC
5/2/25
Approved by AICTE New Delhi & Recognised by Govt of Karnataka
COURSE LABORATORY MANUAL
con=sqlite3.connect('mydatabase.sqlite')
cur=con.cursor()
cur.execute('DROP TABLE IF EXISTS temphum')
cur.execute('CREATE TABLE temphum(temp int,hum int)')
for i in range(5):
h,t=dht11()
cur.execute('INSERT into temphum(temp,hum) VALUES (?,?)',(t,h))
cur.execute('SELECT * FROM temphum')
for row in cur:
print(row)
con.commit()
con.close()
9. BLOCK / CIRCUIT / MODEL DIAGRAM / REACTION EQUATION:
• -
10. OBSERVATION TABLE / LOOKUP TABLE / TRUTH TABLE:
• -
11. GRAPHS / OUTPUTS:
• -
12. RESULTS & CONCLUSIONS:
• Python programs to write basic SQL queries and read database content were learnt
13. LEARNING OUTCOMES :
• Comprehend how to write SQL queries using python
• Learn about sqlite3 command prompt
• Store random data into the sqlite3 database
14. APPLICATION AREAS:
• Interface DHT11 sensor with RPI and store humidity and temperature sensor in database
15. REMARKS:
• -

-
1. EXPERIMENT NO:10
2. TITLE: PROGRAM TO CREATE UDP SERVER ON RASPBERRY PI AND RESPOND
WITH HUMIDITY DATA TO UDP CLIENT WHEN REQUESTED
3. LEARNING OBJECTIVES:
• To design udp server for establishing communication between server and client
• To design udp client for establishing communication between server and client
4. AIM:
• Program to create udp server on RPI-4 for data transfer
• Program to create udp client on RPI-4 for data transfer
5. MATERIAL / EQUIPMENT REQUIRED:
• Raspberry-pi-4, Thonny IDE
6. THEORY / HYPOTHESIS:
• TCP/IP, which stands for Transmission Control Protocol/Internet Protocol, is a suite of
communication protocols used for interconnecting network devices on the internet. It
provides the foundation for data communication in networks, enabling computers to
communicate and share resources
• Components of TCP/IP: Application, Transport, Network, Data-link layer and Physical

Nehru Nagar, Puttur - 574 203, DK, Karnataka State – INDIA.


Phone:+91-8251-235955, 234555 Fax: 236444, Web: www.vcetputtur.ac.in, E-Mail: [email protected]
Vivekananda College of Engineering & Technology TCP03
[A Unit of Vivekananda Vidyavardhaka Sangha Puttur ®] Rev 1.2
Affiliated to Visvesvaraya Technological University EC
5/2/25
Approved by AICTE New Delhi & Recognised by Govt of Karnataka
COURSE LABORATORY MANUAL
layer
• In the transport layer UDP protocol is used for transporting data. It is connection less and
does not guarantee reliable delivery. It is often used for real-time applications where low
latency is crucial.

Fig.1. TCP/IP protocol

Fig.2. UDP datagram protocol

7. FORMULA / CALCULATIONS:
• -
8. PROCEDURE / PROGRAMME / ACTIVITY:
#udp_server.py
import socket
host="127.0.0.1"
port=8080
server= socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
server.bind((host,port))
msg,addr=server.recvfrom(1024)
print(msg.decode('utf-8'))
server.sendto("Hello client!".encode('utf-8'),addr)
#udp_client.py
import socket
host="127.0.0.1"
port=8080
client=socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
client.sendto("Hello Server!".encode('utf-8'),(host,port))
print(client.recvfrom(1024)[0].decode('utf-8'))
9. BLOCK / CIRCUIT / MODEL DIAGRAM / REACTION EQUATION:
• -
10. OBSERVATION TABLE / LOOKUP TABLE / TRUTH TABLE:

Nehru Nagar, Puttur - 574 203, DK, Karnataka State – INDIA.


Phone:+91-8251-235955, 234555 Fax: 236444, Web: www.vcetputtur.ac.in, E-Mail: [email protected]
Vivekananda College of Engineering & Technology TCP03
[A Unit of Vivekananda Vidyavardhaka Sangha Puttur ®] Rev 1.2
Affiliated to Visvesvaraya Technological University EC
5/2/25
Approved by AICTE New Delhi & Recognised by Govt of Karnataka
COURSE LABORATORY MANUAL
• -
11. GRAPHS / OUTPUTS:
• -
12. RESULTS & CONCLUSIONS:
• Implemented udp_server and udp_client for data communication within the local system
• Implemented udp_server and udp_client for data communication between two devices
13. LEARNING OUTCOMES :
• Understand the basics of tcp/ip protocol for data communication
• Understand how to create udp based server in python with socket programming
• Understand how to create udp based client in python with socket programming
14. APPLICATION AREAS:
• Real time temperature and humidity monitoring using udp server/client model
15. REMARKS:
• -

1. EXPERIMENT NO:11
2. TITLE: PROGRAM TO CREATE UDP SERVER ON RASPBERRY PI AND RESPOND
WITH HUMIDITY DATA TO UDP CLIENT WHEN REQUESTED
3. LEARNING OBJECTIVES:
• To design tcp server for establishing communication between server and client
• To design tcp client for establishing communication between server and client
4. AIM:
• Program to create tcp server on RPI-4 for data transfer
• Program to create tcp client on RPI-4 for data transfer
5. MATERIAL / EQUIPMENT REQUIRED:
• Raspberry-pi-4, Thonny IDE
6. THEORY / HYPOTHESIS:
• TCP/IP, which stands for Transmission Control Protocol/Internet Protocol, is a suite of
communication protocols used for interconnecting network devices on the internet. It
provides the foundation for data communication in networks, enabling computers to
communicate and share resources
• Components of TCP/IP: Application, Transport, Network, Data-link layer and Physical
layer
• In the transport layer TCP protocol is used for transporting data. TCP is responsible for
ensuring the reliable and ordered delivery of data between devices on a network.It breaks
down large messages into smaller packets, numbers them, and sends them to the destination.
The receiving end reassembles these packets into the original message and ensures their
correct order.

Nehru Nagar, Puttur - 574 203, DK, Karnataka State – INDIA.


Phone:+91-8251-235955, 234555 Fax: 236444, Web: www.vcetputtur.ac.in, E-Mail: [email protected]
Vivekananda College of Engineering & Technology TCP03
[A Unit of Vivekananda Vidyavardhaka Sangha Puttur ®] Rev 1.2
Affiliated to Visvesvaraya Technological University EC
5/2/25
Approved by AICTE New Delhi & Recognised by Govt of Karnataka
COURSE LABORATORY MANUAL

Fig.1 TCP protocol

7. FORMULA / CALCULATIONS:
• -
8. PROCEDURE / PROGRAMME / ACTIVITY:
#tcp_server.py
import socket
server=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind(('127.0.0.1',8080))
server.listen()
while True:
client,address=server.accept()
print(f"Connected to {address}")
print(client.recv(1024).decode('utf-8'))
client.send("Hello client!".encode('utf-8'))
print(client.recv(1024).decode('utf-8'))
client.send("Bye!".encode('utf-8'))
client.close()
#tcp_client.py
import socket
client=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
client.connect(("127.0.0.1",8080))
client.send("Hello server!".encode('utf-8'))
print(client.recv(1024).decode('utf-8'))
client.send("Bye!".encode('utf-8'))
print(client.recv(1024).decode('utf-8'))
9. BLOCK / CIRCUIT / MODEL DIAGRAM / REACTION EQUATION:

10. OBSERVATION TABLE / LOOKUP TABLE / TRUTH TABLE:
• -
11. GRAPHS / OUTPUTS:
• -
12. RESULTS & CONCLUSIONS:
• Implemented tcp_server and tcp_client for data communication within the local system
• Implemented tcp_server and tcp_client for data communication between two devices
13. LEARNING OUTCOMES :
• Understand the basics of tcp/ip protocol for data communication

Nehru Nagar, Puttur - 574 203, DK, Karnataka State – INDIA.


Phone:+91-8251-235955, 234555 Fax: 236444, Web: www.vcetputtur.ac.in, E-Mail: [email protected]
Vivekananda College of Engineering & Technology TCP03
[A Unit of Vivekananda Vidyavardhaka Sangha Puttur ®] Rev 1.2
Affiliated to Visvesvaraya Technological University EC
5/2/25
Approved by AICTE New Delhi & Recognised by Govt of Karnataka
COURSE LABORATORY MANUAL
• Understand how to create udp based server in python with socket programming
• Understand how to create udp based client in python with socket programming
14. APPLICATION AREAS:
• Real time temperature and humidity monitoring using tcp server/client model
15. REMARKS:
• -

1. EXPERIMENT NO:9
2. TITLE: WRITE A PROGRAM ON ARDUINO/RASPBERRY PI TO PUBLISH
TEMPERATURE DATA TO MQTT BROKER.
3. LEARNING OBJECTIVES:
• To understand the commands used for programming MQTT mosquito broker
• To understand the commands to publish data into MQTT broker
4. AIM:
• Python program to publish data to MQTT broker
5. MATERIAL / EQUIPMENT REQUIRED:
• Raspberry-pi-4, Thonny IDE
6. THEORY / HYPOTHESIS:
• MQTT, or Message Queuing Telemetry Transport, is a lightweight and open-source
messaging protocol designed for efficient communication between devices in situations
where bandwidth is limited or network conditions may be unreliable. It was originally
developed by IBM in the late 1990s and has become a widely adopted standard for the
Internet of Things (IoT), home automation, and other applications.
• Features of MQTT
• Publish/Subscribe Model: MQTT follows a publish/subscribe messaging pattern. Devices
communicate through a central entity called the broker. Clients can publish messages to
specific topics, and other clients can subscribe to those topics to receive the messages
• MQTT broker(server):The MQTT broker is a server that manages the communication
between devices. It receives messages from publishers and routes them to subscribers based
on topic subscriptions.
• MQTT client: An MQTT client is a device or application that connects to the broker to
either publish messages, subscribe to topics, or both. Clients can act as both publishers and
subscribers.
• Topics: Messages are published to topics, which act as communication channels. Clients
can subscribe to specific topics to receive relevant messages
Steps to install Mosquitto open source MQTT broker into Raspberry Pi
• Open the terminal and type the following commands
• pi@raspberrypi>>sudo apt-get install mosquitto mosquitto-clients
• After installation, to run the mosquitto MQTT broker type
• pi@raspberrypi>>sudo systemctl enable mosquitto.service
• Open two terminals one for subscriber and other one for publisher
• In one of the terminal type the command
• pi@raspberrypi>>mosquitto_sub -d -t “binary/updates”
• In other terminal type the command
• pi@raspberrypi>>mosquitto_pub -d -t “binary/updates” -m “MQTT subscriber

Nehru Nagar, Puttur - 574 203, DK, Karnataka State – INDIA.


Phone:+91-8251-235955, 234555 Fax: 236444, Web: www.vcetputtur.ac.in, E-Mail: [email protected]
Vivekananda College of Engineering & Technology TCP03
[A Unit of Vivekananda Vidyavardhaka Sangha Puttur ®] Rev 1.2
Affiliated to Visvesvaraya Technological University EC
5/2/25
Approved by AICTE New Delhi & Recognised by Govt of Karnataka
COURSE LABORATORY MANUAL
publisher demo”
• In the subscriber terminal published message should be received
• Allow mqtt broker to listen to any clients(communicate with client using Rpi ip address)
• pi@raspberrypi>> sudo nano /etc/mosquitto/mosquitto.conf
• Add two lines to the mosquitto.conf files
listener 1883
allow_anonymous true
• save and exit
Installing mqtt client paho in raspberry-pi for python programming
• pi@raspberrypi>>sudo pip install paho-mqtt

7. FORMULA / CALCULATIONS:
• -
8. PROCEDURE / PROGRAMME / ACTIVITY:
# Import package
import paho.mqtt.client as mqtt
# Define Variables
MQTT_HOST = "192.168.1.25"#RPI IP address use ifconfig to access it.
MQTT_PORT = 1883 #MQTT port address
MQTT_KEEPALIVE_INTERVAL = 5
MQTT_TOPIC = "hello/world"
MQTT_MSG = "Hello MQTT"

# Define on_connect event Handler


def on_connect(mosq, obj, rc):
print ("Connected to MQTT Broker")

# Define on_publish event Handler


def on_publish(client, userdata, mid):
print ("Message Published...")

# Initiate MQTT Client


mqttc = mqtt.Client()

# Register Event Handlers


mqttc.on_publish = on_publish
mqttc.on_connect = on_connect

# Connect with MQTT Broker


mqttc.connect(MQTT_HOST, MQTT_PORT, MQTT_KEEPALIVE_INTERVAL)

# Publish message to MQTT Topic


mqttc.publish(MQTT_TOPIC,MQTT_MSG)

# Disconnect from MQTT_Broker


mqttc.disconnect()
9. BLOCK / CIRCUIT / MODEL DIAGRAM / REACTION EQUATION:

Nehru Nagar, Puttur - 574 203, DK, Karnataka State – INDIA.


Phone:+91-8251-235955, 234555 Fax: 236444, Web: www.vcetputtur.ac.in, E-Mail: [email protected]
Vivekananda College of Engineering & Technology TCP03
[A Unit of Vivekananda Vidyavardhaka Sangha Puttur ®] Rev 1.2
Affiliated to Visvesvaraya Technological University EC
5/2/25
Approved by AICTE New Delhi & Recognised by Govt of Karnataka
COURSE LABORATORY MANUAL

Fig.1. Block diagram ofMQTT broker/subscriber/publisher


10. OBSERVATION TABLE / LOOKUP TABLE / TRUTH TABLE:
• -
11. GRAPHS / OUTPUTS:
• -
12. RESULTS & CONCLUSIONS:
• Verified the communication between MQTT subscriber and MQTT publisher for the
selected topic using MQTT broker
13. LEARNING OUTCOMES :
• Understand the use of MQTT broker in IoT appplications
• Understand how to publish a topic using MQTT broker
14. APPLICATION AREAS:
• Raspberry pi based IoT webserver using MQTT
15. REMARKS:
• -

1. EXPERIMENT NO:12
2. TITLE: WRITE A PROGRAM ON ARDUINO/RASPBERRY PI TO SUBSCRIBE TO MQTT
BROKER FOR TEMPERATURE DATA AND PRINT IT
3. LEARNING OBJECTIVES:
• To understand the commands used for programming MQTT mosquito broker
• To understand the commands to subscribe topic using MQTT broker
4. AIM:
• Python program to subscribe a topic using MQTT broker
5. MATERIAL / EQUIPMENT REQUIRED:
• Raspberry-pi-4, Thonny IDE
6. THEORY / HYPOTHESIS:
• MQTT, or Message Queuing Telemetry Transport, is a lightweight and open-source
messaging protocol designed for efficient communication between devices in situations
where bandwidth is limited or network conditions may be unreliable. It was originally
developed by IBM in the late 1990s and has become a widely adopted standard for the
Internet of Things (IoT), home automation, and other applications.
7. FORMULA / CALCULATIONS:

Nehru Nagar, Puttur - 574 203, DK, Karnataka State – INDIA.


Phone:+91-8251-235955, 234555 Fax: 236444, Web: www.vcetputtur.ac.in, E-Mail: [email protected]
Vivekananda College of Engineering & Technology TCP03
[A Unit of Vivekananda Vidyavardhaka Sangha Puttur ®] Rev 1.2
Affiliated to Visvesvaraya Technological University EC
5/2/25
Approved by AICTE New Delhi & Recognised by Govt of Karnataka
COURSE LABORATORY MANUAL
• -
8. PROCEDURE / PROGRAMME / ACTIVITY:
# Import package
import paho.mqtt.client as mqtt
# Define Variables
MQTT_HOST = "192.168.1.25"
MQTT_PORT = 1883
MQTT_KEEPALIVE_INTERVAL = 5
MQTT_TOPIC = "hello/world"
MQTT_MSG = "Hello MQTT"

# Define on_connect event Handler


def on_connect(mosq, obj, flags, rc):
#Subscribe to a the Topic
mqttc.subscribe(MQTT_TOPIC, 0)

# Define on_subscribe event Handler


def on_subscribe(mosq, obj, mid, granted_qos):
print ("Subscribed to MQTT Topic")

# Define on_message event Handler


def on_message(mosq, obj, msg):
print (msg.payload.decode())

# Initiate MQTT Client


mqttc = mqtt.Client()

# Register Event Handlers


mqttc.on_message = on_message
mqttc.on_connect = on_connect
mqttc.on_subscribe = on_subscribe

# Connect with MQTT Broker


mqttc.connect(MQTT_HOST, MQTT_PORT, MQTT_KEEPALIVE_INTERVAL )

# Continue the network loop


mqttc.loop_forever()
9. BLOCK / CIRCUIT / MODEL DIAGRAM / REACTION EQUATION:
• -
10. OBSERVATION TABLE / LOOKUP TABLE / TRUTH TABLE:
• -
11. GRAPHS / OUTPUTS:
• -
12. RESULTS & CONCLUSIONS:
• Verified the communication between MQTT subscriber and MQTT publisher for the
selected topic using MQTT broker
13. LEARNING OUTCOMES :
• Understand the use of MQTT broker in IoT appplications
• Understand how to subscribe a topic using MQTT broker
Nehru Nagar, Puttur - 574 203, DK, Karnataka State – INDIA.
Phone:+91-8251-235955, 234555 Fax: 236444, Web: www.vcetputtur.ac.in, E-Mail: [email protected]
Vivekananda College of Engineering & Technology TCP03
[A Unit of Vivekananda Vidyavardhaka Sangha Puttur ®] Rev 1.2
Affiliated to Visvesvaraya Technological University EC
5/2/25
Approved by AICTE New Delhi & Recognised by Govt of Karnataka
COURSE LABORATORY MANUAL
14. APPLICATION AREAS:
• Raspberry pi based IoT webserver using MQTT
15. REMARKS:
• -

1. EXPERIMENT NO:13
2. TITLE: GUI DESIGN TO CONTROL LED INTERFACED TO RASPBERRY-PI USING
TKINTER(OPEN ENDED EXPERIMENT-1)
3. LEARNING OBJECTIVES:
• To understand the basics of tkinter widgets
• To program button widget
4. AIM:
• Python program to control led using tkinter package
5. MATERIAL / EQUIPMENT REQUIRED:
• Raspberry-pi-4, Thonny IDE, tkinter
6. THEORY / HYPOTHESIS:
• Tkinter is a standard GUI toolkit in Python used for creating desktop applications. It
provides various widgets like Label, Frame, Button, Entry etc.
7. FORMULA / CALCULATIONS:
• -
8. PROCEDURE / PROGRAMME / ACTIVITY:
from tkinter import *
import RPi.GPIO as GPIO
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(3,GPIO.OUT)
def ledon():
GPIO.output(3,GPIO.HIGH)
def ledoff():
GPIO.output(3,GPIO.LOW)
root=Tk()
root.title('GUI based LED control using tkinter')
root.geometry('320x240')
l1=Label(root, text='GUI based LED ccontrol')
l1.pack()
b1=Button(root,text='LED ON',command=ledon)
b1.pack()
b2=Button(root,text='LED OFF',command=ledoff)
b2.pack()
root.mainloop()
9. BLOCK / CIRCUIT / MODEL DIAGRAM / REACTION EQUATION:
• -
10. OBSERVATION TABLE / LOOKUP TABLE / TRUTH TABLE:
• -
11. GRAPHS / OUTPUTS:

Nehru Nagar, Puttur - 574 203, DK, Karnataka State – INDIA.


Phone:+91-8251-235955, 234555 Fax: 236444, Web: www.vcetputtur.ac.in, E-Mail: [email protected]
Vivekananda College of Engineering & Technology TCP03
[A Unit of Vivekananda Vidyavardhaka Sangha Puttur ®] Rev 1.2
Affiliated to Visvesvaraya Technological University EC
5/2/25
Approved by AICTE New Delhi & Recognised by Govt of Karnataka
COURSE LABORATORY MANUAL

Fig.1. GUI App to control LED


12. RESULTS & CONCLUSIONS:
• Observed the controlling of LED on button press
13. LEARNING OUTCOMES :
• Understand how to design user interfaces in python
• Understand how to control peripherals interfaced to RPI using user interfaces
14. APPLICATION AREAS:

15. REMARKS:
• -

1. EXPERIMENT NO:13
2. TITLE: VOICE BASED HOME AUTOMATION USING QPYTHON AND TCP
SERVER/CLIENT PROTOCOL(OPEN ENDED EXPERIMENT-2)
3. LEARNING OBJECTIVES:
• Write python programs in android smartphones
• Communicate between Rpi and Smartphone using voice commands
4. AIM:
• Python program to control appliances connected to Raspberry pi using voice commands
5. MATERIAL / EQUIPMENT REQUIRED:
• Raspberry-pi-4, Thonny IDE, Qpython
6. THEORY / HYPOTHESIS:
• Qpython is a python interpreter for Android devices. It allows us to run python scripts and
projects directly on Android phone or tablet.
7. FORMULA / CALCULATIONS:
• -
8. PROCEDURE / PROGRAMME / ACTIVITY:
#tcp_server.py(to be executed in RPI)
import socket
import time
import RPi.GPIO as GPIO
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)

Nehru Nagar, Puttur - 574 203, DK, Karnataka State – INDIA.


Phone:+91-8251-235955, 234555 Fax: 236444, Web: www.vcetputtur.ac.in, E-Mail: [email protected]
Vivekananda College of Engineering & Technology TCP03
[A Unit of Vivekananda Vidyavardhaka Sangha Puttur ®] Rev 1.2
Affiliated to Visvesvaraya Technological University EC
Approved by AICTE New Delhi & Recognised by Govt of Karnataka 30/11/23
COURSE LABORATORY MANUAL
GPIO.setup(3,GPIO.OUT)
server=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind(('192.168.96.57',8080))
server.listen()
while True:
client,address=server.accept()
print(f"Connected to {address}")
data=client.recv(1024).decode('utf-8')
time.sleep(1)
if data=='LED on':
GPIO.output(3,GPIO.HIGH)
client.send("Hello client!".encode('utf-8'))
elif data=='LED of':
GPIO.output(3,GPIO.LOW)
client.send("Hello client!".encode('utf-8'))
else:
client.send("Hello client!".encode('utf-8'))
client.close()

#tcp_client.py(to be executed in mobile device)


import androidhelper as android
import socket
droid=android.Android()
text=droid.recognizeSpeech()[1]
client=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
client.connect(('192.168.96.57',8080))
client.send(text.encode('utf-8'))
print(client.recv(1024).decode('utf-8'))
9. BLOCK / CIRCUIT / MODEL DIAGRAM / REACTION EQUATION:
• -
10. OBSERVATION TABLE / LOOKUP TABLE / TRUTH TABLE:

11. GRAPHS / OUTPUTS:

12. RESULTS & CONCLUSIONS:
• LED connected to the RPI is controlled using voice commands
13. LEARNING OUTCOMES :
• Understand how to write python program and run the same in mobile devices using qpython
• Understand how to control peripheral connected to RPI using smartphone with voice
commands
14. APPLICATION AREAS:

15. REMARKS:
• -

Nehru Nagar, Puttur - 574 203, DK, Karnataka State – INDIA.


Phone:+91-8251-235955, 234555 Fax: 236444, Web: www.vcetputtur.ac.in, E-Mail: [email protected]

You might also like