IOT and Applications - Lab Manual

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 62

GOVERNMENT ENGINEERING COLLEGE-

PATAN
A Laboratory Manual for

IoT and Applications


(3160716)
B.E. Semester6(Computer Engineering)

Directorate of Technical
Education,Gandhinagar,Gujarat

1
Government Engineering College-Patan
Department of Computer Engineering

CERTIFICATE

This is to certify that Mr./Ms. ____________________________________

Enrollment No. _______________ of B.E. Semester ________ from

Computer Science and Engineering Department of this Institute (GTU

Code: 022) has satisfactorily completed the Practical / Tutorial work for

the subject IoT and Applications(3160716) for the academic year

________.

Place: ___________

Date: ___________

Signature of Course Faculty Head of the Department


2
3
IoT and Applications (3160716)

Preface

Main motto of any laboratory/practical/field work is for enhancing required skills as well as
creating ability amongst students to solve real time problem by developing relevant
competencies in psychomotor domain.By keeping in view, GTU has designed competency
focused outcome-based curriculum for engineering degree programs where sufficient weightage
is given to practical work. It shows importance of enhancement of skills amongst the students
and it pays attention to utilize every second of time allotted for practical amongst students,
instructors and faculty members to achieve relevant outcomes by performing the experiments
rather than having merely study type experiments. It is must for effective implementation of
competency focused outcome-basedcurriculum that every practical is keenly designed to serve
as a tool to develop and enhance relevant competency required by the various industry among
every student. These psychomotor skills are very difficult to develop through traditional chalk
and board content delivery method in the classroom. Accordingly, this lab manual is designed
to focus on the industry defined relevant outcomes, rather than old practice of conducting
practical to prove concept and theory.

By using this lab manual students can go through the relevant theory and procedure in advance
before the actual performance which createsan interest and students can have basic idea prior to
performance.This in turn enhances pre-determined outcomes amongst students.Each experiment
in this manual begins with competency, industry relevant skills, course outcomes as well as
practical outcomes (objectives). The students will also achieve safety and necessary precautions
to be taken while performing practical.

This manual also provides guidelines to faculty members to facilitate studentcentric lab
activities through each experiment by arranging and managing necessary resources in order that
the students follow the procedures with required safety and necessary precautions to achieve the
outcomes. It also gives an idea that how students will be assessed by providing rubrics.

This manual is designed to accompany your practical exploration of the exciting and rapidly
evolving field of Internet of Things (IoT) and its practical applications. IoT is revolutionizing
the way we interact with and utilize technology, and this manual will guide you through hands-
on exercises to deepen your understanding of the subject.

Utmost care has been taken while preparing this lab manual however always there is chances of
improvement. Therefore, we welcome constructive suggestions for improvement and removal
of errors if any.
IoT and Applications (3160716) Enrollment No:

DTE’s Vision

 To provide globally competitive technical education


 Remove geographical imbalances and inconsistencies
 Develop student friendly resources with a special focus on girls’ education and support to
Weaker sections
 Develop programs relevant to industry and create a vibrant pool of technical professionals

Institute’s Vision

 To create an ecosystem for proliferation of socially responsible and technically sound


engineers, innovators and entrepreneurs.

Institute’s Mission

 To develop state-of-the-art laboratories and well-equipped academic infrastructure.


 To motivate faculty and staff for qualification up-gradation, and enhancement of subject
knowledge.
 To promote research, innovation and real-life problem-solving skills.
 To strengthen linkages with industries, academic and research organizations.
 To reinforce concern for sustainability, natural resource conservation and social
responsibility.

Department’s Vision

 To create an environment for providing value-based education in Computer Engineering


through innovation, team work and ethical practices.

Department’s Mission

 To produce computer engineering graduates according to the needs of industry,


government, society and scientific community.
 To develop state of the art computing facilities and academic infrastructure.
 To develop partnership with industries, government agencies and R & D organizations for
knowledge sharing and overall development of faculties and students.
 To solve industrial, governance and societal issues by applying computing techniques.
 To create environment for research and entrepreneurship.
IoT and Applications (3160716) Enrollment No:

Programme Outcomes (POs)

1. Engineering knowledge: Apply the knowledge of mathematics, science, engineering


fundamentals, and an engineering specialization to the solution of complex engineering
problems.
2. Problem analysis: Identify, formulate, review research literature, and analyze complex
engineering problems reaching substantiated conclusions using first principles of
mathematics, natural sciences, and engineering sciences.
3. Design/development of solutions: Design solutions for complex engineering problems and
design system components or processes that meet the specified needs with appropriate
consideration for the public health and safety, and the cultural, societal, and environmental
considerations.
4. Conduct investigations of complex problems: Use research-based knowledge and research
methods including design of experiments, analysis and interpretation of data, and synthesis
of the information to provide valid conclusions.
5. Modern tool usage: Create, select, and apply appropriate techniques, resources, and modern
engineering and IT tools including prediction and modeling to complex engineering activities
with an understanding of the limitations.
6. The engineer and society: Apply reasoning informed by the contextual knowledge to assess
societal, health, safety, legal and cultural issues and the consequent responsibilities relevant
to the professional engineering practice.
7. Environment and sustainability: Understand the impact of the professional engineering
solutions in societal and environmental contexts, and demonstrate the knowledge of, and
need for sustainable development.
8. Ethics: Apply ethical principles and commit to professional ethics and responsibilities and
norms of the engineering practice.
9. Individual and team work: Function effectively as an individual, and as a member or leader
in diverse teams, and in multidisciplinary settings.
10. Communication: Communicate effectively on complex engineering activities with the
engineering community and with society at large, such as, being able to comprehend and
write effective reports and design documentation, make effective presentations, and give and
receive clear instructions.
11. Project management and finance: Demonstrate knowledge and understanding of the
engineering and management principles and apply these to one’s own work, as a member and
leader in a team, to manage projects and in multidisciplinary environments.
12. Life-long learning: Recognize the need for, and have the preparation and ability to engage
in independent and life-long learning in the broadest context of technological change.
IoT and Applications (3160716) Enrollment No:

Program Specific Outcomes (PSOs)

 Sound knowledge of fundamentals of computer science and engineering including


software and hardware.
 Develop the software using sound software engineering principles having web
based/mobile based interface.
 Use various tools and technology supporting modern software frameworks for solving
problems having large volume of data in the domain of data science and machine learning.

Program Educational Objectives (PEOs)

 Possess technical competence in solving real life problems related to Computing.


 Acquire good analysis, design, development, implementation and testing skills to
formulate simple computing solutions to the business and societal needs.
 Provide requisite skills to pursue entrepreneurship, higher studies, research, and
development and imbibe high degree of professionalism in the fields of computing.
 Embrace life-long learning and remain continuously employable.
 Work and excel in a highly competence supportive, multicultural and professional
environment which abiding to the legal and ethical responsibilities.
IoT and Applications (3160716) Enrollment No:

Practical – Course Outcome matrix

Course Outcomes (COs):


CO_3160716.1 Demonstrate the architecture and functioning of IoT systems including the sensors
and microcontrollers with their interfacing and software need considering
application areas.
CO_3160716.2 Diagnose the various IoT protocols with detailing of their elements and overall
functioning within IoT systems for efficient communication.
CO_3160716.3 Design an IoT system to take the benefit of the Clouds for computing and storage
considering security issues.
CO_3160716.4 Leverage the benefits of IoT technologies for automating the various real-life
challenges in various application areas.
CO_3160716.5 Develop the software components of IoT system using Arduino/Raspberry Pi
Programming.
Sr. CO CO CO CO CO
Objective(s) of Experiment
No. 1 2 3 4 5
Understanding Arduino UNO, NodeMCU and Raspberry
1. Pi and Arduino IDE. √
Controlling LED ON/OFF using Arduino UNO.
2. √
Measuring Temperature and Humidity using Sensor
3. DHT-11 and Arduino UNO. √
Measuring object presence using IR Sensor and when
4. present, use buzzer for notification. √
Measuring object distance using Ultrasonic Sensor and
5. Arduino Uno. √
Measuring moving object using PIR Sensor and Arduino
6. Uno. √
Measure temperature using DHT-11 sensor and send it to
7. cloud ThingSpeak using NodeMCU. √
Controlling Led ON/OFF by giving command from
8. mobile phone. (Use cloud ThingSpeak) √
Controlling Led ON/OFF by giving commands using
9. Google Assistant from a mobile phone. (Use cloud √
Adafruit)
Installing Raspbian OS in Raspberry Pi and performing
10. basic practical like LED on/off. √
IoT and Applications (3160716) Enrollment No:

Industry Relevant Skills

The following industry relevant competency is expected to be developed in the student


by undertaking the practical work of this laboratory.
1. Sensor and Actuator Integration: Teach students how to interface various
sensors (e.g., temperature sensors, motion sensors, humidity sensors) and
actuators (e.g., LED, motors) with microcontrollers (e.g., Arduino, Raspberry Pi)
to collect data and control physical devices.
2. Programming and Coding: Provide hands-on experience with programming
microcontrollers using languages like C++, Python, or Arduino IDE. Emphasize
the importance of clean and efficient code for IoT applications.
3. IoT Protocols: Introduce students to common communication protocols used in
IoT, such as MQTT, HTTP, CoAP, and Web Socket. Show how to send and
receive data over the internet and within IoT networks.
4. Real-Time Systems: Introduce the concept of real-time systems and demonstrate
how to design and program IoT applications that respond quickly to sensor data.
5. Project Management: Encourage students to work on IoT projects with a focus
on planning, design, execution, and documentation. This mimics real-world
project management skills required in industry.
6. Industry-Specific Applications: Tailor lab exercises to specific industries where
IoT is heavily utilized, such as smart agriculture, healthcare, smart cities,
manufacturing, and logistics. This provides students with practical knowledge for
targeted job roles.

Guidelines forFaculty members


1. Teacher should provide the guideline with demonstration of practical to the students
with all features.
2. Teacher shall explain basic concepts/theory related to the experiment to the students
before starting of each practical
3. Involve all the students in performance of each experiment.
4. Teacher is expected to share the skills and competencies to be developed in the
students and ensure that the respective skills and competencies are developed in the
students after the completion of the experimentation.
5. Teachers should give opportunity to students for hands-on experience after the
demonstration.
6. Teacher may provide additional knowledge and skills to the students even though not
covered in the manual but are expected from the students by concerned industry.
7. Give practical assignment and assess the performance of students based on task
assigned to check whether it is as per the instructions or not.
8. Teacher is expected to refer complete curriculum of the course and follow the
guidelines for implementation.
IoT and Applications (3160716) Enrollment No:

Instructions for Students


1. Students are expected to carefully listen to all the theory classes delivered by the
faculty members and understand the COs, content of the course, teaching and
examination scheme, skill set to be developed etc.
2. Student should develop a habit of submitting the experimentation work as per the
schedule and s/he should be well preparedfor the same.

Common Safety Instructions


Students are expected to
1) switch on the PC carefully (not to use wet hands)
2) shutdown the PC properly at the end of your Lab
3) carefully Handle the peripherals (Mouse, Keyboard, Network cable etc)
4) Use Laptop in lab after getting permission from Instructor
5) Handle equipment and components with care to prevent damage or malfunction.
6) Do not open devices or components unless instructed to do so by the Instructor.
7) Keep the lab clean and organized. Dispose of waste and materials properly.
IoT and Applications (3160716) Enrollment No:

Index
(Progressive Assessment Sheet)
Sign. of
Sr. Page Date of Date of Assessment
No.
Objective(s) of Experiment No. performance submission Marks
Teacher Remarks
with date

Understanding Arduino UNO, NodeMCU


1.
and Raspberry Pi and Arduino IDE.

Controlling LED ON/OFF using Arduino


2.
UNO.

Measuring Temperature and Humidity using


3.
Sensor DHT-11 and Arduino UNO.

Measuring object presence using IR Sensor


4. and when present, use buzzer for
notification.

Measuring object distance using Ultrasonic


5.
Sensor and Arduino Uno.

Measuring moving object using PIR Sensor


6.
and Arduino Uno.

Measure temperature using DHT-11 sensor


7. and send it to cloud ThingSpeak using
NodeMCU.

Controlling Led ON/OFF by giving


8. command from mobile phone. (Use cloud
ThingSpeak)

Controlling Led ON/OFF by giving


9. commands using Google Assistant from a
mobile phone. (Use cloud Adafruit)

Installing Raspbian OS in Raspberry Pi and


10.
performing basic practical like LED on/off.

Total
Experiment No: 1

Aim: Understanding Arduino UNO, NodeMCU and Raspberry Pi and Arduino IDE.
Date:

Competency and PracticalSkills:


1. Identifying Hardware Components: Students should be able to identify the key
components on each of the hardware platforms (Arduino UNO, Node MCU, Raspberry
Pi). This includes recognizing input/output pins, power connectors, microcontrollers,
and other components specific to each board.
2. Handling Microcontrollers: Students should learn how to handle microcontrollers
with care. This includes proper insertion into breadboards or connectors and
understanding the importance of static electricity precautions.
3. Software Installation: Proficiency in installing and configuring software is essential.
This includes installing the Arduino IDE on a computer, setting up drivers if needed,
and ensuring that the development environment is functional.
4. Basic Programming: Students should acquire basic programming skills, especially in
the context of Arduino. This includes writing and uploading simple code to control
LEDs, read sensors, and performs basic tasks.

Relevant CO:CO1

Objectives:
1. Differentiate between Arduino UNO, Node MCU, and Raspberry Pi in terms of
hardware and applications.
2. Identify and handle the key components of each platform.
3. Install and configure the Arduino IDE for microcontroller programming.
4. Write and upload a basic "Hello, World!" program to Arduino UNO.
5. Understand the basic structure of Arduino code, including setup () and loop () functions.
6. Describe the significance of GPIO pins in microcontroller programming.
7. Explore the Node MCU board and its compatibility with IoT applications.
8. Gain familiarity with the Raspberry Pi as a versatile single-board computer.
9. Describe the role of Raspberry Pi in IoT projects and applications.
10. Recognize the significance of choosing the appropriate hardware platform for specific
IoT projects.

Equipment/Instruments:
1. Arduino UNO microcontroller board.
2. Node MCU development board.
3. Raspberry Pi single-board computer.
4. Laptop or desktop computer with the Arduino IDE installed.
5. USB cables for connecting the microcontroller boards to the computer.
6. Basic electronic components such as LEDs and resistors (if needed for practical
demonstrations).
7. Internet connectivity for software and IDE installation (if required).

8
Explanation:
Arduino UNO:
Arduino is an open-source electronics platform based on easy-to-use hardware and
software. Arduino boards are able to read inputs - light on a sensor, a finger on a button, or a
Twitter message - and turn it into an output - activating a motor, turning on an LED, publishing
something online. You can tell your board what to do by sending a set of instructions to the
microcontroller on the board. To do so you use the Arduino programming language (based
on Wiring), and the Arduino Software (IDE), based on Processing.
Arduino was born at the Ivrea Interaction Design Institute as an easy tool for fast prototyping,
aimed at students without a background in electronics and programming. As soon as it reached a
wider community, the Arduino board started changing to adapt to new needs and challenges,
differentiating its offer from simple 8-bit boards to products for IoT applications, wearable, 3D
printing, and embedded environments. All Arduino boards are completely open-source,
empowering users to build them independently and eventually adapt them to their particular
needs. The software, too, is open-source, and it is growing through the contributions of users
worldwide.

Fig.1: Arduino Board


Why Arduino is used?
Arduino has been used in thousands of different projects and applications. The Arduino
software is easy-to-use for beginners, yet flexible enough for advanced users. It runs on Mac,
Windows, and Linux. Teachers and students use it to build low cost scientific instruments, to
prove chemistry and physics principles, or to get started with programming and robotics.
Designers and architects build interactive prototypes, musicians and artists use it for
installations and to experiment with new musical instruments. Makers, of course, use it to build
many of the projects exhibited at the Maker Faire, for example. Arduino is a key tool to learn
new things. Anyone - children, hobbyists, artists, programmers - can start tinkering just
following the step by step instructions of a kit, or sharing ideas online with other members of
the Arduino community.
There are many other microcontrollers and microcontroller platforms available for physical
computing. Parallax Basic Stamp, Netmedia's BX-24, Phidgets, MIT's Handy board, and many
others offer similar functionality. All of these tools take the messy details of microcontroller
programming and wrap it up in an easy-to-use package. Arduino also simplifies the process of
working with microcontrollers, but it offers some advantage for teachers, students, and
interested amateurs over other systems:

9
 Inexpensive - Arduino boards are relatively inexpensive compared to other
microcontroller platforms.
 Cross-platform - The Arduino Software (IDE) runs on Windows, Macintosh OSX, and
Linux operating systems. Most microcontroller systems are limited to Windows.
 Simple, clear programming environment - The Arduino Software (IDE) is easy-to-use
for beginners, yet flexible enough for advanced users to take advantage of as well. For
teachers, it's conveniently based on the Processing programming environment, so
students learning to program in that environment will be familiar with how the Arduino
IDE works.
The key features are −
 Arduino boards are able to read analog or digital input signals from different sensors and
turn it into an output such as activating a motor, turning LED on/off, connect to the
cloud and many other actions.
 You can control your board functions by sending a set of instructions to the
microcontroller on the board via Arduino IDE (referred to as uploading software).
 Unlike most previous programmable circuit boards, Arduino does not need an extra piece
of hardware (called a programmer) in order to load a new code onto the board. You can
simply use a USB cable.
 Additionally, the Arduino IDE uses a simplified version of C++, making it easier to learn
to program.
 Finally, Arduino provides a standard form factor that breaks the functions of the micro-
controller into a more accessible package.

NodeMCU :
NodeMCU is an open-source Lua based firmware and development board specially targeted for
IoT based Applications. It includes firmware that runs on the ESP8266 Wi-Fi SoC from
Espressif Systems, and hardware which is based on the ESP-12 module.

Fig 2: Node MCU ESP8266


Raspberry Pi:

Arduino is a microcontroller, while Raspberry Pi is a full computer. Microcontrollers don’t


usually run a mainstream operating system, but they’re extremely power-efficient, so they can

10
be great for projects that can’t stay plugged into the mains. You need to use a separate computer
to set up your Arduino, but you can do everything on a Raspberry Pi itself… including setting
up an Arduino. As we said, the two work really well together in some projects: for example, you
might build a robot where the Raspberry Pi handles intensive processing tasks and provides you
with a friendly environment for developing your code, while the Arduino handles precise real-
time control of the motors.

Fig 3:Raspberry Pi

Raspberry Pi is the name of a series of single-board computers made by the Raspberry Pi


Foundation, a UK charity that aims to educate people in computing and create easier access to
computing education.
The Raspberry Pi launched in 2012, and there have been several iterations and variations
released since then. All over the world, people use the Raspberry Pi to learn programming skills,
build hardware projects, do home automation, implement Kubernetes clusters and Edge
computing, and even use them in industrial applications.
The Raspberry Pi is a very cheap computer that runs Linux, but it also provides a set of GPIO
(general purpose input/output) pins, allowing you to control electronic components for physical
computing and explore the Internet of Things (IoT).

Arduino IDE:
The Arduino Integrated Development Environment (IDE) is a cross-platform application
(for Windows, macOS, Linux) that is written in functions from C and C++.It is used to write
and upload programs to Arduino compatible boards, but also, with the help of third-party cores,
other vendor development boards.

11
The source code for the IDE is released under the GNU General Public License, version 2. The
Arduino IDE supports the languages C and C++ using special rules of code structuring. The
Arduino IDE supplies a software library from the Wiring project, which provides many
common input and output procedures. User-written code only requires two basic functions, for
starting the sketch and the main program loop, that are compiled and linked with a program
stub main() into an executable cyclic executive program with the GNU toolchain, also included
with the IDE distribution.The Arduino IDE employs the program avrdude to convert the
executable code into a text file in hexadecimal encoding that is loaded into the Arduino board
by a loader program in the board's firmware. By default, avrdude is used as the uploading tool to
flash the user code onto official Arduino boards.
Arduino IDE is a derivative of the Processing IDE, however as of version 2.0, the Processing
IDE will be replaced with the Visual Studio Code-based Eclipse Theia IDE framework.
With the rising popularity of Arduino as a software platform, other vendors started to implement
custom open source compilers and tools (cores) that can build and upload sketches to
other microcontrollers that are not supported by Arduino's official line of microcontrollers.

Observation:
“Write YourObservation Here”

12
Conclusion:
“Write YourConclusion of Experiment”
Quiz:
1. Which hardware platform is known for its versatility and use as a single-board computer
in IoT applications?
2. What is the primary function of the Arduino Integrated Development Environment
(IDE)?
3. In the context of Arduino programming, what is the purpose of the setup () function?
4. Which hardware platform is typically used to create web servers and Wi-Fi-enabled IoT
applications?
5. Which of the following IoT hardware platforms is primarily based on the use of GPIO
pins for interfacing with sensors and devices?

References:

“List Down references used to perform above practical”

Rubric wise marks obtained:

Identification of Practical Skills and Documentation and


Quiz Performance Ethics
Hardware Application Collaboration
Good Average Good Average Good Average Good Average Good Average
(2) (1) (2) (1) (2) (1) (2) (1) (2) (1)

13
Experiment No: 2

Aim:Controlling LED ON/OFF using Arduino UNO.


Date:

Competency and PracticalSkills:

 Gain competency in interfacing hardware components with an Arduino UNO.


 Develop practical skills in writing Arduino code to control digital pins.
 Understand the fundamentals of using input/output pins for controlling external
devices.

Relevant CO: CO1


Objectives:
1. Identify the key components of an Arduino UNO microcontroller board.
2. Establish a connection between an Arduino UNO and an LED.
3. Write and upload an Arduino sketch (program) to control the LED's state (ON or OFF).
4. Understand the concept of digital output and how to use it for controlling external
devices.
5. Experiment with modifying the code to change the LED's behaviour (e.g., blinking
patterns).
6. Troubleshoot common issues related to hardware connections and code errors.
7. Recognize the relevance of this fundamental skill in various IoT and embedded systems
applications.

Components:
1. Arduino UNO Microcontroller: This is the central component of the lab session. The
Arduino UNO is a microcontroller board that will be used to control the LED.
2. LED (Light-Emitting Diode): An LED is used as the output device. LEDs come in
various colours and types, but a basic one will suffice for this exercise.
3. Resistor (220-330 ohms): A current-limiting resistor is necessary to prevent excessive
current from flowing through the LED and potentially damaging it.
4. Breadboard: A breadboard is used for easy prototyping and making temporary
connections. It simplifies the setup and makes it easier to modify the circuit.
5. Jumper Wires: These wires are used to make connections between the components on
the breadboard, ensuring electrical continuity.
6. USB Cable: A USB cable is required to connect the Arduino UNO to a computer for
programming.
7. Computer with Arduino IDE: You'll need a computer with the Arduino Integrated
Development Environment (IDE) installed. The Arduino IDE is used to write, compile,
and upload code to the Arduino UNO.
8. Power Source (optional): In some cases, an external power source may be required if
you are working with multiple LEDs or components that draw more current than the
Arduino can provide.

14
Configuration:

Fig 4:Schematic Diagram

Fig 5:Arduino with Breadboard

Procedure:

Step 1: Build the Circuit:


1. Connect one end of the LED (the anode, the longer pin) to a 220-ohm resistor.

15
2. Connect the other end of the resistor to digital Pin 9 on the Arduino Uno.
3. Connect the cathode of the LED (the shorter pin) directly to the GND (ground) on the
Arduino.
This setup ensures that when Pin 9 on the Arduino outputs a high-level signal, the LED will
light up due to the current flowing through the current-limiting resistor.
Step 2: Write Code in Arduino IDE:
void setup() {
// Set LED_BUILTIN (usually Pin 13 on Arduino Uno) as an output.
pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
// Turn on the LED by setting Pin 13 (or LED_BUILTIN) to HIGH.
digitalWrite(LED_BUILTIN, HIGH);
delay(1000); // Wait for 1 second (1000 milliseconds).

// Turn off the LED by setting Pin 13 (or LED_BUILTIN) to LOW.


digitalWrite(LED_BUILTIN, LOW);
delay(2000); // Wait for 2 seconds (2000 milliseconds).
}
In the code, you set Pin 13 (or LED_BUILTIN) as an output in the setup() function. In the
loop() function, you turn the LED on (high) for 1 second, then turn it off (low) for 2 seconds,
creating a blinking pattern.
Step 3: Upload the Sketch to the Arduino Uno Board:
1. Connect the Arduino Uno to your computer using a USB cable.
2. Open the Arduino IDE and make sure it is set to the correct board (Arduino Uno) and
port (the port your Arduino is connected to).
3. Click the "Upload" icon in the Arduino IDE to compile and upload the code to the
Arduino Uno.
4. If the code is successfully uploaded, you will see "Done uploading" at the bottom of the
IDE window.
After completing these steps, your Arduino Uno will control the LED connected to Pin 13,
making it blink with a 1-second ON and 2-second OFF pattern. You should observe the LED
blinking as described in the code.

Observation:
“Put Your Output Screenshot Here”

Conclusion:
“Write Your Conclusion of Practical”
Quiz:
1. In the circuit setup to control an LED with an Arduino Uno, which pin is connected to
the anode (long pin) of the LED?
2. What is the function of a current-limiting resistor in an LED circuit?
3. In the provided Arduino code, what is the purpose of the pin Mode (LED_BUILTIN,
OUTPUT); line in the setup () function?

16
4. How long does the LED stay on in the provided Arduino code before turning off in the
loop () function?
References:

“List Down references used to perform above practical”

Rubric wise marks obtained:

Identification of Circuit Setup and


Code Understanding Quiz Performance Ethics
Hardware Connections
Good Average Good Average Good Average Good Average Good Average
(2) (1) (2) (1) (2) (1) (2) (1) (2) (1)

17
Experiment No: 3

Aim:Measuring Temperature and Humidity using Sensor DHT-11 and Arduino UNO.
Date:

Competency and PracticalSkills:


 Gain competency in interfacing sensors with an Arduino UNO.
 Develop practical skills in reading sensor data and displaying it.
 Understand the fundamentals of sensor calibration and data interpretation.

Relevant CO: CO1

Objectives:
1. Identify the components of the DHT-11 sensor, including the temperature and humidity
sensing elements.
2. Build a circuit to connect the DHT-11 sensor to an Arduino UNO.
3. Write Arduino code to read temperature and humidity data from the sensor.
4. Display the sensor data on a connected display (e.g., a serial monitor or an LCD).
5. Understand the calibration and limitations of the DHT-11 sensor.
6. Recognize the importance of temperature and humidity measurements in IoT
applications.
Components:
1. Arduino UNO Microcontroller: This is the central component for interfacing with the
DHT-11 sensor and processing data.
2. DHT-11 Sensor: A sensor module that can measure temperature and humidity.
3. Breadboard: Used for easy prototyping and making temporary connections.
4. Jumper Wires: These wires are used to make connections between the components on
the breadboard.
5. Display (e.g., Serial Monitor on a computer or an LCD): Used to display the temperature
and humidity data.
6. Power Source: The Arduino UNO may require a power source to operate the circuit.

Configuration:

Fig 6:Schematic Diagram

18
Fig 7: Arduino UNO with Breadboard

Procedure:
Step 1: Place the Sensor
 Position the DHT-11 sensor on the breadboard with the blue part of the sensor facing
you. Ensure it is securely placed.
Step 2: Connect Everything 2.1. Identify the pins on the DHT-11 sensor: S (signal), middle
pin (voltage), and the minus sign (ground). 2.2. Connect the sensor to the Arduino UNO as
follows:
 Connect the S (signal) pin of the sensor to header A0 on the Arduino.
 Connect the middle pin (voltage) of the sensor to 5V on the Arduino.
 Connect the minus sign (ground) of the sensor to GND on the Arduino. 2.3. Use
coloured cables (e.g., yellow for signal, red for power, black for ground) for the
connections.
Step 3: Adding the DHT Library
 In the Arduino IDE, go to "Sketch" > "Include Library" > "Add ZIP file."

19
 Locate and select the "DHT_Library.zip" file and add it to the IDE.

Code:
#include <dht.h>

#define dht_11_PIN 7

dht DHT;

void setup(){
Serial.begin(9600);
delay(500); // Delay to let the system boot
Serial.println("DHT11 Humidity & Temperature Sensor\n\n");
delay(1000); // Wait before accessing the sensor
}

void loop(){
DHT.read11(dht_11_PIN);
Serial.print("Current humidity = ");
Serial.print(DHT.humidity);
Serial.print("% ");
Serial.print("temperature = ");
Serial.print(DHT.temperature);
Serial.println("C ");
delay(5000);
}
Step 4: Uploading and Monitoring Data
 Upload the provided code to the Arduino UNO.
 After uploading, open the Arduino IDE's serial monitor by clicking the magnifying

20
glass button in the top right corner.
 The sensor data (humidity and temperature) should be displayed and updated every 5
seconds in the serial monitor.

Output:
“Put Your Output Screenshot Here”

Conclusion:
“Write Your Conclusion ofExperiment”
Quiz:
1. When placing the DHT-11 sensor on the breadboard, which part of the sensor should be
facing you?
2. Which of the following correctly identifies the pins on the DHT-11 sensor?
3. How do you add the DHT library to the Arduino IDE?
4. What is the purpose of the DHT.read11(dht_11_PIN); line in the provided code?
5. In the serial monitor, how often (In seconds) does the sensor data update in the provided
code?

References:

“List Down references used to perform above practical”

Rubric wise marks obtained:

Code Understanding
Sensor
Connection Setup & Quiz Performance Ethics
Placement
Data Display
Good Average Good Average Good Average Good Average Good Average
(2) (1) (2) (1) (2) (1) (2) (1) (2) (1)

21
Experiment No: 4

Aim:Measuring object presence using IR Sensor and when present, use buzzer for
notification.
Date:

Competency and PracticalSkills:


 Gain competency in working with IR sensors and buzzer components.
 Develop practical skills in setting up sensor-based object detection systems.
 Understand the application of sensors and notification devices in real-world
scenarios.

Relevant CO: CO4

Objectives:

1. Identify the key components of an IR sensor, buzzer, and the necessary connections.
2. Build a circuit to connect an IR sensor and a buzzer to an Arduino or microcontroller.
3. Write Arduino code to detect the presence of an object using the IR sensor.
4. Implement logic in the code to activate the buzzer when an object is detected.
5. Understand the practical applications of object detection and notification systems in IoT
and automation.

Components:
1. IR Sensor: A sensor module designed to detect the presence of objects by emitting and
receiving infrared signals.
2. Buzzer: An audible notification device that produces sound when activated.
3. Arduino or Microcontroller: The central control unit used to process sensor data and
control the buzzer.
4. Breadboard: Used for easy prototyping and making temporary connections.
5. Jumper Wires: These wires are used to make connections between the components on
the breadboard.
6. Power Source (if required): Depending on the components used, an external power
source may be needed to operate the circuit.

Configuration:

Fig 8:Circuit Diagram

22
Procedure:
Step 1: Build the Circuit
 Follow the circuit diagram provided to set up the components. Ensure you
connect the IR sensor and buzzer to the appropriate pins on the Arduino or
microcontroller. Double-check your connections to avoid errors.
Step 2: Write and Upload the Arduino Code
 Open the Arduino Integrated Development Environment (IDE) on your
computer.
 Write the following code:
Code:
intirSensor = 12;
int buzzer = 7;

void setup() {
Serial.begin(9600);
pinMode(irSensor, INPUT);
pinMode(buzzer, OUTPUT);
}

void loop() {
int value = digitalRead(irSensor);
Serial.println("");
Serial.print("Sensor Value = ");
Serial.print(value);
if (value == 0) {
digitalWrite(buzzer, HIGH);
} else {
digitalWrite(buzzer, LOW);
}
delay(50);
}
Code Explanation:
 The code initializes two variables irSensor (connected to pin 12) and buzzer
(connected to pin 7) to represent the IR sensor and buzzer pins, respectively.
 In the setup () function, it sets up the serial communication for debugging,
configures the IR sensor pin as an input, and the buzzer pin as an output.
 The loop () function reads the value of the IR sensor using
digitalRead(irSensor) and stores it in the value variable.
 It then prints the sensor value to the serial monitor for monitoring.
 If the sensor value is 0 (indicating the presence of an object), it sets the buzzer
pin to HIGH to activate the buzzer. If there is no object detected, it sets the
buzzer pin to LOW to turn off the buzzer.
 There's a delay (50) to introduce a small delay between readings.

23
Step 3: Test the Circuit
 Upload the code to your Arduino or microcontroller.
 Open the serial monitor in the Arduino IDE.
 Observe the sensor value being printed and listen for the buzzer activation
when an object is detected (sensor value is 0).

Observation:
“Write Your Observation Here”

Conclusion:
“Write Your Conclusion ofExperiment”
Quiz:
1. In the provided procedure, which pin is connected to the IR sensor for reading its output value?
2. In the provided code, what is the purpose of the digitalWrite(buzzer, HIGH); line?
3. What is the purpose of the delay(50); line in the provided code?
4. In the provided code, what does an IR sensor value of 0 indicate?
5. In the procedure, what is the purpose of opening the serial monitor in the Arduino IDE?

References:

“List Down references used to perform above practical”

Rubric wise marks obtained:


Circuit Setup Code Sensor and Buzzer
Quiz Performance Ethics
and Connections Understanding Activation
Good Average Good Average Good Average Good Average Good Average
(2) (1) (2) (1) (2) (1) (2) (1) (2) (1)

24
Experiment No: 5
Aim:Measuring object distance using Ultrasonic Sensor and Arduino Uno.
Date:

Competency and PracticalSkills:


 Gain competency in working with Ultrasonic sensors for distance measurement.
 Develop practical skills in setting up sensor-based distance measurement
systems.
 Understand the application of distance measurement in real-world scenarios.

Relevant CO: CO4

Objectives:
1. Identify the key components of an Ultrasonic sensor and the necessary connections.
2. Build a circuit to connect an Ultrasonic sensor to an Arduino Uno.
3. Write Arduino code to measure object distance using the Ultrasonic sensor.
4. Interpret the distance data and display it on a connected output device (e.g., LCD or
serial monitor).
5. Understand the practical applications of distance measurement in IoT, robotics, and
automation.

Components:
1. Ultrasonic Sensor (HC-SR04): A sensor module designed to measure distances by
sending and receiving ultrasonic sound waves.
2. Arduino Uno: The central control unit used to process sensor data and display distance
information.
3. Breadboard: Used for easy prototyping and making temporary connections.
4. Jumper Wires: These wires are used to make connections between the components on
the breadboard.
5. Display (optional): An output device (e.g., LCD or serial monitor) for displaying the
measured distance.
6. Power Source (if required): Depending on the components used, an external power
source may be needed to operate the circuit.

Configuration:

Fig 9: Circuit Diagram

25
Fig 10: Arduino Uno WithUltrasonic Sensor

Procedure:
Step 1: Setup the Circuit
1. Place the Ultrasonic sensor on one end of the breadboard so that none of the pins
are connected to each other.
2. Connect the "trigger" pin on the Ultrasonic sensor to pin 10 on the Arduino.
3. Connect the "echo" pin on the Ultrasonic sensor to pin 9 on the Arduino.
4. Connect the Ultrasonic Sensor's 5V pin to the 5V pin on the Arduino.
5. Complete the circuit by connecting the Ultrasonic Sensor's ground pin to the
Arduino's ground pin.
Step 2: Understanding the Ultrasonic Sensor
 The Ultrasonic sensor is capable of non-contact distance measurements in the
range of 2cm to 400cm, with a ranging accuracy of up to 3mm.
 It operates by emitting ultrasonic sound waves and measuring the time it takes
for the waves to bounce back after hitting an object, similar to how bats use
echolocation.
Step 3: Write and Upload the Arduino Code
 Open the Arduino Integrated Development Environment (IDE) on your
computer.

26
 Write the following code:
Code:
constint trigger = 9;
constint echo = 10;
long duration;
int distance;

void setup() {
pinMode(trigger, OUTPUT);
pinMode(echo, INPUT);
Serial.begin(9600);
}

void loop() {
digitalWrite(trigger, LOW);
delayMicroseconds(2);
digitalWrite(trigger, HIGH);
delayMicroseconds(10);
digitalWrite(trigger, LOW);
duration = pulseIn(echo, HIGH);
distance = duration * 0.034 / 2;
Serial.print("Distance: ");
Serial.println(distance);
}
Code Explanation:
 The code initializes two constants, trigger (connected to pin 9) and echo
(connected to pin 10) to represent the trigger and echo pins of the Ultrasonic
sensor.
 In the setup () function, it sets the trigger pin as an OUTPUT and the echo pin as
an INPUT. It also initializes serial communication for monitoring.
 The loop() function sends a trigger signal, measures the echo response, calculates
the distance based on the time it takes for the signal to bounce back, and then
prints the distance to the serial monitor.
Step 4: Testing the Circuit
 Upload the code to your Arduino Uno.
 Open the serial monitor in the Arduino IDE to observe the measured distance
values.

Observation:
“Write YourObservation Here”

Conclusion:
“Write YourConclusionof Experiment”

27
Quiz:
1. In the provided procedure, which pins on the Arduino are connected to the "trigger" and
"echo" pins of the Ultrasonic sensor?
2. How does the Ultrasonic sensor measure object distance?
3. What is the purpose of the "trigger" pin on the Ultrasonic sensor in the code?
4. In the code, what value is used to calculate the distance based on the time it takes for the
echo signal to return?
5. What is the purpose of opening the serial monitor in the Arduino IDE when using the
Ultrasonic sensor?
References:

“List Down references used to perform above practical”

Rubric wise marks obtained:

Circuit Setup Code


Distance Measurement Quiz Performance Ethics
and Connections Understanding
Good Average Good Average Good Average Good Average Good Average
(2) (1) (2) (1) (2) (1) (2) (1) (2) (1)

28
Experiment No: 6

Aim:Measuring moving object using PIR Sensor and Arduino Uno.


Date:

Competency and PracticalSkills:


 Gain competency in working with PIR sensors for motion detection.
 Develop practical skills in setting up sensor-based motion detection systems.
 Understand the application of motion detection in real-world scenarios.

Relevant CO: CO4

Objectives:
1. Identify the key components of a PIR sensor and the necessary connections.
2. Build a circuit to connect a PIR sensor to an Arduino Uno.
3. Write Arduino code to detect and respond to moving objects using the PIR sensor.
4. Interpret the motion data and trigger appropriate actions (e.g., turning on an LED or
sending a notification).
5. Understand the practical applications of motion detection in security systems and
automation.

Components:
1. PIR Sensor (HC-SR501 or similar): A sensor designed to detect motion by measuring
changes in infrared radiation.
2. Arduino Uno: The central control unit used to process sensor data and trigger actions.
3. Breadboard: Used for easy prototyping and making temporary connections.
4. Jumper Wires: These wires are used to make connections between the components on
the breadboard.
5. Output Device (e.g., LED or buzzer): An optional component for demonstrating motion
detection.
6. Power Source (if required): Depending on the components used, an external power
source may be needed to operate the circuit.

Configuration:

Fig 11: Circuit Diagram

29
The design of the PIR Motion Sensor using Arduino is very simple. The PIR Sensor Module has
three pins: VCC, Digital Out and GND. Connect VCC and GND to +5V and GND respectively.
Then connect the Digital Out Pin of the PIR sensor to the digital I/O pin 8 of Arduino.
As we need to indicate the detection of motion by the sensor, connect a buzzer to Pin 11 of the
Arduino.

Fig 10: Arduino Uno withPIR Sensor

Procedure:
1. When the system is powered on, the Arduino enters a calibration phase for the PIR
sensor. During this 10-second calibration period, the PIR sensor should not detect any
motion.
2. After the calibration period, the PIR sensor is ready to detect any movement in front of
it.
3. If the PIR sensor detects motion, its digital output pin (connected to Arduino Pin 8)
becomes HIGH.
4. Arduino detects the HIGH signal from the PIR sensor and activates the buzzer.
5. The buzzer remains active for 3 seconds (3000 milliseconds).
6. After the buzzer has been activated, it turns off when motion is no longer detected by the
PIR sensor.
Code:
int buzzer = 11;
int sensor = 8;
int led = 13;
void setup()
{
pinMode(buzzer, OUTPUT);
pinMode(sensor, INPUT);
pinMode(led, OUTPUT);
digitalWrite(buzzer,LOW);
digitalWrite(sensor,LOW);

30
digitalWrite(led,LOW);
while(millis()<13000)
{
digitalWrite(led,HIGH);
delay(50);
digitalWrite(led,LOW);
delay(50);
}
digitalWrite(led,HIGH);
}
void loop()
{
if(digitalRead(sensor)==HIGH)
{
digitalWrite(buzzer,HIGH);
delay(3000);
digitalWrite(buzzer,LOW);
while(digitalRead(sensor)==HIGH);
}
}
Code Explanation:
 The code initializes three variables: buzzer (connected to pin 11), sensor (connected
to pin 8), and led (connected to pin 13).
 In the setup() function, the code sets the pinMode for the buzzer as OUTPUT, the
sensor as INPUT, and the LED as OUTPUT. It also initializes these components
with LOW states.
 During the calibration period, the LED blinks every 100 milliseconds for 13 seconds.
 In the loop() function, the code continuously checks the state of the PIR sensor. If
the PIR sensor detects motion (HIGH signal), it activates the buzzer for 3 seconds
and then turns it off when motion is no longer detected.

Observation:
“Write YourObservation Here”

Conclusion:
“Write YourConclusion of Experiment”
Quiz:
1. In the provided project, how long is the calibration period for the PIR sensor?
2. What happens when the PIR sensor detects motion in front of it in the provided project?
3. Which pin on the Arduino is used to connect the PIR sensor's digital output pin in the
project?
4. During the calibration period, how often does the LED connected to Pin 13 blink in the
code?
5. In the project's code, for how many milliseconds is the buzzer activated when motion is
detected by the PIR sensor?

31
References:

“List Down references used to perform above practical”

Rubric wise marks obtained:

PIR Sensor Activation


Circuit Setup Code &
Quiz Performance Ethics
and Connections Understanding Buzzer Activation
Duration
Good Average Good Average Good Average Good Average Good Average
(2) (1) (2) (1) (2) (1) (2) (1) (2) (1)

32
Experiment No: 7

Aim:Measure temperature using DHT-11 sensor and send it to cloud ThingSpeak using
NodeMCU.
Date:

Competency and PracticalSkills:


 Gain competency in working with DHT-11 sensors for temperature and
humidity measurements.
 Develop practical skills in interfacing a NodeMCU with sensors and cloud
platforms for IoT applications.
 Understand the application of IoT in real-world scenarios, including
environmental monitoring and data sharing in the cloud.

Relevant CO: CO3

Objectives:
1. Identify the key components of a DHT-11 sensor and NodeMCU.
2. Build a circuit to connect a DHT-11 sensor to a NodeMCU and configure the NodeMCU
for data transmission.
3. Write Arduino code to read temperature data from the DHT-11 sensor.
4. Set up ThingSpeak, a cloud platform for IoT, and create a channel to receive temperature
data.
5. Send temperature data from the NodeMCU to ThingSpeak for cloud-based storage and
visualization.

Components:
1. DHT-11 Sensor: A sensor module for measuring temperature and humidity.
2. NodeMCU (ESP8266): A low-cost open-source IoT platform for WiFi connectivity.
3. Breadboard and Jumper Wires: Used for easy prototyping and making connections.
4. Power Source (if required): Depending on the components used, an external power
source may be needed for the NodeMCU.
5. ThingSpeak Account: An online platform for collecting, visualizing, and analyzing IoT
data.
Configuration:

Fig 12: Circuit Diagram

33
Fig 13: Node Node MCU with DHT-11
Procedure:
Step 1: Place the Sensor
 Place the DHT11 sensor on a breadboard with the blue part of the sensor facing you.
Ensure the sensor is properly connected to the breadboard.
Step 2: Getting API Key
1. Go to https://thingspeak.com/ and create an account or log in if you already have
one.
2. Create a new channel by clicking the button, providing basic channel details, and
saving the channel.
3. Go to API keys and copy the Write API key to a separate notepad file. You will need
this key in the programming section.
Programming:
1. Write the provided program in the Arduino IDE.
2. Download the DHT11/DHT22 library from GitHub and add it to your library
manager.
3. Select the NodeMCU ESP-12E board from the board manager.
4. Paste the API Key from ThingSpeak (which you obtained earlier) in the program.
5. Edit the program to replace the Wi-Fi SSID and password with your own.
6. Compile the code and upload it to the NodeMCU board.
Code:
#include <DHT.h> // Including library for dht
#include <ESP8266WiFi.h>
String apiKey = "H38TEGNC0XKW43BB"; // Enter your Write API key from
ThingSpeak
const char *ssid = "how2electronics"; // replace with your wifissid and wpa2 key
const char *pass = "alhabibi";
const char* server = "api.thingspeak.com";
#define DHTPIN 0 //pin where the dht11 is connected
DHT dht(DHTPIN, DHT11);
WiFiClient client;
void setup()
{

34
Serial.begin(115200);
delay(10);
dht.begin();
Serial.println("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
}
void loop()
{
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(h) || isnan(t))
{
Serial.println("Failed to read from DHT sensor!");
return;
}
if (client.connect(server,80)) // "184.106.153.149" or api.thingspeak.com
{
String postStr = apiKey;
postStr +="&field1=";
postStr += String(t);
postStr +="&field2=";
postStr += String(h);
postStr += "\r\n\r\n";
client.print("POST /update HTTP/1.1\n");
client.print("Host: api.thingspeak.com\n");
client.print("Connection: close\n");
client.print("X-THINGSPEAKAPIKEY: "+apiKey+"\n");
client.print("Content-Type: application/x-www-form-urlencoded\n");
client.print("Content-Length: ");
client.print(postStr.length());
client.print("\n\n");
client.print(postStr);
Serial.print("Temperature: ");
Serial.print(t);
Serial.print(" degrees Celcius, Humidity: ");
Serial.print(h);
Serial.println("%. Send to Thingspeak.");
}
client.stop();
Serial.println("Waiting...");
// thingspeak needs minimum 15 sec delay between updates
delay(1000);

35
}
Code Explanation:
 The code includes libraries for the DHT sensor and ESP8266 WiFi.
 It defines the API key, WiFi credentials, and the ThingSpeak server.
 The DHT sensor is set up to read from pin D0 (NodeMCU's pin 0).
 The program establishes a connection to the Wi-Fi network using the provided
credentials.
 In the loop, it reads temperature and humidity data from the DHT sensor.
 If the data is valid (not NaN), it connects to ThingSpeak and sends the data using an
HTTP POST request.
 The program prints the temperature and humidity data to the serial monitor.
 A delay of 15 seconds (or more) is added between updates, as ThingSpeak requires a
minimum delay.

Observation:
“Write YourObservation Here”

Conclusion:
“Write YourConclusion of Experiment”
Quiz:
1. In the provided project, which pin is used to connect the DHT-11 sensor to the
NodeMCU?
2. What is the purpose of the ThingSpeak API key in this project?
3. According to the provided code, what is the minimum delay required between data
updates when sending data to ThingSpeak?
4. What should be edited in the code to specify your Wi-Fi network credentials?
5. In the code, what method is used to send data to ThingSpeak for cloud storage?

References:

“List Down references used to perform above practical”

Rubric wise marks obtained:

Circuit Setup Code


ThingSpeak Integration Quiz Performance Ethics
and Connections Understanding
Good Average Good Average Good Average Good Average Good Average
(2) (1) (2) (1) (2) (1) (2) (1) (2) (1)

36
Experiment No: 8

Aim:Controlling Led ON/OFF by giving command from mobile phone. (Use cloud ThingSpeak)
Date:

Competency and PracticalSkills:


 Develop competency in IoT applications and cloud-based control systems.
 Build practical skills in interfacing microcontrollers with cloud platforms for
remote control.
 Understand the practical applications of IoT in real-world scenarios, such as
home automation and remote control.

Relevant CO: CO2

Objectives:
1. Identify the key components required for cloud-based IoT control using ThingSpeak.
2. Build a circuit that connects an LED to a microcontroller (e.g., Arduino) and configure
the microcontroller for cloud-based control.
3. Set up a ThingSpeak channel to receive control commands from a mobile phone.
4. Write code to receive commands from the ThingSpeak channel and control the LED
based on the commands sent from a mobile phone.
5. Use a mobile phone to send commands to ThingSpeak and observe the real-time control
of the LED.

Components:
1. Microcontroller (e.g., Arduino): Used to control the LED.
2. LED and Resistor: Components for the LED circuit.
3. Breadboard and Jumper Wires: Used for circuit prototyping.
4. ThingSpeak Account: An online platform for IoT data control.
5. Mobile Phone: Used to send control commands to ThingSpeak.
6. Power Source (if required): Depending on the components used, an external power
source may be needed for the microcontroller and LED.

Configuration:

Fig 14: Circuit Diagram

37
Fig 15: Node MCU with LED

Procedure:
Step 1: Setting Up ThingSpeak
1. Log in to the ThingSpeak server (https://thingspeak.com/login).
2. If you are a new user, create a new account.
3. After logging in, create a new channel.

38
4. Enter the channel name, description, and select Field 1. Click the checkbox and save
the channel.

5. Make a note of the Channel ID for later use in the Arduino code.

39
Step 2: Firmware
1. Write code in the Arduino IDE, selecting the NodeMCU 12E board.

2. Use the provided code to configure the NodeMCU for connecting to ThingSpeak.
3. Replace the SSID and password with your Wi-Fi network credentials.
4. Enter the ThingSpeak Channel ID in the code.
Channel ID: 1070593, it’s written in code.
5. Upload the code to the NodeMCU.
Code :

#include<ThingSpeak.h>
#include<ESP8266WiFi.h>
#include<ESP8266WebServer.h>
unsigned long channel_num=1070593;
const char* ssid="shravan";
const char* password="8905552134";
int led;
unsignedint value;
WiFiClient client;// make the client of the WiFi which connect to the ThingSpeakwebServer
ESP8266WebServer server(80); // make the naother server
voidsetup()
{
pinMode(D1,OUTPUT);
digitalWrite(D1,0);
Serial.begin(115200);
WiFi.begin(ssid,password); // connect to the wifi STA connection
while(WiFi.status()!=WL_CONNECTED)
{
delay(500);
Serial.print(".");

40
}
Serial.println(WiFi.localIP()); // print the wifi local ip
server.on("/",handleonconnect); // in urt type the "/" then call the handle on connect function

ThingSpeak.begin(client); // connect the client to the thingSpeak server


server.begin(); // start the server
}
voidloop()
{
server.handleClient(); // it realy handle the Client
led=ThingSpeak.readFloatField(channel_num,1); // rad the last data of the field 1
if(led==1)
{
digitalWrite(D1,1);
}
elseif(led==0)
{
digitalWrite(D1,0);
}
}
voidhandleonconnect()
{
server.send(200,"text/html",SendHTML());
}

Step 3: HTML for Mobile Control


1. Create an HTML file to control the LED via a web interface.
2. Provide buttons for turning the LED ON and OFF.
3. Use ThingSpeak update URLs to control the LED via HTTP requests. Update the API
key accordingly.

HTML :

String SendHTML(void){
String ptr = "<!DOCTYPE html><html>\n";
ptr +="<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, user-
scalable=no\">\n";
ptr +="<title>LED Control</title>\n";
ptr +="<style>html { font-family: Helvetica; display: inline-block; margin: 0px auto; text-align:
center;}\n";
ptr +="body{margin-top: 50px;} h1 {color: #444444;margin: 50px auto 30px;} h3
{color:#444444;margin-bottom: 50px;}\n";
ptr +=".button {display: block;width: 80px;background-color: #1abc9c;border: none;color:
white;padding: 13px 30px;text-decoration: none;font-size: 25px;margin: 0px auto35px;cursor:
pointer;border-radius: 4px;}\n";
ptr +=".button-on {background-color: #1abc9c;}\n";

41
ptr +=".button-on:active {background-color: #16a085;}\n";
ptr +=".button-off {background-color: #34495e;}\n";
ptr +=".button-off:active {background-color: #2c3e50;}\n";
ptr +="p {font-size: 14px;color: #888;margin-bottom: 10px;}\n";
ptr +="</style>\n";
ptr +="</head>\n";
ptr +="<body>\n";
ptr +="<h1>ESP8266 with ThingSpeak Server</h1>\n";
ptr +="<h3>Using Station(STA) Mode</h3>\n";
ptr +="<h4>Control status For D1</h4>\n";
ptr +="<a class=\"button button-on\" href=\"https://api.thingspeak.com/update?
api_key=MOHD33LYGVXTG5UF&field1=1\">ON</a>\n";
ptr +="<a class=\"button button-off\" href=\"https://api.thingspeak.com/update?
api_key=MOHD33LYGVXTG5UF&field1=0\">OFF</a>\n";
ptr +="</body>\n";
ptr +="</html>\n";
returnptr;

 That is my HTML code if you are an embedded engineer then do not learn the
HTML and CSS, but knowledge abut the how it work we press the any url.
 https://api.thingspeak.com/update?
api_key=MOHD33LYGVXTG5UF&field1=0 thisurl is copy from the thingserver
here api_key is different in your case last one &field1=0 mean we we press this url
then send the 0 on your thingspeak server to the field1 and &field1=1 mean when
we press this url then send the 1 on your thingspeak server to the field1. but we don't
press the url using HTML code we only clink on the ON button to turn on the led
and OFF button for turn off the led.
 Now go to the thingspeak server click on the API KEYS and copy the Write API
KEY and paste the HTML code code which highlighted on the upper HTML code
pic.

42
Step 4: Share the Channel
1. Share the ThingSpeak channel with everyone to obtain a public link.

2. Copy the Write API KEY from ThingSpeak.

Step 5: Testing
1. Upload the code to the NodeMCU.

43
2. Verify that the NodeMCU connects to Wi-Fi, and note the local IP address.
3. Access the local IP address in a web browser.
4. Use the web interface to control the LED by clicking the ON and OFF buttons.

 Now click on the ON button LED is ON .


 Now click on the OFF button LED is OFF.

 Now show the status of the thingSpeak server.

44
Observation:
“Write YourObservation Here”
Conclusion:
“Write YourConclusion of Experiment”
Quiz:
1. What is the primary purpose of using ThingSpeak in this project?
2. How do you set up a new channel on ThingSpeak
3. In the HTML code for mobile control, what is the purpose of the "ON" and "OFF"
buttons?
4. Which component is responsible for handling HTTP requests and controlling the LED
based on those requests?

References:

“List Down references used to perform above practical”

Rubric wise marks obtained:

Circuit Setup and Code


HTML Interface Quiz Performance Ethics
Connections Understanding
Good Average Good Average Good Average Good Average Good Average
(2) (1) (2) (1) (2) (1) (2) (1) (2) (1)

45
46
Experiment No: 9

Aim:Controlling Led ON/OFF by giving commands using Google Assistant from a mobile
phone. (Use cloud Adafruit)
Date:

Competency and PracticalSkills:


 Understanding of IoT communication protocols.
 Proficiency in cloud-based IoT platforms.
 Knowledge of Arduino programming.
 Mobile app integration with IoT devices.

Relevant CO: CO4

Objectives:
1. To set up an IoT system for controlling an LED using Google Assistant.
2. To integrate a cloud-based platform (Adafruit) into the IoT system for communication.
3. To create an Arduino-based program for controlling the LED.
4. To enable voice commands through Google Assistant for controlling the LED.
5. To provide a seamless user experience by demonstrating the control of the LED via
mobile phone and voice commands.

Components:
1. LED and resistor
2. Arduino or NodeMCU board
3. Google Assistant-enabled mobile phone
4. Adafruit cloud platform
5. Wi-Fi connection
6. Breadboard and connecting wires
Configurations:

Fig: Circuit Diagram – Connections

47
Procedure:
Step 1: Setting up Adafruit IO Account for IOT controlled LED
1. Visit https://io.adafruit.com and create an account.

2. After creating an account, you'll be taken to your home screen. Click on "Feeds" from
the menu.

3. Create a new feed by clicking on "New Feed." Name your feed (e.g., "LED_Control"),
provide a description if desired, select "Field 1," and save the channel.

4. Create a new dashboard by going to "Dashboards" from the menu. Give it a name (e.g.,
"LEDSwitch") and create the dashboard.

48
5. Open your new dashboard by clicking on it. Click the blue "+" button to add new UI
components to the dashboard.

6. Add a button to the dashboard by selecting the first option. Choose the feed you created
earlier and keep the default settings.

49
7. During programming, you will require your unique AIO key. Click on the key button at
the right-hand corner of your window to generate your active key for this project.

Step 2: Connecting to Google Assistant through IFTTT


1. Go to www.ifttt.com and create an account if you haven't already.
2. Click on your username in the top right corner and select "New Applet."
3. You'll see an "If This Then That" window. Click on the blue "+" button and search for
"Google Assistant." Select "Say a simple phrase" as the trigger.

50
4. Define a phrase and create the trigger.
5. Create an action by clicking the "+" button under "That." Search for "Adafruit" and
choose "Send data to Adafruit IO."
6. Select the feed you created earlier and set "Data to save" to "ON" for this applet. Create
the action.

7. Create another applet for turning the LED "OFF" by following the same steps.
8. Both applets will appear under "My Applets" in your account.

51
Step 3: Programming ESP32 for Google Assistant Controlled LED
1. Program your ESP32 using the Arduino IDE. You'll need to include the "Adafruit
MQTT" client library, which can be found by going to "Sketch" > "Include Library" >
"Manage Libraries" and searching for "adafruitmqtt." Install the library.

2. The code provided in the project can be used to connect the ESP32 to Adafruit IO.
Modify the WLAN_SSID, WLAN_PASS, AIO_USERNAME, and AIO_KEY in the
code with your credentials.
3. After modifying the code, upload it to the ESP32.

52
Code:
#include <WiFi.h>
#include "Adafruit_MQTT.h"
#include "Adafruit_MQTT_Client.h"
#define WLAN_SSID "Ashish"
#define WLAN_PASS "12345678"
#define AIO_SERVER "io.adafruit.com"
#define AIO_SERVERPORT 1883
#define AIO_USERNAME "DURGESH_SINGH"
#define AIO_KEY "aio_OQrD206pQvpMfzJhKcPPXBnw79DL"
int output=2;
WiFiClient client; // Create an ESP8266 WiFiClient class to connect to the MQTT
server.
Adafruit_MQTT_Clientmqtt(&client, AIO_SERVER, AIO_SERVERPORT,
AIO_USERNAME, AIO_KEY); // Setup the MQTT client class by passing in
the WiFi
client and MQTT server and login details.
Adafruit_MQTT_SubscribeLED_Control = Adafruit_MQTT_Subscribe(&mqtt,
AIO_USERNAME "/feeds/LED_Control");
voidMQTT_connect();
void setup() {
Serial.begin(115200);
delay(10);
pinMode(2,OUTPUT);
// Connect to WiFi access point.
Serial.println(); Serial.println();
Serial.print("Connecting to ");
Serial.println(WLAN_SSID);
WiFi.begin(WLAN_SSID, WLAN_PASS);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println();
Serial.println("WiFi connected");
Serial.println("IP address: "); Serial.println(WiFi.localIP());
mqtt.subscribe(&LED_Control);
}
uint32_t x=0;
void loop() {
MQTT_connect();
Adafruit_MQTT_Subscribe *subscription;
while ((subscription = mqtt.readSubscription(5000))) {
if (subscription == &LED_Control) {

53
Serial.print(F("Got: "));
Serial.println((char *)LED_Control.lastread);
if (!strcmp((char*) LED_Control.lastread, "ON"))
{
digitalWrite(2, HIGH);
}
else
{
digitalWrite(2, LOW);
}
}
}
}
voidMQTT_connect() {
int8_t ret;
// Stop if already connected.
if (mqtt.connected()) {
return;
}
Serial.print("Connecting to MQTT... ");
uint8_t retries = 3;
while ((ret = mqtt.connect()) != 0) { // connect will return 0 for connected
Serial.println(mqtt.connectErrorString(ret));
Serial.println("Retrying MQTT connection in 5 seconds...");
mqtt.disconnect();
delay(5000); // wait 5 seconds
retries--;
if (retries == 0) {
// basically die and wait for WDT to reset me
while (1);
}
}
Serial.println("MQTT Connected!");
}
4. The ESP32 will connect to Adafruit IO, and you'll be able to control the LED using
Google Assistant via the applets created in IFTTT.
5. After uploading of code open your serial monitor and your serial monitor should look
like this:

54
6. Now open Google assistant in your Android and give voice command like “Turn LED
on” or “Turn LED off” and it will respond you like you defined earlier and you will
observe change of LED state also.

Observation:
“Write YourObservation Here”
Conclusion:
“Write YourConclusion of Experiment”
Quiz:
1. What is the primary purpose of using Adafruit IO in this project?
2. What is IFTTT, and how is it used in this project?
3. Which service is used to set up voice commands for Google Assistant in this project?
4. What is the role of the unique AIO key generated in the Adafruit IO setup?

References:

“List Down references used to perform above practical”

Rubric wise marks obtained:


Setup of Integration Programming
Quiz
Adafruit IO with Google and ESP32 Ethics
Performance
Account Assistant Configuration
Good Average Good Average Good Average Good Average Good Average
(2) (1) (2) (1) (2) (1) (2) (1) (2) (1)

55
Experiment No: 10

Aim:Installing Raspbian OS in Raspberry Pi and performing basic practical like LED


on/off.
Date:

Competency and PracticalSkills:


 Operating System Installation
 Basic Raspberry Pi Setup
 GPIO Pin Control
 Basic Programming Skills

Relevant CO: CO5

Objectives:

1. Install the Raspbian operating system on a Raspberry Pi.


2. Set up the Raspberry Pi with the necessary configurations, including connecting to the
internet.
3. Understand the basics of GPIO (General Purpose Input/Output) pins on the Raspberry
Pi.
4. Write a simple Python script to control an LED connected to one of the GPIO pins.
5. Execute the script to turn the LED on and off using Raspberry Pi.

Components:
 Raspberry Pi (any model with GPIO pins)
 MicroSD card (for Raspbian OS)
 Power supply for Raspberry Pi
 LED
 Resistor (appropriate value to limit LED current)
 Jumper wires
 Breadboard (optional, for easier circuit connections)

Configuration:

Fig: Circuit Diagram

56
Fig: Raspberry Pi with LED
Procedure:
Circuit Setup:
1. Create a simple LED circuit, consisting of an LED and a current-limiting resistor.
2. Calculate the resistor value to limit current based on LED specifications (forward
voltage and forward current) and Raspberry Pi output voltage.
3. Round up the resistor value (e.g., 100 ohms) and use a resistor with the appropriate
color code.
4. Connect the LED and resistor in series with GPIO pin 8 on the Raspberry Pi.
5. Pay attention to the LED's polarity – the long lead (anode) connects to the resistor,
and the short lead (cathode) connects to ground (pin 6 on the Raspberry Pi).

Python Script for LED Control:


1. Install the Raspberry Pi GPIO Python library using the following terminal command:
$ sudo apt-get install python-rpi.gpio python3-rpi.gpio
2. Open a Python IDE (e.g., Thonny Python IDE) for writing the Python script.
3. In your Python script, perform the following tasks:
 Import the necessary libraries, including RPi.GPIO and time.
 Initialize GPIO ports, set pin 8 as an output pin, and set the initial value to
low (off).
 Create an infinite loop.
 Within the loop, turn the LED on and off in 1-second intervals.

Python Code:
importRPi.GPIO as GPIO
from time import sleep

GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)

57
GPIO.setup(8, GPIO.OUT, initial=GPIO.LOW)

while True:
GPIO.output(8, GPIO.HIGH) # Turn on
sleep(1)
GPIO.output(8, GPIO.LOW) # Turn off
sleep(1)

1. Save the Python script as "blinking_led.py."


2. Run the script either in your Python IDE or in the console using the following
command:
$ python blinking_led.py

Observation:
“Write YourObservation Here”
Conclusion:
“Write YourConclusion of Experiment”
Quiz:
1. What is the purpose of a current-limiting resistor in an LED circuit?
2. What is the forward voltage (VF) and forward current (IF) of a typical red LED?
3. In the Raspberry Pi GPIO setup code, what does GPIO.BOARD refer to?
4. What is the purpose of the GPIO.setwarnings(False) line in the Python script?

References:

“List Down references used to perform above practical”

Rubric wise marks obtained:


Understanding of
Python Script Command Execution Quiz Performance Ethics
LED Circuit
Good Average Good Average Good Average Good Average Good Average
(2) (1) (2) (1) (2) (1) (2) (1) (2) (1)

58

You might also like