Final IOT
Final IOT
Internet ofThings
(3164206)
B.E. Semester 6
(Computer Science & Engineering-Data
Science)
Enrolment No 230173146015
Name Pasee Pruthviraj Jitendra
Academic Term 2024-25
Institute Name Vishwakarma Government Engineering
College
CERTIFICATE
017) has satisfactorily completed the Practical / Tutorial work for the
Place:
Date:
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-based curriculum 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 creates an 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 student centric 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.
DTE’s Vision
▪ 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
Institute’s Mission
Department’s Vision
Department’s Mission
Aim: Understanding Arduino UNO, Node MCU and Raspberry Pi and Arduino IDE.
Date:
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).
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.
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 3: Raspberry Pi
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.
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:
Arduino UNO, NodeMCU, and Raspberry Pi serve different purposes in embedded systems and IoT
development. Arduino UNO, based on the ATmega328P microcontroller, is designed for simple,
real-time applications, with digital and analog input/output capabilities. NodeMCU, built on the
ESP8266/ESP32, integrates Wi-Fi, making it well-suited for IoT projects. Raspberry Pi, unlike the
others, is a complete mini-computer with a Linux-based OS, supporting high-level computing tasks,
including machine learning and multimedia applications. The Arduino IDE simplifies programming,
mainly supporting Arduino and ESP-based boards, while Raspberry Pi relies on Python and other
development environments.
Conclusion:
Each board has its strengths depending on the project’s complexity. Arduino UNO is
best for basic electronics and sensor-based applications. NodeMCU is ideal for IoT
solutions requiring wireless connectivity. Raspberry Pi, with its higher processing
power, is preferred for advanced computing tasks. The Arduino IDE provides an
easy-to-use coding environment, mainly for microcontroller-based projects, ensuring
accessibility for beginners and hobbyists.
Quiz:
1. Which hardware platform is known for its versatility and use as a single-board
computer in IoT applications?
Ans. Raspberry Pi
2. What is the primary function of the Arduino Integrated Development Environment
(IDE)?
Ans. To write, compile, and upload code to Arduino boards.
3. In the context of Arduino programming, what is the purpose of the setup ()
function? Ans. To initialize settings and run once when the Arduino starts.
4. Which hardware platform is typically used to create web servers and Wi-Fi-enabled
IoT applications?
Ans. ESP8266 / ESP32
5. Which of the following IoT hardware platforms is primarily based on the use of
GPIO pins for interfacing with sensors and devices?
Ans. Raspberry Pi/Arduino
References:
● Books:-
o Arduino for Dummies – John Nussey
o Internet of Things with ESP8266 – Marco Schwartz
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.
Configuration:
Fig 4: Schematic
Diagram
Procedure:
void loop()
{
digitalWrite(13, HIGH);
delay(1000); // Wait for 1000 millisecond(s)
digitalWrite(13, LOW);
delay(1000); // Wait for 1000 millisecond(s)
}
Observation:
Conclusion:
Controlling an LED using Arduino UNO demonstrates basic microcontroller programming and digital
output control. By using simple code with `digitalWrite()`, we can turn the LED ON and OFF through an
Arduino pin. This experiment helps in understanding circuit connections, the working of GPIO pins, and
fundamental programming concepts in the Arduino IDE. It serves as a foundation for more advanced
projects involving sensors, actuators, and automation.
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?
Ans. D7
3. In the provided Arduino code, what is the purpose of the pin Mode
(LED_BUILTIN, OUTPUT); line in the setup () function?
Ans. It configures the built-in LED pin as an output to control its state.
4. How long does the LED stay on in the provided Arduino code before turning off
in the loop () function?
Ans. In the given project the LED turns on when the button is pressed.
References:
● Books:-
o Arduino for Dummies – John Nussey
o Internet of Things with ESP8266 – Marco Schwartz
●IDE :-
marks obtained:
Aim: Measuring Temperature and Humidity using Sensor DHT-11 and Arduino UNO.
Date:
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.
Configuration:
voltage = reading*5/1024;
Serial.print("Voltage Reading : ");
Serial.println(voltage);
delay(3000);
}
Output:
Conclusion:
Measuring temperature using the DHT-11 sensor and Arduino UNO is a simple and effective way to
monitor environmental conditions. The DHT-11 provides digital temperature and humidity readings with
decent accuracy, making it suitable for basic weather stations and IoT applications. This experiment
demonstrates how microcontrollers interact with sensors, reinforcing concepts of data acquisition, signal
processing, and real-time monitoring.
Quiz:
1. In the serial monitor, how often (In seconds) does the sensor data update in the
provided code?
Ans. The sensor data is updated is every 5 seconds.
References:
● Books:-
o Arduino for Dummies – John Nussey
o Internet of Things with ESP8266 – Marco Schwartz
●IDE :-
marks obtained:
Code Understanding
Sensor
Connection Setup & Quiz Performance Ethics
Placement Data Display
Goo Average Goo Average Goo Average Goo Average Goo Average
d (1) d (1) d (1) d (1) d (1)
(2) (2) (2) (2) (2)
Experiment No: 4
Aim: Measuring object presence using IR Sensor and when present, use buzzer for
notification.
Date:
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:
Observation:
Conclusion:
The IR sensor successfully detected object presence, triggering the buzzer for notification,
demonstrating an effective method for proximity sensing in automation and security
systems.
Quiz:
1. In the provided procedure, which pin is connected to the IR sensor for reading its
output value? Ans. The OUT pin of IR sensor is connected to the D2 pin of the Arduino.
5. In the procedure, what is the purpose of opening the serial monitor in the Arduino IDE?
Ans. In this experiment the serial monitor is used to the sensor value (0 if object is present and 1 if not).
References:
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:
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.
Code:
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
#define trigPin A0
#define echoPin A1
void setup() {
pinMode(trigPin,
OUTPUT);
pinMode(echoPin,
INPUT);
lcd.init();
lcd.backlight();
lcd.clear();
lcd.setCursor(0,0
);
lcd.print("Simple
Circuits"); delay(2000);
lcd.clear();
}
void loop() {
long duration,
distance; float
distanceInch;
// Display on LCD
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Distance:
"); lcd.print(distance);
lcd.print(" cm");
lcd.setCursor(0, 1);
lcd.print("Distance: ");
lcd.print(distanceInch);
lcd.print(" inch");
Conclusion:
Measuring object distance using an ultrasonic sensor and Arduino UNO is an efficient and cost-effective
method for distance measurement. The ultrasonic sensor (HC-SR04) calculates distance by emitting
ultrasonic waves and measuring the time taken for the echo to return. Arduino UNO processes this data
and converts it into distance values. This setup is widely used in automation, obstacle detection, and
robotics due to its accuracy and ease of implementation.
Quiz:
1. In the provided procedure, which pins on the Arduino are connected to the "trigger"
and "echo" pins of the Ultrasonic sensor?
Ans. ECHO is connected to D2 and TRIG is connected to D3.
4. In the code, what value is used to calculate the distance based on the time it takes
for the echo signal to return?
Ans. The speed of sound in air is nearly 344 m/s.
5. What is the purpose of opening the serial monitor in the Arduino IDE when using
the Ultrasonic sensor?
Ans. To see the distance measured by the ultrasonic sensor.
References:
IDE: - Tinkercad
Aim: Measuring moving object using PIR Sensor and Arduino Uno.
Date:
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:
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:
void setup()
{
pinMode(2, INPUT);
pinMode(13, OUTPUT);
}
void loop()
{
if(digitalRead(2) == HIGH)
{
digitalWrite(13,HIGH);
}
else
{
digitalWrite(13,LOW);
}
delay(10);
}
Observation:
Conclusion:
The experiment using a PIR sensor and Arduino Uno to measure a moving object
demonstrates the sensor's ability to detect motion based on infrared radiation changes.
While effective for motion detection, the PIR sensor does not provide precise distance or
speed measurements, as it only detects movement within its field of view. The experiment
highlights its suitability for applications like security systems and automation but shows
limitations in scenarios requiring detailed motion tracking.
Quiz:
1. In the provided project, how long is the calibration period for the PIR
sensor? Ans. The calibration period of the PIR sensor is 20 seconds.
2. What happens when the PIR sensor detects motion in front of it in the provided
project? Ans. Passive Infrared (PIR) sensors detect heat energy by comparing the
signals from a pair of pyroelectric elements. The supporting circuitry then sends a
HIGH signal to its signal wire. So, the buzzer starts to ring for 1.5 seconds.
3. Which pin on the Arduino is used to connect the PIR sensor's digital output pin in
the project?
Ans. D8
4. During the calibration period, how often does the LED connected to Pin 13 blink
in the code?
Ans. During the calibration period, the LED blinks every 100 milliseconds for 13
seconds.
5. In the project's code, for how many milliseconds is the buzzer activated when
motion is detected by the PIR sensor?
Ans. 1.5 seconds
References:
IDE: - Tinkercad
Aim: Measure temperature using DHT-11 sensor and send it to cloud ThingSpeak using
NodeMCU.
Date:
Objectives:
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:
// ThingSpeak Settings
const char* server = "api.thingspeak.com";
String apiKey = "YOUR_API_KEY"; // Replace with your ThingSpeak Write API Key
WiFiClient client;
void setup() {
Serial.begin(115
200); delay(10);
dht.begin();
Serial.println("Connecting to WiFi...");
WiFi.begin(ssid, password);
while (WiFi.status() !=
WL_CONNECTED) { delay(1000);
Serial.print(".");
}
Serial.println("\nWiFi connected");
}
void loop() {
float temp = dht.readTemperature(); // Temperature in Celsius
if (isnan(temp)) {
Serial.println("Failed to read from DHT
sensor!"); return;
}
if (client.connect(server, 80)) {
String postStr = "api_key=" + apiKey + "&field1=" + String(temp);
client.println("POST /update
HTTP/1.1"); client.println("Host:
api.thingspeak.com");
client.println("Connection: close");
client.println("Content-Type:
application/x-www-form-urlencoded");
client.print("Content-Length: ");
client.println(postStr.length())
; client.println();
client.print(postStr);
Conclusion:
This project demonstrates how IoT devices like NodeMCU can collect real-time environmental
data and upload it to the cloud, enabling remote monitoring and data visualization from anywhere.
Quiz:
1. In the provided project, which pin is used to connect the DHT-11 sensor to the
NodeMCU?
Ans.The D2 pin (GPIO4) is used to connect the DHT-11 sensor.
2. What is the purpose of the ThingSpeak API key in this project?
Ans. The API key is used to authenticate and authorize the data upload to your
specific ThingSpeak channel.
3. According to the provided code, what is the minimum delay required between data
updates when sending data to ThingSpeak?
Ans. The minimum delay is 15 seconds, as specified by delay(15000);
4. What should be edited in the code to specify your Wi-Fi network
credentials? Ans. We should replace:
const char* ssid = "YOUR_WIFI_SSID";
const char* password = "YOUR_WIFI_PASSWORD";
5. In the code, what method is used to send data to ThingSpeak for cloud storage?
Ans. AHTTP POST request is used via the
line: client.println("POST/updateHTTP/1.1");
using the WiFiClient object.
References:
Tinkercad, ChatGpt, GeeksForGeeks
Aim: Controlling Led ON/OFF by giving command from mobile phone. (Use cloud ThingSpeak)
Date:
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
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.
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.
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;
unsigned int value;
WiFiClient client; // make the client of the WiFi which connect to the ThingSpeak
webServer ESP8266WebServer server(80);// make the naother server
{
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(".");
}
Serial.println(WiFi.localIP()); // print the wifi local ip
server.on("/",handleonconnect); // in urt type the "/" then call the handle on connect function
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
auto 35px;cursor: pointer;border-radius: 4px;}\n";
ptr +=".button-on {background-color: #1abc9c;}\n";
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";
return ptr;
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&fiel
d1= 0 this url 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.
Step 5: Testing
1. Upload the code to the NodeMCU.
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.
Conclusion:
This project demonstrates a basic yet powerful example of home automation using IoT. By
integrating mobile control with NodeMCU, it shows how everyday devices like LEDs can be
remotely controlled through Wi-Fi, laying the foundation for smart home systems.
Quiz:
1. What is the primary purpose of using ThingSpeak in this project?
Ans. The primary purpose of ThingSpeak is to store, monitor, and visualize sensor data (like
temperature) in real time over the internet.
3. In the HTML code for mobile control, what is the purpose of the "ON" and "OFF"
buttons?
Ans. The "ON" and "OFF" buttons send commands to the NodeMCU through a web interface to
turn the LED on or off remotely.
4. Which component is responsible for handling HTTP requests and controlling the
LED based on those requests?
Ans. The NodeMCU (ESP8266), using its built-in web server, handles HTTP requests and controls
the LED accordingly.
References:
Tinkercad, ChatGpt, GeeksForGeeks
Aim: Controlling Led ON/OFF by giving commands using Google Assistant from a mobile
phone. (Use cloud Adafruit)
Date:
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:
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.
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.
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.
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.
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 "adafruit mqtt." 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.
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_Client mqtt(&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_Subscribe LED_Control = Adafruit_MQTT_Subscribe(&mqtt,
AIO_USERNAME "/feeds/LED_Control");
void
MQTT_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) { Serial.print(F("Got: "));
Serial.println((char *)LED_Control.lastread);
if (!strcmp((char*) LED_Control.lastread, "ON"))
{
digitalWrite(2, HIGH);
}
else
{
digitalWrite(2, LOW);
}
}
}
}
void MQTT_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:
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:
Conclusion:
This project shows how we can control an LED using voice commands through Google
Assistant. It uses NodeMCU, Adafruit IO, and IFTTT to make smart home control easy and
wireless.
Quiz:
1. What is the primary purpose of using Adafruit IO in this project? \
Ans. The primary purpose of Adafruit IO is to store and manage data (like LED status) and
communicate between NodeMCU and Google Assistant.
3. Which service is used to set up voice commands for Google Assistant in this project?
Ans. The Google Assistant service on IFTTT is used to create custom voice command triggers.
4. What is the role of the unique AIO key generated in the Adafruit IO setup?
Ans. The AIO key is like a password that authenticates and secures the connection between the
NodeMCU and your Adafruit IO account.
References:
Aim: Installing Raspbian OS in Raspberry Pi and performing basic practical like LED on/off.
Date:
Objectives:
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:
Python Code:
import RPi.GPIO as
GPIO from time import
sleep
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
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:
Conclusion:
This project shows how Raspberry Pi can act as a mini-computer for learning programming and
electronics. Installing the OS and performing tasks like LED control helps beginners understand
GPIO usage, Python scripting, and real-world hardware interaction.
Quiz: 1. What is the purpose of a current-limiting resistor in
an LED circuit?
Ans. To prevent too much current from flowing
through the LED, which could damage or burn it out.
References:
Tinkercad, ChatGpt, GeeksForGeeks
Rubric wise marks obtained:
Understanding of
Python Script Command Execution Quiz Performance Ethics
LED Circuit
Goo Average Goo Average Goo Averag Goo Average Goo Average
d (1) d (1) d e (1) d (1) d (1)
(2) (2) (2) (2) (2)