Tushar IoT file
Tushar IoT file
Practical No:-01
Aim:- Study and Install IDE of Arduino
Introduction to Arduino
Arduino is an open-source hardware and software platform designed to make it easy for anyone
to create interactive electronic projects. It is widely used by hobbyists, students, educators, and
professionals for a variety of applications, from simple DIY projects to complex systems.
Arduino has revolutionized the field of electronics and programming by bridging the gap
between software and hardware. Its simplicity, affordability, and versatility make it a preferred
platform for creating interactive devices that can sense and control the physical world.
1
Tushar Tikia 02590302022 Internet of Things lab file
Core Concepts of
Arduino
1. Digital and Analog Pins:
o Digital pins can be used for input or output, such as controlling LEDs or
reading button presses.
2
Tushar Tikia 02590302022 Internet of Things lab file
o Analog pins allow the board to read analog signals (e.g., from temperature
sensors) and convert them to digital values.
2. Microcontroller:
o The "brain" of the Arduino board, responsible for processing data and
executing the uploaded code.
3. Power Supply:
o Powered via USB or an external power source (e.g., a battery or adapter).
4. Programming:
o Arduino uses a simplified version of C/C++ for programming.
o Key functions include:
▪ setup(): Runs once when the board is powered on or reset, used to
initialize settings.
▪ loop(): Repeats continuously, containing the core logic of your program.
Advantages of Arduino
1. Low Cost: Affordable for beginners and professionals.
2. Versatility: Compatible with a vast array of sensors and modules.
3
Tushar Tikia 02590302022 Internet of Things lab file
3. Community Support: A large, active community provides tutorials, forums, and libraries.
4. Open-Source Ecosystem: Encourages innovation and customization.
5. Cross-Disciplinary Applications: Used in art, science, engineering, and education.
Features of Arduino
Open Source: Arduino's hardware designs and software are open source, encouraging
community collaboration.
Ease of Use: Simple to program and set up, making it beginner-friendly.
Variety of Modules: Compatible with various sensors, actuators, and shields for expansion.
Cross-Platform: Works on Windows, macOS, and Linux.
4
Tushar Tikia 02590302022 Internet of Things lab file
• Download the IDE: Install the Arduino IDE from the official website (arduino.cc).
• Learn the Basics: Start with simple projects, such as blinking an LED.
• Expand: Explore advanced projects using sensors, motors, and communication modules.
5
Tushar Tikia 02590302022 Internet of Things lab file
6
Tushar Tikia 02590302022 Internet of Things lab file
7
Tushar Tikia 02590302022 Internet of Things lab file
8
Tushar Tikia 02590302022 Internet of Things lab file
9
Tushar Tikia 02590302022 Internet of Things lab file
Key Features
• Toolbar:
o New: Create a new sketch.
o Open: Open an existing sketch.
o Save: Save the current sketch.
o Upload: Compile and upload code to the board.
o Verify: Check for code errors.
• Serial Monitor: Exchanges data between the board and computer.
RESULT:
In this practical, we studied and installed the Arduino IDE, which allows programming Arduino
boards using a simplified version of C/C++. We explored key features of the IDE, including
creating and uploading sketches, using libraries, and interacting with hardware through the
Serial Monitor.
10
Tushar Tikia 02590302022 Internet of Things lab file
Practical No:-02
Aim:- Study and Install IDE of NodeMCU
NodeMCU is an open-source IoT platform built on the ESP8266 Wi-Fi SoC (System on
Chip). Designed for Internet of Things (IoT) applications, it integrates hardware and software
features to simplify the process of building connected devices.
1. What is NodeMCU?
NodeMCU stands for Node Microcontroller Unit. It is an open-source development board
and firmware based on the popular ESP8266 module, making it a cost-effective and powerful
choice for IoT applications. It supports both Lua scripting language and Arduino IDE,
allowing developers to program it with ease.
11
Tushar Tikia 02590302022 Internet of Things lab file
• High Compatibility: Supports programming through both Lua scripting language and
the Arduino IDE.
• Integrated GPIO Pins: Provides access to GPIO (General Purpose Input/Output) pins
for interfacing with sensors, LEDs, and other peripherals.
• Additional Communication Protocols:
o PWM (Pulse Width Modulation) for controlling devices like motors.
o I2C (Inter-Integrated Circuit) for interfacing with sensors and other modules.
o SPI (Serial Peripheral Interface) for high-speed communication.
o ADC (Analog-to-Digital Converter) for reading analog signals.
3. NodeMCU Firmware
The NodeMCU firmware runs on the ESP8266 Wi-Fi SoC and is based on the Lua programming
language, offering:
• Easy scripting for IoT projects.
• Ready-to-use libraries for common functions like HTTP requests, MQTT
communication, and GPIO control.
• Open-source development, allowing users to modify or extend its functionality.
4. Applications of NodeMCU
NodeMCU is widely used in IoT projects due to its affordability, compact design, and robust
features. Common applications include:
• Home Automation: Controlling lights, fans, and other appliances remotely.
• Weather Monitoring: Connecting to sensors to measure temperature, humidity,
and pressure.
• Smart Agriculture: Monitoring soil moisture and automating irrigation systems.
• Industrial IoT: Monitoring machinery and automating processes.
• Wearables: Integration into fitness trackers and other smart devices.
5. Advantages of NodeMCU
• Affordable: Low cost compared to other IoT development boards.
• Wi-Fi Connectivity: Simplifies IoT projects with built-in Wi-Fi.
12
Tushar Tikia 02590302022 Internet of Things lab file
6. Programming NodeMCU
NodeMCU can be programmed using:
1. Lua Language: A lightweight scripting language, easy to learn for beginners.
2. Arduino IDE: Allows the use of C/C++ programming and Arduino libraries,
making it accessible to Arduino enthusiasts.
Steps to Program NodeMCU:
1. Install the required software (e.g., Arduino IDE or Lua Loader).
2. Select the NodeMCU board and configure the COM port in the IDE.
3. Write the program (sketch or script) for your project.
4. Upload the program to NodeMCU via a USB connection.
7. Specifications of NodeMCU
• Microcontroller: ESP8266
• Operating Voltage: 3.3V
• Wi-Fi Standards: 802.11 b/g/n
• Flash Memory: 4MB
• GPIO Pins: 16 (available for interfacing)
• Analog Input Pins: 1 (max input voltage 3.3V)
• Clock Speed: 80 MHz (can be overclocked to 160 MHz)
• Power Supply: USB or external (via Vin and GND pins)
8. Limitations of NodeMCU
• Limited GPIO pins compared to larger microcontrollers.
• Single ADC pin restricts the ability to read multiple analog sensors.
• Requires careful handling due to its 3.3V logic level (incompatible with 5V
peripherals without level shifting).
13
Tushar Tikia 02590302022 Internet of Things lab file
14
Tushar Tikia 02590302022 Internet of Things lab file
Important Points
1. Power Supply:
o Use the Vin pin to power NodeMCU externally (5V).
o Use the 3V3 pin for powering peripherals that require 3.3V.
2. Built-In LED:
o The built-in LED is connected to D4 (GPIO2) and can be
controlled programmatically.
3. I2C Communication:
o Default I2C pins: SDA (D2, GPIO4) and SCL (D1, GPIO5).
4. SPI Communication:
o SPI pins include MOSI (D7), MISO (D6), SCK (D5), and CS (D8).
5. UART Communication:
o Serial communication pins: TX (GPIO1) and RX (GPIO3).
6. Analog Input:
o The A0 pin is used for reading analog signals. Voltage must be limited to 0–
3.3V (use a voltage divider for higher voltages).
15
Tushar Tikia 02590302022 Internet of Things lab file
3. Select preferences then select additional board manager and paste the URL here
and click on OK.
4. Now select Tools -> Board ->Board Manager -> Search for ESP8266 by
ESP8266 community and install it.
1. Search for CP2102 driver download on google. Or click on the link given
below. https://www.dnatechindia.com/cp-2102-driver-download-
installation.html
https://drive.google.com/file/d/0B0rzq9C03J8ecUZIdE1KVUFvSVk/view?usp=sh
ari ng&resourcekey=0-7nouXDGHyIX2Kgcxv1uYng
Initially connect your hardware having CP2102 USB to Serial IC to your PC. In the device
manager it will show “CP2102 USB to UART Bridge Controller” (as shown in below figure)
which means that your PC has detected the drivers but please note the “!” sign which indicated
cp2102 drivers have not been installed.
16
Tushar Tikia 02590302022 Internet of Things lab file
Now extract the “CP210x_Windows_Drivers” in a folder and in that you will find applications
named “CP210xVCPInstaller_x64” & “CP210xVCPInstaller_x86”. If your system is 64 bit
then run “CP210xVCPInstaller_x64.exe” application and if it is 32 bit then run
“CP210xVCPInstaller_x86” application.
17
Tushar Tikia 02590302022 Internet of Things lab file
Once you run your application it will show you the welcome screen click “Next” on the screen.
Then the license Agreement screen is shown select “I agree” and then on “Next”.
Just relax now the CP2102 drivers will start installing…..and within few seconds completed screen
will be displayed.
18
Tushar Tikia 02590302022 Internet of Things lab file
Once installed it will show driver successfully installed. Now go again back to device manager
and there you will see that the driver has been successfully been installed and a com port has
been allotted. In below image you can see that “com4” has been allotted for cp2102 IC in my
laptop.
19
Tushar Tikia 02590302022 Internet of Things lab file
Drivers for the CP2102 have now been installed successfully. You can see in above image that
Port Number 4 has been allocated to this IC. If you want you can even change the virtual com
port number from Device Manager.
RESULT:
In this practical, we studied and installed the NodeMCU IDE for IoT projects, exploring its key
features like built-in Wi-Fi, GPIO pins, and communication protocols. We also installed the
necessary CP2102 drivers, enabling successful communication between NodeMCU and the
computer for programming and testing IoT applications.
20
Tushar Tikia 02590302022 Internet of Things lab file
Practical No:-03
Aim:- Write the steps to add libraries in Arduino and setup of
Arduino IDE for programming.
Introduction
Libraries are a collection of code that makes it easy for you to connect to a sensor, display,
module, etc. For example, the Liquid Crystal library makes it easy to talk to character LCD
displays.
21
Tushar Tikia 02590302022 Internet of Things lab file
There are thousands of libraries available for download directly through the Arduino IDE,
and you can find all of them listed at the Arduino Library Reference.
Procedure:
In this example we will install the Bridge library. Scroll the list to find it, click on it, then select
the version of the library you want to install. Sometimes only one version of the library is
available. If the version selection menu does not appear, don't worry: it is normal.
22
Tushar Tikia 02590302022 Internet of Things lab file
Finally click on install and wait for the IDE to install the new library. Downloading may take
time depending on your connection speed. Once it has finished, an Installed tag should appear
next to the Bridge library. You can close the library manager.
23
Tushar Tikia 02590302022 Internet of Things lab file
You can now find the new library available in the Sketch > Include Library menu.
24
Tushar Tikia 02590302022 Internet of Things lab file
Return to the Sketch > Include Library menu. . You should now see the library at the bottom
of the drop-down menu. It is ready to be used in your sketch. The zip file will have been
expanded in the libraries folder in your Arduino sketches directory.
RESULT:
In this practical, we learned how to add libraries to the Arduino IDE, both through the Library
Manager and by importing a .zip library. Using these methods, we can easily extend the
functionality of the Arduino platform to interface with various sensors, displays, and other
modules in our projects.
25
Tushar Tikia 02590302022 Internet of Things lab file
Practical No:-04
Aim:- Introduction to different types of IoT Sensors
Introduction
In IoT (Internet of Things), a sensor is a device that detects and measures physical or
environmental conditions and converts this information into an electrical signal that can be
read, processed, and transmitted to other devices for analysis and action.
26
Tushar Tikia 02590302022 Internet of Things lab file
8. Sound Sensors: Detect sound levels and convert them into an electrical signal
for applications like noise monitoring or audio-based IoT systems.
9. Gas and Smoke Sensors: Detect hazardous gases or smoke, essential for fire alarms
and safety systems.
10. Accelerometers: Measure changes in velocity and movement, commonly used
in wearables, fitness trackers, and automotive systems.
Sensor Type Function Main Uses
Alcohol Sensor Detects alcohol gases Breath analyzers, Safety monitoring
Ultrasonic Sensor Measures distance Parking systems, Robot navigation
IR Optical Sensor Detects objects Line following, Object detection
LDR Sensor Measures light Automatic lighting, Photography
Gas Sensor Detects gases Air quality, Safety systems
Gyroscope Sensor Measures orientation Phone orientation, Gaming
Rain Sensor Detects water Auto wipers, Irrigation
Sense Hat Multiple measurements Weather stations, Education
Photo Diode Light to electrical signal Light detection, Communications
IR Proximity Detects close objects Touchless switches, Robotics
Proximity Sensor Detects objects Manufacturing, Automation
PIR Sensor Detects motion Security, Auto lighting
27
Tushar Tikia 02590302022 Internet of Things lab file
RESULT:
The practical introduces various types of IoT sensors, explaining their functions and
applications across different fields. Sensors in IoT play a crucial role in data collection,
processing, and triggering actions for smart systems, such as smart homes, healthcare,
agriculture, and industrial automation.
28
Tushar Tikia 02590302022 Internet of Things lab file
Practical No:-05
Aim:- Write a Program using NodeMCU for Blink LED
Introduction
This project demonstrates how to blink an LED using a NodeMCU. The LED is controlled by
the GPIO pins of the NodeMCU, and it will blink at a set interval. This is a beginner-friendly
project to understand the basic working of NodeMCU.
Structure
• Objective: To blink an LED on the NodeMCU board at regular intervals using a
simple program.
• Key Features:
o Uses NodeMCU (ESP8266) for control.
o LED blinks at regular intervals (on/off).
o Output visible through the physical LED blinking.
Hardware Required
• NodeMCU Kit (includes NodeMCU ESP8266) – 1 unit
• External LED (optional, for external setup) – 1 unit
• 220-ohm Resistor (optional, for external setup) – 1 unit
• Breadboard and connecting wires (optional, for external setup)
Connections
• Onboard LED:
29
Tushar Tikia 02590302022 Internet of Things lab file
Steps of Working
• Hardware Setup:
Use the onboard LED or connect the external LED as described above.
• Software Setup:
Install the Arduino IDE and ensure the ESP8266 board package is installed.
Connect the NodeMCU to your computer using a USB cable.
• Code Upload:
Open the Arduino IDE.
Select the board and the correct COM port.
Copy and upload the program given below.
• Monitor the Output:
After the program is uploaded successfully, the onboard or external LED will blink at regular
intervals.
Program
pinMode(LED_PIN, OUTPUT);
void loop() {
30
Tushar Tikia 02590302022 Internet of Things lab file
Precautions
• Power Supply: Ensure the NodeMCU kit is connected to a stable power source via USB.
• Pin Configuration: Refer to the IoT Academy kit manual for exact pin labeling
and functionality.
• Connections: Double-check wiring for external LEDs to avoid short circuits.
• Resistor Usage: Use a 220-ohm resistor to protect an external LED from
excessive current.
• Onboard LED Logic: Note that onboard LEDs typically operate with inverted
logic (LOW = ON, HIGH = OFF).
Expected Output
• The onboard or external LED will blink on and off every second.
• The pattern will be:
o LED ON for 1 second.
o LED OFF for 1 second.
RESULT
The LED successfully blinks on and off at 1-second intervals, demonstrating the correct setup
of the NodeMCU hardware and successful program execution. This validates the working of
GPIO pins and basic control logic for LED blinking.
31
Tushar Tikia 02590302022 Internet of Things lab file
Original Output
32
Tushar Tikia 02590302022 Internet of Things lab file
Practical No:-06
Aim:- Write a Program using Monitoring Temperature and
Humidity Using DHT11 and NodeMCU
1. Introduction
The project involves monitoring temperature and humidity using the DHT11 sensor and the
NodeMCU ESP8266 microcontroller. The DHT11 sensor provides digital output for
temperature and humidity, which the NodeMCU reads and displays on the Serial Monitor. This
project is ideal for IoT applications, including weather monitoring systems, smart homes, and
industrial environments.
2. Structure
• Objective: To measure and display temperature (in Celsius and Fahrenheit) and
humidity on the Serial Monitor using NodeMCU and DHT11 sensor.
• Key Features:
o Uses NodeMCU for Wi-Fi compatibility.
o Accurate measurement of temperature and humidity.
o Output visible on the Serial Monitor.
3. Hardware Required
1. NodeMCU ESP8266 (1 unit)
2. DHT11 Sensor (1 unit)
3. Connecting Wires
4. USB Cable (to connect NodeMCU to the computer)
5. Breadboard (optional, for easier wiring)
4. Connections
Here is the connection of the DHT11 sensor with NodeMCU:
VCC 3.3V
GND GND
DATA D4 (GPIO2)
33
Tushar Tikia 02590302022 Internet of Things lab file
5. Steps of Working
1. Hardware Setup:
o Connect the DHT11 sensor to the NodeMCU as per the connection diagram.
o Ensure secure connections to avoid loose wiring.
2. Software Setup:
o Install the Arduino IDE on your computer.
o Add the ESP8266 Board Package to the Arduino IDE (via Preferences
→ Additional Board URLs).
o Install the DHT Sensor Library from the Library Manager (search for
"DHT Sensor Library").
3. Code Upload:
o Select the correct board (NodeMCU 1.0 (ESP-12E)) and port in the Arduino IDE.
o Upload the program (given below) to the NodeMCU.
4. Monitor the Output:
o Open the Serial Monitor in the Arduino IDE.
o Set the baud rate to 115200 to view the temperature and humidity readings.
6. Program
#include <DHT.h> // Include the DHT sensor library
34
Tushar Tikia 02590302022 Internet of Things lab file
void setup() {
// Begin communication with Serial
Monitor Serial.begin(115200);
35
Tushar Tikia 02590302022 Internet of Things lab file
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.print(" %\t");
Serial.print("Temperature in Celsius:
"); Serial.print(temperatureC);
Serial.print(" °C\t");
Serial.print("Temperature in Fahrenheit: ");
Serial.print(temperatureF);
Serial.println(" °F");
}
7. Precautions
1. Power Supply: Ensure that the NodeMCU is connected to a stable power source via
the USB cable.
2. Connections: Double-check all connections to avoid short circuits or loose connections.
3. Library Installation: Make sure the DHT Sensor Library and ESP8266 Board Package
are properly installed in the Arduino IDE.
4. Sensor Placement: Place the DHT11 sensor in an environment free from
external interference, such as direct heat or moisture, for accurate readings.
5. Baud Rate: Set the Serial Monitor's baud rate to 115200 for proper data display.
8. Expected Output
After successful code upload and execution:
• Humidity and temperature readings will be displayed on the Serial Monitor in the
following format:
Humidity: 45.00 % Temperature in Celsius: 25.50 °C Temperature in Fahrenheit: 77.90
°F
• If there’s an error in reading the sensor, the
message: Error: Failed to read from DHT sensor!
will be displayed.
36
Tushar Tikia 02590302022 Internet of Things lab file
RESULT:
The NodeMCU successfully reads and displays temperature and humidity values from the
DHT11 sensor on the Serial Monitor. Accurate readings are shown in both Celsius and
Fahrenheit, along with the humidity percentage, validating the setup and functionality.
Original Output
37
Tushar Tikia 02590302022 Internet of Things lab file
38
Tushar Tikia 02590302022 Internet of Things lab file
Practical No:-07
Aim:- Write a Program to Fade LED on NodeMCU
1. Introduction
This project demonstrates how to fade an LED connected to a NodeMCU board (ESP8266)
using the analogWrite() function. The LED's brightness will gradually increase and decrease to
create a fading effect. This project is a basic example of how to use PWM-like functionality on
the NodeMCU board.
2. Structure
• Objective: To fade an LED connected to a NodeMCU using the analogWrite()
function, creating a smooth fading effect.
• Key Features:
o Uses NodeMCU (ESP8266) for control.
o Gradual change in LED brightness (fade in and fade out).
o Simulates analog brightness control using PWM.
3. Hardware Required
• NodeMCU ESP8266 – 1 unit
• LED – 1 unit
• 220-ohm Resistor – 1 unit (optional, for protection)
• Breadboard and Connecting Wires – as required
• USB Cable – to connect NodeMCU to the computer
4. Connections
• Connect the anode (longer leg) of the LED to GPIO4 (D2) on NodeMCU.
• Connect the cathode (shorter leg) to GND through a 220-ohm resistor (optional).
5. Steps of Working
1. Hardware Setup:
39
Tushar Tikia 02590302022 Internet of Things lab file
6. Program
// Define the pin where the LED is connected
#define LED_PIN 4 // GPIO4 corresponds to D2 on NodeMCU
void setup() {
// Set the LED pin as an output
pinMode(LED_PIN, OUTPUT);
}
void loop() {
// Set the LED brightness using PWM
analogWrite(LED_PIN, brightness);
40
Tushar Tikia 02590302022 Internet of Things lab file
7. Precautions
1. Power Supply: Ensure that the NodeMCU is connected to a stable power source via USB.
2. Pin Configuration: GPIO4 (D2) on NodeMCU is used for PWM control. Ensure the
pin supports PWM functionality.
3. Connections: Double-check all wiring connections to avoid short circuits and
ensure proper LED orientation.
4. Resistor Usage: Always use a resistor (220-ohm or similar) to protect the LED
from excessive current.
5. Smoothness: This program creates a fade effect by changing brightness in steps. You
may need to adjust delay() for a smoother fade.
8. Expected Output
• After uploading and running the program:
o The LED will gradually fade in (increase brightness) and fade out
(decrease brightness).
o The fading will happen continuously, reversing direction when the
brightness reaches the minimum (0) or maximum (255).
RESULT:
The LED connected to the NodeMCU will gradually fade in and out, increasing and decreasing
its brightness in smooth steps. The fading effect will continuously reverse direction between
the minimum and maximum brightness levels.
41
Tushar Tikia 02590302022 Internet of Things lab file
Original Output
42
Tushar Tikia 02590302022 Internet of Things lab file
Practical No:-08
Aim:- Write a program to print “ Hello World” on LCD
Display using NodeMCU
1. Introduction
To display a "Hello, World!" message on an LED screen using a NodeMCU, you'll typically
use an OLED display, such as the popular SSD1306 OLED display. Below is a basic
example of how to display "Hello, World!" on a 128x64 OLED screen using NodeMCU and
the Arduino IDE.
2. Hardware Required
• NodeMCU ESP8266 – 1 unit
• OLED Display (SSD1306) – 1 unit (128x64)
• Connecting Wires
• Breadboard (optional)
3. Connections
• VCC/VDD of the OLED to 3V on NodeMCU
• GND of the OLED to GND on NodeMCU
• SCL/SCK of the OLED to D1 (GPIO5) on NodeMCU
• SDA of the OLED to D2 (GPIO4) on NodeMCU
43
Tushar Tikia 02590302022 Internet of Things lab file
5. Program
#include <Wire.h> // Include the Wire library for I2C
pixels
Serial.begin(115200);
44
Tushar Tikia 02590302022 Internet of Things lab file
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
for(;;);
}
// Clear the display
buffer
display.clearDisplay()
display.setTextColor(SSD1306_WHITE);
display.setTextSize(1);
display.setCursor(0, 0);
45
Tushar Tikia 02590302022 Internet of Things lab file
display.display();
}
void loop() {
6. Precautions
• Ensure proper wiring connections to avoid display malfunctions.
• Make sure the OLED display is compatible with the I2C protocol (SSD1306).
• Check the address of the SSD1306 OLED (usually 0x3C or 0x3D).
7. Expected Output
The OLED display will show the message "Hello, World !" centered on the screen, once
the program is uploaded and executed on the NodeMCU.
RESULTS
The OLED display successfully shows the message "Hello, World!". The output is clear and stable,
indicating proper communication between the NodeMCU and the SSD1306 OLED display.
46
Tushar Tikia 02590302022 Internet of Things lab file
Original Output
47
Tushar Tikia 02590302022 Internet of Things lab file
Practical No:-09
Aim:- Write a program to Monitoring Air Quality Using
NodeMCU and MQ135 Sensor
1. Introduction
The MQ135 sensor is widely used for air quality monitoring. It detects gases like CO2, NH3,
benzene, and smoke. This program uses NodeMCU to read sensor values and categorize air
quality into qualitative levels like "Good," "Moderate," and "Poor."
2. Hardware Required
1. NodeMCU ESP8266 – 1 unit
2. MQ135 Air Quality Sensor – 1 unit
3. Connecting Wires
4. Breadboard (optional)
3. Connections
MQ135 Pin NodeMCU Pin
VCC 3.3V
GND GND
AOUT A0
DOUT D2 (GPIO4)
4. Steps of Working
1. Hardware Setup:
o Connect the sensor's pins to the NodeMCU as per the wiring diagram.
o Ensure secure connections.
2. Software Setup:
o Install and open the Arduino IDE.
48
Tushar Tikia 02590302022 Internet of Things lab file
5. Program
void setup() {
// Start serial communication
Serial.begin(115200);
// Welcome message
Serial.println("MQ135 Real-World Air Quality Monitoring");
}
void loop() {
// Read analog value (proportional to gas
concentration) int airQualityAnalog =
analogRead(MQ135_AOUT);
49
Tushar Tikia 02590302022 Internet of Things lab file
airQualityCategory = "Moderate";
} else if (airQualityAnalog < 600) {
airQualityCategory = "Unhealthy";
} else {
airQualityCategory = "Hazardous";
}
6. Precautions
• Ensure the MQ135 sensor is powered by a stable 3.3V.
• Place the sensor in a well-ventilated environment for accurate readings.
• Warm up the MQ135 sensor for at least 5 minutes before taking measurements.
50
Tushar Tikia 02590302022 Internet of Things lab file
7. Expected Output
1. Serial Monitor Output:
Analog Air Quality Value:
150 Air Quality Category:
Good
Digital Status: Air Quality is Good
2. Real-Time Air Quality:
o The analog value will vary based on gas concentration.
o The category will update based on predefined thresholds.
RESULTS
The NodeMCU successfully monitors air quality using the MQ135 sensor. It categorizes air
quality as "Good," "Moderate," "Unhealthy," or "Hazardous" based on analog readings and
displays the results in real time on the Serial Monitor.
51
Tushar Tikia 02590302022 Internet of Things lab file
Original Output
52
Tushar Tikia 02590302022 Internet of Things lab file
Practical No:-10
Aim:- Write a program for Arduino by using Ultrasonic sensors
and servo motor (HC- SR04), and make a smart dustbin.
1. Introduction
This project demonstrates an automated dustbin lid mechanism controlled by an ultrasonic
sensor and a servo motor. The system opens the lid when an object is detected within a specified
range and closes it after a short delay. This automation promotes hygienic waste disposal
practices.
2. Structure
The program consists of:
1. Setting up the hardware components (ultrasonic sensor and servo motor).
2. Measuring the distance to detect the presence of an object.
3. Controlling the servo motor to open and close the lid based on distance measurements.
3. Hardware Required
• Arduino board (e.g., Uno)
• HC-SR04 Ultrasonic Sensor
• Servo motor (e.g., SG90)
• Jumper wires
• Breadboard
• Power source (USB or battery)
4. Connections
Component Pin Name Connection
VCC 5V
GND GND
Ultrasonic Sensor
Trig Pin 9
Echo Pin 8
Signal Pin 3
Servo Motor VCC 5V
GND GND
53
Tushar Tikia 02590302022 Internet of Things lab file
5. Steps of Working
1. The ultrasonic sensor measures the distance to a nearby object.
2. If an object is detected within 15 cm, the program sends a signal to the servo motor to
open the lid.
3. After a 2-second delay, the servo motor closes the lid.
4. If no object is detected, the lid remains closed.
6. Program
#include <Servo.h>
// Define servo
motor Servo
dustbinLid; const
int servoPin = 3;
void setup() {
// Initialize Serial Monitor
Serial.begin(9600);
54
Tushar Tikia 02590302022 Internet of Things lab file
void loop() {
// Measure distance using ultrasonic
sensor long duration, distance;
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Calculate distance in cm
duration = pulseIn(echoPin,
HIGH); distance = duration *
0.034 / 2;
55
Tushar Tikia 02590302022 Internet of Things lab file
8. Expected Output
• When an object is detected within 15 cm, the dustbin lid opens, remains open for 2
seconds, and then closes automatically.
• The measured distance is displayed on the Serial Monitor.
RESULTS
The automated dustbin lid system functions as expected, providing hands-free operation for
hygienic waste disposal.
56
Tushar Tikia 02590302022 Internet of Things lab file
Original Output
57
Tushar Tikia 02590302022 Internet of Things lab file
58
Tushar Tikia 02590302022 Internet of Things lab file
Practical No:-11
Aim:- Write a program for Blink LED using NodeMCU (ESP8266)
and Blynk app
1. Introduction
This project demonstrates how to control an LED remotely using the Blynk IoT platform and
an ESP8266 microcontroller. Users can toggle the LED on/off using either the Blynk mobile
app or web dashboard.
2. Structure
The system consists of three main components:
• ESP8266 microcontroller with an LED
• Blynk cloud server
• Blynk app/web interface for control
3. Hardware Required
• ESP8266 development board (NodeMCU or similar)
• LED
• 220Ω resistor
• Breadboard
• Jumper wires
• Micro USB cable for programming
• Smartphone with internet connection
• Computer with Arduino IDE installed
4. Connection Diagram
1. Connect LED anode (longer leg) to GPIO16 (D0) through a 220Ω resistor
2. Connect LED cathode (shorter leg) to GND
3. Power ESP8266 via USB or external power supply
59
Tushar Tikia 02590302022 Internet of Things lab file
5. Steps of Working
1. ESP8266 connects to WiFi network
2. Device establishes connection with Blynk cloud
3. Blynk app/web interface communicates with cloud
4. Cloud sends commands to ESP8266
5. ESP8266 controls LED based on received commands
60
Tushar Tikia 02590302022 Internet of Things lab file
o Select Button
o Set output pin to V0
o Set mode to Switch
8. Program
// Include the library files
#define BLYNK_PRINT
Serial #include
<ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
void setup() {
// Set the LED pin as an output pin
pinMode(LED_PIN, OUTPUT);
// Initialize the Blynk library
Blynk.begin(auth, ssid, pass, "blynk.cloud", 80);
}
void loop() {
61
Tushar Tikia 02590302022 Internet of Things lab file
RESULTS:
When you press the button in the Blynk mobile app or web dashboard, the LED connected to
GPIO16 (D0) of ESP8266 will turn ON, and when you release the button, the LED will turn
OFF. The changes are instantaneous with real-time synchronization between the LED state and
the Blynk interface.
62
Tushar Tikia 02590302022 Internet of Things lab file
Original Output
Figure:- LED ON
63
Tushar Tikia 02590302022 Internet of Things lab file
64