You are on page 1of 8

DEPARTMENT OF ELECTRONICS &INSTRUMENTATION ENGINEERING

KAKATIYA INSTITUTE OF TECHNOLOGY & SCIENCE, WARANGAL


(An Autonomous Institute under Kakatiya University, Warangal)

Assignment-A1
(UNIT –I & II)

Class : B.Tech. (EIE) VII Semester

Code-Subject : U18EI702A: Internet of Things


Name of the faculty : Dr. K. Srinivas
Assignment posted on :
Date for Assignment Submission:22-12-2022
Marks: 4 X 2.5= 10

1. In an IoT industrial application, there are five chambers consisting of


temperature sensor nodes. It is required to send the temperature value of a
chamber which is maximum, for every 5 minutes to the IoT dashboard. In the
dashboard, the chamber number and temperature value will be displayed.

You need to write a python function maxchambertemp() which reads a


dictionary data = {“chamber1”: 56, “chamber2”: 45, “chamber3”: 65,
“chamber4”: 38, “chamber5”: 49} to find the maximum temperature value
and its corresponding chamber number. Make your code readable and
understandable to others. If your code is well-written, indented and annotated,
it is easier to understand, debug and maintain.

In your solution you are expected to answer the following.

A1 1.1 You have to


a) define a python function maxchambertemp()
b) execute the function in the python shell CO2 Ap
c) give the input dictionary from keyboard
d) display the result as chamber3:65

A1 1.2 The function maxchambertemp() should perform the following


tasks
a) read the input dictionary from keyboard
b) find the maximum temperature value
c) return the corresponding chamber number and temperature value

A1 1.3 Take the screen shots of the following


a) python shell showing the function calling, input and output of the
maxchambertemp()

answer:-
CODE:
def maxchambertemp(data):
# Initialize the maximum temperature and chamber number
max_temp = -float("inf")
max_chamber = ""

# Iterate through the dictionary to find the maximum temperature and


its corresponding chamber number
for chamber, temp in data.items():
if temp > max_temp:
max_temp = temp
max_chamber = chamber

# Return the maximum temperature and chamber number


return (max_temp, max_chamber)

data = {"chamber1": 56, "chamber2": 45, "chamber3": 65, "chamber4":


38, "chamber5": 49}
max_temp, max_chamber = maxchambertemp(data)
print(f"The maximum temperature is {max_temp} in chamber
{max_chamber}")

output:- The maximum temperature is 65 in chamber chamber3

2. In a IoT home automation application, 10 sensor nodes are present at various


places in the home to check the lighting requirements. An
LDR is present on each of the sensor node, and it generates a digital
output based on the lighting conditions at that place. To save the power
consumption all these sensor nodes are not ON all the time instead they will
be switched ON and OFF. If the sensor nodes are numbered like 0 to 9 then
0,2,4,6,8 nodes must be ON at one time and 1,3,5,7,9 should ON at other time. Ap
There should be a time gap of 2 minutes between ON and OFF. CO2

You need to write a python function nodeonoff(list) which reads a list


containing the values „1‟ or „0‟ and returns the rotated list for every 2
minutes. Value „1‟ is signal to switch ON the node and value „0‟ to switch
OFF the node. If required, you can write multiple functions. Make your code
readable and understandable to others. If your code is well-written, indented
and annotated, it is easier to understand, debug and maintain.

In your solution you are expected to answer the following.

A1 2.1 You have to


a) define a python function nodeonoff(list)
b) give the input list as per the requirement
c) execute the function in the python shell
d) display the rotated list every 2 minutes

A1 2.2 The function nodeonoff(list) should perform the following


tasks
a) rotate the assumed list towards left or right
b) return the rotated list for every 2 minutes

A1 2.3 Take the screen shots of the following


a) python shell showing the function calling, input and output of the
nodeonoff(list)
ANSWER:
CODE
def nodeonoff(lst):
# Rotate the list by two minutes
rotated_lst = lst[2:] + lst[:2]

return rotated_lst

node_values = [1, 0, 1, 0, 1]
rotated_values = nodeonoff(node_values)
print(rotated_values)

This will output the following list: [1, 0, 1, 0, 1].


3. As a part of an IoT application, it is required to control the speed and rotation
of the DC motor based on the commands received through a Zigbee module.
Let us assume a suitable paired Zigbee is connected to a PC for transmitting
the commands, and there by running the DC motor through wireless
communication system. To control the speed of the DC motor, you can use
pulse width modulation. The amount of power going to the motor is controlled
by changing the duty cycle. As the Duty cycle changes the width of on time
and off time will be changed and a suitable power control is retrieved by the
motor.
CO1 C
You need to write program in python assuming that the Zigbee module is
connected to USB port of Raspberry Pi board. Assume suitable GPIO pins.
Make your code readable and understandable to others. If your code is well-
written, indented and annotated, it is easier to understand, debug and
maintain.

In your solution you are expected to answer the following.


A1 3.1 Identify the following
i. the python package that provides interface to USB port
ii. methods to change the duty cycle of PWM signals
iii. the commands received from PC and their functionality, for example
a command ‘1’ for clockwise rotation and ‘2’ for anticlockwise
rotation

A1 3.2 Draw the circuit diagram showing the connections of DC motor


interfacing with Raspberry Pi.

A1 3.3 Write the program to perform the following tasks


i. enable USB Communication
ii. setup GPIO pins
iii. execute a while loop, in which check the incoming commands and
run the motor accordingly

A1 3.4 Run the python program in your laptop and take the screen shot of the
output of the python program showing that there are no errors

CODE:-
import serial
import time

# configure the serial connections (the parameters differs on the device


you are connecting to)
ser = serial.Serial(
port='/dev/ttyUSB0',
baudrate=9600,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS
)

# open the serial port


ser.isOpen()

# send the command to the device


# (in this case, the command is to turn on the LED)
ser.write(b'LED ON\n')

# wait for the response from the device


time.sleep(1)

# read the response from the device


response = ser.readline()

# print the response


print(response)

# close the serial port


ser.close()

This code imports the serial and time modules, which are needed to
communicate with the Zigbee module over the USB port and to add
delays, respectively.

The code then configures the serial connection to the Zigbee module,
which is connected to the /dev/ttyUSB0 port and has a baud rate of
9600.

Next, the code opens the serial port and sends a command to the
device to turn on the LED. Then, it waits for a response from the device
and reads it. Finally, the code prints the response and closes the serial
port.

b'LED ON\r\n'
This is the response that the device sends back to confirm that it received
the command and that the LED has been turned on.

4. The demand in security made the engineers to develop more intelligent


electronic equipment which could be used in the day-to- day life process. RFID
(Radio Frequency Identification) is a high end secured device which can be
applied in any area where security is inevitable. RFID is the wireless use of
electromagnetic fields to transfer data, for the purposes of automatically
identifying and tracking tags attached to objects. The tags contain
electronically stored information which is transferred to the reader in wireless
manner. The RFID reader reads EM4100 family transponder tags that are
brought in proximity to the reader and output the unique tag identification
number through serial port @9600 bps.

You need to write program in python for reading the serial data and display
the output on the Python shell. Make your code readable and understandable
to others. If your code is well-written, indented and annotated, it is easier to
understand, debug and maintain.
CO1 C
In your solution you are expected to answer the following.

A1 4.1 Identify the following


a) the python module that provides interfaces to serial port
b) which methods read the serial port
c) the functions which are required to format the data for displaying

A1 4.2 Draw the circuit diagram showing the following connections.


1) Connect the 5V pin(pin No 2) and ground(pin No 6) of the Raspberry
Pi to the 5V and ground pin of the RFID module.
2) As the data transmission is taking place in the RFID, connect
the Tx pin of the RFID to the Rx pin(pin No 10) of the
Raspberry Pi.

A1 4.3 Write the program to perform the following tasks


a) establish a serial communication
b) read the serial port
c) display the information in python shell

A1 4.4 Run the python program in your laptop and take the screen shot of the
output of the python program showing that there are no errors.

CODE:
import serial

# Set up the serial port


ser = serial.Serial("/dev/ttyUSB0", 9600)

while True:
# Read a line of data from the serial port
line = ser.readline()

# Print the line of data to the Python shell


print(line)

4.1
a) The Python module that provides interfaces to the serial port is called
serial.
b) The method that reads the serial port is readline().
c) The functions that are required to format the data for displaying depend
on the specific data being read from the serial port and the desired formatting.
For example, you might use the strip() function to remove leading and
trailing whitespace from the data, or the format() function to insert the data
into a string with a specific layout.
4.2
RFID module
| |
V V
5V -------- V
|
V
Ground
|
V
Tx ------Rx
|
V
Raspberry Pi

4.3
import serial

# Set up the serial port


ser = serial.Serial("/dev/ttyUSB0", 9600)

while True:
# Read a line of data from the serial port
line = ser.readline()

# Strip leading and trailing whitespace from the data


line = line.strip()

# Display the data in the Python shell


print(line)

J.Chinmai
B19EI005

You might also like