Professional Documents
Culture Documents
&TECHNOLOGY
FOR WOMEN
(Approved by AICTE, New Delhi and Affiliated to JNTUH)
Nizampet Cross Road, JNTUH Kukatpally Hyderabad–500085
LABORATORY MANUAL
C PROGRAMMING FOR ENGINEERS
LABORATORY
I List of Experiments ii
II V/M /POs/PSOs/PEOs iv
III Syllabus ix
i
List of Experiments
ii
RISHI M.S INSTITUTE OF ENGINEERING & TECHNOLOGY FOR WOMEN
(Affiliated to JNTUH University, Approved by AICTE)
To be a center of excellence in producing women engineers and scientists who are professionally
competent social leaders to face multi-disciplinary global environment by imparting quality technical
education, values and ethics through innovation methods of teaching and learning.
To promote women technocrats capable enough to resolve the problems faced by the society using
the knowledge imparted.
To prepare self-reliant women engineering for technological growth of the nation and society by
laying strong theoretical foundation accompanied by wide practical training.
To equip the young women with creative thinking capabilities and empowering them towards
innovation.
iii
RISHI M.S INSTITUTE OF ENGINEERING & TECHNOLOGY FOR WOMEN
(Affiliated to JNTUH University, Approved by AICTE)
Adopting creative techniques to nurture and strengthen the core skill of Computer Science.
Introduce students to the most recent technological advancements.
Impart quality education, improve the research, entrepreneurial, and employability skills of women
technocrats.
Instill professional ethics and a sense of social responsibility in students.
Strengthen the Industry-Academia interface, which will enable graduates to emerge as
academic leaders or inspiring entrepreneurs
iv
RISHI M.S INSTITUTE OF ENGINEERING & TECHNOLOGY FOR WOMEN
(Affiliated to JNTUH University, Approved by AICTE)
v
RISHI M.S INSTITUTE OF ENGINEERING & TECHNOLOGY FOR WOMEN
(Affiliated to JNTUH University, Approved by AICTE)
PSO 1: Improve the student's ability to decipher the basic principles and methodology of computer
systems. Improve the students' ability to absorb facts and technical ideas in order to build and
develop software.
PSO 2: The capacity to create novel job routes as an entrepreneur using modern computer languages
and evolving technologies like SDLC, Python, Machine Learning, Social Networks, Cyber
Security, Mobile Apps etc.
vi
RISHI M.S INSTITUTE OF ENGINEERING & TECHNOLOGY FOR WOMEN
(Affiliated to JNTUH University, Approved by AICTE)
PEO-1: Engineering graduates with excellent fundamental and technical skills will have
successful careers in industry, meeting the needs of Indian and worldwide firms.
PEO-2: With determination, development, self-reliance, leadership, morality, and moral principles,
engineering graduates will become successful entrepreneurs who will leverage employability.
PEO-3: To support personal and organisational progress, engineering graduates will pursue higher
education and engage in lifelong learning.
vii
SYLLABUS
IOT FOR ENGINEERS LABORATORY
B. TECH II Year I Sem
Week -1:
Using raspberry pi
a. Calculate the distance using a distance sensor.
b. Basic LED functionality.
TEXT BOOKS:
1. Internet of Things - A Hands-on Approach, Arshdeep Bahga and Vijay Madisetti, Universities Press,
2015, ISBN: 9788173719547
2. Getting Started with Raspberry Pi, Matt Richardson & Shawn Wallace, O'Reilly (SPD), 2014, ISBN:
9789350239759
REFERENCE BOOKS:
1. Bernd Scholz-Reiter, Florian Michahelles, “Architecting the Internet of Things”, ISBN 978-3- 642-19156-5 e-
ISBN 978-3-642-19157-2, Springer, 2016.
2. N. Ida, Sensors, Actuators and Their Interfaces, SciTech Publishers, 2014.
viii
Course Objectives:
● To introduce the raspberry PI platform, that is widely used in IoT applications.
● To introduce the implementation of distance sensor on IoT devices.
Course Outcomes:
Ability to introduce the concept of M2M (machine to machine) with necessary protocols and get awareness in
implementation of distance sensor.
Get the skill to program using python scripting language which is used in many IoT devices.
CO - PO MAPPING:
CO PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12
Python CO1 3 2 1 1 1 1 - - 1 1 1
Programming
Lab
CO2 1 2 3 2 1 2 1 1 1
CO - PSO MAPPING:
PSO-1 PSO-2
CO1 1 3
CO2 2 3
ix
Week 1
EXPERIMENT NO:
Using raspberry pi
a. Calculate the distance using a distance sensor. b. Basic LED functionality.
PROGRAM:
RESULT:
xi
B. Use a Raspberry Pi to implement basic LED functionality:
Connect the LED to the Raspberry Pi's GPIO pins, with a resistor in series to protect the LED from excessive
current.
Install the required libraries and packages (e.g. RPi.GPIO, time, etc.).
Write a script in Python to control the GPIO pin connected to the LED and turn it on and off.
Run the script on the Raspberry Pi to control the LED.
PROGRAM:
This code sets up the GPIO pin 18 as an output and turns the LED on for 1 second and then off. You can modify
the code to implement different LED functionality, such as blinking, fading, etc.
RESULT:
VIVA QUESTIONS:
xii
SYLLABUS
IOT FOR ENGINEERS LABORATORY
B. TECH II Year I Sem
Week -2:
Using Arduino
a. Calculate the distance using a distance sensor.
b. Basic LED functionality.
c. Calculate temperature using a temperature sensor.
TEXT BOOKS:
1. Internet of Things - A Hands-on Approach, Arshdeep Bahga and Vijay Madisetti, Universities Press,
2015, ISBN: 9788173719547
2. Getting Started with Raspberry Pi, Matt Richardson & Shawn Wallace, O'Reilly (SPD), 2014, ISBN:
9789350239759
REFERENCE BOOKS:
1. Bernd Scholz-Reiter, Florian Michahelles, “Architecting the Internet of Things”, ISBN 978-3- 642-19156-5 e-
ISBN 978-3-642-19157-2, Springer, 2016.
2. N. Ida, Sensors, Actuators and Their Interfaces, SciTech Publishers, 2014.
xiii
Course Objectives:
● To introduce the raspberry PI platform, that is widely used in IoT applications.
● To introduce the implementation of distance sensor on IoT devices.
Course Outcomes:
Ability to introduce the concept of M2M (machine to machine) with necessary protocols and get awareness in
implementation of distance sensor.
Get the skill to program using python scripting language which is used in many IoT devices.
CO - PO MAPPING:
CO PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12
Python CO1 2 2 2 3 1 2 - - 1 1 1
Programming
Lab
CO2 2 3 1 3 2 1 1 1 1
CO - PSO MAPPING:
PSO-1 PSO-2
CO1 2 1
CO2 1 2
xiv
Week 2
EXPERIMENT NO:
Using Arduino
a. Calculate the distance using a distance sensor.
b. Basic LED functionality.
c. Calculate temperature using a temperature sensor.
PROGRAM:
#include <NewPing.h>
#define TRIGGER_PIN 12
#define ECHO_PIN 11
#define MAX_DISTANCE 200
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);
void setup() {
Serial.begin(9600);
}
void loop() {
delay(50);
int distance = sonar.ping_cm();
Serial.print("Distance: ");
Serial.print(distance);
Serial.println(" cm");
}
This code uses the NewPing library to calculate the distance using the sensor connected to digital pins
12 and 11. The distance is displayed on the serial monitor and updated every 50 milliseconds.
RESULT:
xv
B. Use Arduino to implement basic LED functionality:
Connect the LED to the Arduino's digital pins, with a resistor in series to protect the LED from excessive
current.
Write a sketch in the Arduino IDE to control the digital pin connected to the LED and turn it on and
off.
Upload the sketch to the Arduino to control the LED.
Here's an example code that demonstrates this process:
PROGRAM:
This code sets up digital pin 13 as an output and turns the LED on and off every 1 second. You can modify the
code to implement different LED functionality, such as blinking, fading, etc.
RESULT:
xvi
C. Use Arduino to Calculate temperature using a temperature sensor:
Connect the temperature sensor (e.g. LM35) to the Arduino's analog pins.
Write a sketch in the Arduino IDE to read the sensor data and convert it into a temperature
value.
Display the temperature output on the serial monitor or send it to a remote server for storage
and processing.
Upload the sketch to the Arduino to get the temperature readings.
Here's an example code that demonstrates this process:
PROGRAM:
This code reads the analog voltage from the temperature sensor connected to analog pin A0 and converts it into a
temperature value in degrees Celsius. The temperature is displayed on the serial monitor and updated every
1second.
RESULT:
VIVA QUESTIONS:
Define Arduino
What is temperature sensor
xvii
SYLLABUS
IOT FOR ENGINEERS LABORATORY
B. TECH II Year I Sem
Week -3:
Using Node MCU
a. Calculate the distance using a distance sensor.
b. Basic LED functionality.
c. Calculate temperature using a temperature sensor.
TEXT BOOKS:
1. Internet of Things - A Hands-on Approach, Arshdeep Bahga and Vijay Madisetti, Universities Press,
2015, ISBN: 9788173719547
2. Getting Started with Raspberry Pi, Matt Richardson & Shawn Wallace, O'Reilly (SPD), 2014, ISBN:
9789350239759
REFERENCE BOOKS:
1. Bernd Scholz-Reiter, Florian Michahelles, “Architecting the Internet of Things”, ISBN 978-3- 642-19156-5 e-
ISBN 978-3-642-19157-2, Springer, 2016.
2. N. Ida, Sensors, Actuators and Their Interfaces, SciTech Publishers, 2014.
xvii
i
Course Objectives:
● To introduce the raspberry PI platform, that is widely used in IoT applications.
● To introduce the implementation of distance sensor on IoT devices.
Course Outcomes:
Ability to introduce the concept of M2M (machine to machine) with necessary protocols and get awareness in
implementation of distance sensor.
Get the skill to program using python scripting language which is used in many IoT devices.
CO - PO MAPPING:
CO PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12
Python CO1 1 3 2 1 1 1 - - 1 1 1
Programming
Lab
CO2 2 3 1 2 1 2 1 1 1
CO - PSO MAPPING:
PSO-1 PSO-2
CO1 1 1
CO2 3 3
xix
Week 3
EXPERIMENT NO:
Using Node MCU
a. Calculate the distance using a distance sensor.
b. Basic LED functionality.
c. Calculate temperature using a temperature sensor.
PROGRAM:
-- Trigger pin will be used to send a signal to the sensor to measure distance
local trigger_pin = 4
-- Echo pin will be used to receive the signal back from the sensor
local echo_pin = 3
-- Set trigger_pin as an output pin
gpio.mode(trigger_pin, gpio.OUTPUT)
-- Set echo_pin as an input pin
gpio.mode(echo_pin, gpio.INPUT)
-- Function to calculate distance
function get_distance()
-- Send a 10us pulse to trigger the measurement
gpio.write(trigger_pin, gpio.HIGH)
tmr.delay(10)
gpio.write(trigger_pin, gpio.LOW)
-- Measure the duration of the pulse received back on the echo pin
local duration = pulse_in(echo_pin, gpio.HIGH)
-- Calculate the distance based on the duration
local distance = duration / 58
xx
-- Return the calculated distance
return distance
end
-- Call the get_distance function and print the result
print("Distance: " .. get_distance() .. " cm")
This is just a basic example and you may need to modify the code based on your specific requirements. You can
also use a library such as the HC-SR04 library in NodeMCU to simplify the process.
RESULT:
xxi
B. Using Node MCU to Basic LED functionality in IOT with output:
To control a basic LED in IoT with NodeMCU, you can use the following steps:
Connect the LED to the NodeMCU board.
Write a program in Lua to control the state of the LED (on or off).
Use the NodeMCU's Wi-Fi capability to send commands to the LED to turn it on or off.
On a remote device, such as a smartphone or a computer, you can create a user interface to send the commands
to the NodeMCU.
Here is an example code in Lua to control an LED connected to pin D1 on the NodeMCU board:
PROGRAM:
-- LED pin
local led_pin = 1
-- Set the LED pin as an output pin
gpio.mode(led_pin, gpio.OUTPUT)
-- Function to turn the LED on
function turn_on_led()
gpio.write(led_pin, gpio.HIGH)
end
-- Function to turn the LED off
function turn_off_led()
gpio.write(led_pin, gpio.LOW)
end
-- Call the turn_on_led function to turn the LED on
turn_on_led()
-- Wait for 2 seconds
tmr.delay(2000000)
-- Call the turn_off_led function to turn the LED off
turn_off_led()
This is just a basic example and you can modify it to fit your specific requirements. You can also use the
NodeMCU API to create a web server that allows you to control the LED through a web browser.
RESULT:
xxii
C. Using Node MCU to Calculate temperature using a temperature sensor:
To calculate temperature using a temperature sensor in IoT with NodeMCU, you would need to
connect the temperature sensor to the NodeMCU board. Then you would need to write a program in the
Lua programming language to read the temperature from the sensor and send it to a remote server. Here
is an example of how this can be done:
Connect the temperature sensor to the NodeMCU board.
Write a program in Lua to read the temperature from the sensor and store it in a variable.
Use the NodeMCU's Wi-Fi capability to send the temperature data to a remote server.
On the remote server, process the data and display the temperature on a webpage.
Here is an example code in Lua to read the temperature from a DS18B20 temperature sensor
PROGRAM:
This is just a basic example and you may need to modify the code based on your specific requirements.
You can also use a library such as the DS18B20 library in NodeMCU to simplify the process.
RESULT:
VIVA QUESTIONS:
Define Node MCU
xxii
i
SYLLABUS
IOT FOR ENGINEERS LABORATORY
B. TECH II Year I Sem
Week -4:
Installing OS on Raspberry Pi
a) Installation using PiImager
b) Installation using image file
● Downloading an Image
● Writing the image to an SD card
● using Linux
● using Windows
● Booting up Follow the instructions given in the URL
https://www.raspberrypi.com/documentation/computers/getting-started.html
TEXT BOOKS:
1. Internet of Things - A Hands-on Approach, Arshdeep Bahga and Vijay Madisetti, Universities Press,
2015, ISBN: 9788173719547
2. Getting Started with Raspberry Pi, Matt Richardson & Shawn Wallace, O'Reilly (SPD), 2014, ISBN:
9789350239759
REFERENCE BOOKS:
1. Bernd Scholz-Reiter, Florian Michahelles, “Architecting the Internet of Things”, ISBN 978-3- 642-19156-5 e-
ISBN 978-3-642-19157-2, Springer, 2016.
2. N. Ida, Sensors, Actuators and Their Interfaces, SciTech Publishers, 2014.
xxi
v
Course Objectives:
● To introduce the raspberry PI platform, that is widely used in IoT applications.
● To introduce the implementation of distance sensor on IoT devices.
Course Outcomes:
Ability to introduce the concept of M2M (machine to machine) with necessary protocols and get awareness in
implementation of distance sensor.
Get the skill to program using python scripting language which is used in many IoT devices.
CO - PO MAPPING:
CO PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12
Python CO1 3 2 1 1 1 1 - - 1 1 1
Programming
Lab
CO2 1 2 3 2 1 2 1 1 1
CO - PSO MAPPING:
PSO-1 PSO-2
CO1 1 3
CO2 2 3
xxv
Week 4
EXPERIMENT NO:
Installing OS on Raspberry Pi
a) Installation using PiImager
b) Installation using image file
● Downloading an Image
● Writing the image to an SD card
● using Linux
● using Windows
● Booting up Follow the instructions given in the URL
https://www.raspberrypi.com/documentation/computers/getting-started.html
AIM:
PROGRAM:
RESULT:
VIVA QUESTIONS:
xxv
i
SYLLABUS
IOT FOR ENGINEERS LABORATORY
B. TECH II Year I Sem
Week -5:
5. Accessing GPIO pins using Python
a) Installing GPIO Zero library.
First, update your repositories list:
sudo apt update
Then install the package for Python 3:
sudo apt install python3-gpiozero
b) Blinking an LED connected to one of the GPIO pin
c) Adjusting the brightness of an LED Adjust the brightness of an LED (0 to 100, where 100 means
maximum brightness) using the in-built PWM wavelength.
TEXT BOOKS:
1. Internet of Things - A Hands-on Approach, Arshdeep Bahga and Vijay Madisetti, Universities Press,
2015, ISBN: 9788173719547
2. Getting Started with Raspberry Pi, Matt Richardson & Shawn Wallace, O'Reilly (SPD), 2014, ISBN:
9789350239759
REFERENCE BOOKS:
1. Bernd Scholz-Reiter, Florian Michahelles, “Architecting the Internet of Things”, ISBN 978-3- 642-19156-5 e-
ISBN 978-3-642-19157-2, Springer, 2016.
2. N. Ida, Sensors, Actuators and Their Interfaces, SciTech Publishers, 2014.
xxv
ii
Course Objectives:
● To introduce the raspberry PI platform, that is widely used in IoT applications.
● To introduce the implementation of distance sensor on IoT devices.
Course Outcomes:
Ability to introduce the concept of M2M (machine to machine) with necessary protocols and get awareness in
implementation of distance sensor.
Get the skill to program using python scripting language which is used in many IoT devices.
CO - PO MAPPING:
CO PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12
Python CO1 3 2 1 1 1 1 - - 1 1 1
Programming
Lab
CO2 1 2 3 2 1 2 1 1 1
CO - PSO MAPPING:
PSO-1 PSO-2
CO1 1 3
CO2 2 3
xxv
iii
Week 5
EXPERIMENT NO:
Accessing GPIO pins using Python
a) Installing GPIO Zero library.
First, update your repositories list:
sudo apt update
Then install the package for Python 3:
sudo apt install python3-gpiozero
b) Blinking an LED connected to one of the GPIO pin
c) Adjusting the brightness of an LED Adjust the brightness of an LED (0 to 100, where 100 means
maximum brightness) using the in-built PWM wavelength.
AIM:
PROGRAM:
RESULT:
VIVA QUESTIONS:
xxi
x
xxx
SYLLABUS
IOT FOR ENGINEERS LABORATORY
B. TECH II Year I Sem
Week -6:
Collecting Sensor Data
a) DHT Sensor interface
● Connect the terminals of DHT GPIO pins of Raspberry Pi.
● Import the DHT library using import Adafruit_DHT
● Read sensor data and display it on screen.
TEXT BOOKS:
1. Internet of Things - A Hands-on Approach, Arshdeep Bahga and Vijay Madisetti, Universities Press,
2015, ISBN: 9788173719547
2. Getting Started with Raspberry Pi, Matt Richardson & Shawn Wallace, O'Reilly (SPD), 2014, ISBN:
9789350239759
REFERENCE BOOKS:
1. Bernd Scholz-Reiter, Florian Michahelles, “Architecting the Internet of Things”, ISBN 978-3- 642-19156-5 e-
ISBN 978-3-642-19157-2, Springer, 2016.
2. N. Ida, Sensors, Actuators and Their Interfaces, SciTech Publishers, 2014.
xxx
i
Course Objectives:
● To introduce the raspberry PI platform, that is widely used in IoT applications.
● To introduce the implementation of distance sensor on IoT devices.
Course Outcomes:
Ability to introduce the concept of M2M (machine to machine) with necessary protocols and get awareness in
implementation of distance sensor.
Get the skill to program using python scripting language which is used in many IoT devices.
CO - PO MAPPING:
CO PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12
Python CO1 3 2 1 1 1 1 - - 1 1 1
Programming
Lab
CO2 1 2 3 2 1 2 1 1 1
CO - PSO MAPPING:
PSO-1 PSO-2
CO1 1 3
CO2 2 3
xxx
ii
Week 6
EXPERIMENT NO:
Collecting Sensor Data
a) DHT Sensor interface
● Connect the terminals of DHT GPIO pins of Raspberry Pi.
● Import the DHT library using import Adafruit_DHT
● Read sensor data and display it on screen.
AIM:
PROGRAM:
RESULT:
VIVA QUESTIONS: