0% found this document useful (0 votes)
28 views41 pages

047 Iotdeepanshi

reading manual for it

Uploaded by

adeepanshi03
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views41 pages

047 Iotdeepanshi

reading manual for it

Uploaded by

adeepanshi03
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 41

Jagan Institute of Management Studies

SECTOR – 5, ROHINI, NEW DELHI

(Affiliated to)

GURU GOBIND SINGH INDRAPRASTHA UNIVERSITY


SECTOR – 16 C, DWARKA, NEW DELHI

INTERNET OF THINGS LAB


(MCA 267)

Submitted To: Submitted by:

Ms. Suman Singh Deepanshi

Assistant Professor 04750404423

Department of IT MCA III – A (Shift 2)


CERTIFICATE

This is certified to be the bonafide work of the student, Name: Deepanshi,

Enrollment No.: 04750404423 for the purpose of subject Internet of Things of

MCA, 3rd semester under my supervision during the academic year 2023-2025.

Ms. Suman Singh


Assistant Professor
Department of IT
ACKNOWLEDGEMENT
I take this opportunity to present my votes of thanks to my faculty who really

acted as pillars to help my way throughout the execution of lab exercises that has

led to successful and satisfactory completion of the study of Artificial Intelligence

and Machine Learning.

I feel great sense of gratitude for Ms. Suman Singh under whose guidance and

motivation this work has been performed.

I would also like to express my thanks to all lab assistants for giving me

opportunity to work under their esteemed guidance. This project would not have

completed without their guidance and coordination.

The inspiration of the faculty members of the Information Technology

Department of JIMS Rohini (Sec-5) enabled me to make a thorough study of these

subjects.

Student Name: Deepanshi

Enrollment No.: 04750404423


INDEX
S.no. Experiment Page No. Signature

1 To understand various component of IoT


tool Kit (such as Jumper wire, bread 1
board, various sensors, and actuators).
2 To understand the Arduino Board
architecture and Raspberry Pi pin 4
diagram and architecture.
3 To understand the basic of Arduino IDE
7
programming and Install IDE of Arduino.
4 Write steps to Write Program in Arduino
and add libraries in Arduino and setup of 9
Arduino IDE for programming.
5 Write a Program using Arduino for Blink
11
LED.
6 To Demonstrate Autodesk Tinkercad
12
Simulation Platform.
7 Controlling the Light Emitting Diode
15
(LED) with a push button.
8 Measure the Distance Using Ultrasonic
17
Sensor and Make Led Blink Using Arduino
9 Sense The Available Networks Using
20
Arduino
10 Write a program to blink multiple LEDs
using: a) Without breadboard, b) With 22
breadboard.
11 Interface DHT11 Sensor for temperature
25
and humidity monitoring.
12 Write a program to blink an LED based on
27
input from a PIR motion sensor
13 Interface Three LEDs with an Ultrasonic
29
Sensor to display proximity-based actions.
14 Write down the steps to demonstrate the
setup of Blynk app using Node MCU 32
(ESP8266).
15 Write a program for controlling LED
36
on/off using Blynk app.
EXPERIMENT 1
AIM: To understand various component of IoT tool Kit (such as Jumper wire, bread board,
various sensors, and actuators).

The Internet of Things (IoT) toolkit contains various components that enable the creation
of interconnected devices.

1. Jumper Wires

Function: Jumper wires are used to connect different components on a breadboard or


between other devices (e.g., microcontrollers, sensors, actuators).

Types:

• Male-to-Male
• Male-to-Female
• Female-to-Female

Usage: They help transfer signals and power between components without the need for
soldering. In IoT projects, jumper wires connect sensors to microcontrollers like Arduino
or Raspberry Pi.

2. Breadboard

Function: A breadboard is a construction base for prototyping electronics. It allows


components to be inserted and interconnected without soldering.

Structure:

• Consists of many small holes into which electronic components can be inserted.
• The holes are electrically connected in rows and columns.

Usage: Breadboards are commonly used in IoT projects for testing and prototyping
circuits involving sensors, actuators, and microcontrollers. You can easily rearrange and
modify your circuit by plugging in or removing components.

04750404423 1 Deepanshi
3. Sensors

Function: Sensors detect and measure physical conditions (e.g., temperature, humidity,
light, motion) and convert them into electrical signals.

Types:

• Temperature Sensor (e.g., DHT11, DS18B20): Measures temperature. Common in


IoT systems for smart thermostats.
• Humidity Sensor (e.g., DHT22): Measures the amount of moisture in the air. Used
in agriculture IoT systems.
• Light Sensor (e.g., LDR): Measures the intensity of light. Used in smart lighting
systems.
• Motion Sensor (e.g., PIR Sensor): Detects movement and is commonly used in
security IoT systems.
• Gas Sensor (e.g., MQ2): Measures gas concentration in the air (like CO2 or
methane). Useful for air quality monitoring in IoT projects.

4. Actuators

Function: Actuators are devices that receive signals from the microcontroller and perform
a physical action, such as moving, heating, or emitting light.

Types:

• Servo Motors: Provide precise control of angular or linear position, velocity, and
acceleration. Used in robotics and smart home applications like automatic doors.
• DC Motors: Convert electrical energy into mechanical movement. Common in IoT
systems for creating moving parts or fans.
• LEDs: Emit light when powered. Used in IoT systems for indicators or smart
lighting.
• Buzzers: Produce sound or alarm when activated. Used in alarm systems.
04750404423 2 Deepanshi
• Relay Modules: Act as electrical switches, allowing IoT devices to control higher
power devices like home appliances.

04750404423 3 Deepanshi
EXPERIMENT 2
AIM: To understand the Arduino Board architecture and Raspberry Pi pin diagram and
architecture.

Arduino UNO

1. ATmega328 Microcontroller- It is a single chip Microcontroller of the ATmel family.


The processor code inside it is of 8-bit. It combines Memory (SRAM, EEPROM, and
Flash), Analog to Digital Converter, SPI serial ports, I/O lines, registers, timer, external
and internal interrupts, and oscillator.
2. ICSP pin - The In-Circuit Serial Programming pin allows the user to program using the
firmware of the Arduino board.

04750404423 4 Deepanshi
3. Power LED Indicator- The ON status of LED shows the power is activated. When the
power is OFF, the LED will not light up.
4. Digital I/O pins- The digital pins have the value HIGH or LOW. The pins numbered
from D0 to D13 are digital pins.
5. TX and RX LED's- The successful flow of data is represented by the lighting of these
LED's.
6. AREF- The Analog Reference (AREF) pin is used to feed a reference voltage to the
Arduino UNO board from the external power supply.
7. Reset button- It is used to add a Reset button to the connection.
8. USB- It allows the board to connect to the computer. It is essential for the
programming of the Arduino UNO board.
9. Crystal Oscillator- The Crystal oscillator has a frequency of 16MHz, which makes the
Arduino UNO a powerful board.
10. Voltage Regulator- The voltage regulator converts the input voltage to 5V.
11. GND- Ground pins. The ground pin acts as a pin with zero voltage.
12. Vin- It is the input voltage.
13. Analog Pins- The pins numbered from A0 to A5 are analog pins. The function of Analog
pins is to read the analog sensor used in the connection. It can also act as GPIO
(General Purpose Input Output) pins.

Raspberry Pi

04750404423 5 Deepanshi
Raspberry Pi mainly consists of the following blocks:

1. Processor: Raspberry Pi uses Broadcom BCM2835 system on chip which is an ARM


processor and Video core Graphics Processing Unit (GPU). It is the heart of the
Raspberry Pi which controls the operations of all the connected devices and handles
all the required computations.
2. HDMI: High-Definition Multimedia Interface is used for transmitting video or digital
audio data to a computer monitor or to digital TV. This HDMI port helps Raspberry Pi
to connect its signals to any digital device such as a monitor digital TV or display
through an HDMI cable.
3. GPIO ports: General Purpose Input Output ports are available on Raspberry Pi which
allows the user to interface various I/P devices.
4. Audio output: An audio connector is available for connecting audio output devices
such as headphones and speakers.
5. USB ports: This is a common port available for various peripherals such as a mouse,
keyboard, or any other I/P device. With the help of a USB port, the system can be
expanded by connecting more peripherals.
6. SD card: The SD card slot is available on Raspberry Pi. An SD card with an operating
system installed is required for booting the device.
7. Ethernet: The ethernet connector allows access to the wired network, it is available
only on the model B of Raspberry Pi.
8. Power supply: A micro USB power connector is available onto which a 5V power
supply can be connected.
9. Camera module: Camera Serial Interface (CSI) connects the Broadcom processor to
the Pi camera.
10. Display: Display Serial Interface (DSI) is used for connecting LCD to Raspberry Pi
using 15 15-pin ribbon cables. DSI provides a high-resolution display interface that is
specifically used for sending video data.

04750404423 6 Deepanshi
AIM:
EXPERIMENT 3
To understand the basic of Arduino IDE programming and Install IDE of Arduino.

The Arduino Integrated Development Environment (IDE) is a software application used


to write, compile, and upload code to Arduino boards. It provides a user-friendly interface
for programming Arduino microcontrollers.

Key features of the Arduino IDE:

• Text editor for writing code


• Message area for feedback
• Text console for output
• Toolbar with common functions
• Menu bar with additional options

Arduino IDE Installation:

1. Download the Arduino IDE:

• Visit the official Arduino website: https://www.arduino.cc/en/software


• Choose the appropriate version for your operating system (Windows, macOS,
or Linux)
• Click on the download link for the latest version

2. Install the Arduino IDE:

For Windows:

o Open the downloaded .exe file o Follow the installation wizard


instructions
o Choose the installation directory (default is usually fine)
o Select the components you want to install (leave all checked for a full
installation)
o Allow the installation of drivers when prompted

3. Launch the Arduino IDE:

• Open the Arduino IDE from your applications menu or desktop shortcut

4. Install board support (if needed):

• Go to Tools > Board > Boards Manager


• Search for and install support for your specific Arduino board if it's not already
included

5. Verify the installation:

04750404423 7 Deepanshi
• Connect your Arduino board to your computer via USB
• Select your board type from Tools > Board
• Select the correct port from Tools > Port
• Open an example sketch: File > Examples > 01. Basics > Blink
• Click the Upload button (right arrow icon) to compile and upload the sketch to
your board

Important Concepts:

a) Sketch structure:

• Every Arduino program (called a "sketch") has two main functions:


o setup(): Runs once when the board starts o
loop(): Runs repeatedly after setup

b) Common functions:
• pinMode(): Sets a pin as input or output
• digitalWrite(): Writes a HIGH or LOW value to a digital pin
• digitalRead(): Reads the value from a digital pin
• analogRead(): Reads the value from an analog pin • analogWrite(): Writes an
analog value to a pin

c) Variables and data types:

• int: Integer values


• float: Floating-point numbers
• boolean: True/false values • char: Single characters

d) Control structures:

• if, else if, else: Conditional statements


• for, while: Loops
• switch, case: Multiple choice decisions

04750404423 8 Deepanshi
AIM:

EXPERIMENT 4
Write steps to write program in Arduino and add libraries in Arduino and setup of
Arduino IDE for programming.

Steps to Write a Program in Arduino IDE and Add Libraries:

1. Setup the Arduino IDE for Programming:

a. Open the Arduino IDE:


b. Launch the Arduino IDE on your computer after installation.
c. Select the Arduino Board:
d. Go to the Tools menu, then Board, and select your Arduino model (e.g., Arduino
Uno).
e. Select the Port:
f. Under Tools, go to Port and select the port to which your Arduino is connected. It
will usually be labeled something like "COM3" (on Windows) or "/dev/ttyUSB0"
(on Linux/Mac).

2. Writing a Program in Arduino:

a. Understand the Arduino Sketch Structure: An Arduino program (called a sketch)


consists of two main functions:

• void setup(): This function runs once when the board is powered on or reset.
It is used to initialize settings (e.g., pin modes).
• void loop(): This function runs continuously and contains the main logic of the
program.

b. Write the Code:

04750404423 9 Deepanshi
• In the editor window, write your code. For example, to blink an LED, the code
would look like:

void setup() {
pinMode(13, OUTPUT); // Set pin 13 as an output
} void
loop() {
digitalWrite(13, HIGH); // Turn the LED on
delay(1000); // Wait for 1 second
digitalWrite(13, LOW); // Turn the LED off
delay(1000); // Wait for 1 second }

c. Verify the Code:

• After writing the code, click the Verify button (✓) at the top of the Arduino IDE.
This checks for any syntax errors in the code.

d. Upload the Code:

• Once the code is verified, click the Upload button (→) to upload the code to the
Arduino board. The board will run the program immediately after the upload.

3. Adding Libraries in Arduino IDE:

Libraries in Arduino provide additional functionalities, making it easier to interface with


sensors, motors, displays, etc.

1. Open Library Manager:

• In the Arduino IDE, go to Sketch > Include Library > Manage Libraries...

2. Search for the Library:

• In the Library Manager window, use the search bar to find the library you need
(e.g., "Adafruit Sensor").

3. Install the Library:

• Once you find the desired library, click Install. After installation, the library will
be available for use in your sketches.

4. Include the Library in Your Code:

• To use the library in your program, include it at the beginning of your code with
the #include statement. For example:

04750404423 10 Deepanshi
AIM:
#include <Adafruit_Sensor.h>

EXPERIMENT 5
Write a Program using Arduino for Blink LED.

Materials Required:

1. Arduino Board (e.g., Arduino Uno)


2. LED
3. Resistor (220Ω or 330Ω)
4. Breadboard
5. Jumper Wires
6. USB Cable (to connect Arduino to a computer)

Steps:

1. Circuit Setup:
o Connect the longer leg (anode) of the LED to digital pin 13 on the Arduino.
o Connect the shorter leg (cathode) to one end of a resistor.
o Connect the other end of the resistor to the GND pin on the Arduino.
2. Program to Blink the LED:
Open the Arduino IDE and write the following program:

void setup() {
// Initialize digital pin 13 as an output
pinMode(13, OUTPUT);
}
void loop() {
// Turn the LED on (HIGH voltage)
digitalWrite(13, HIGH);
delay(1000); // Wait for 1 second
// Turn the LED off (LOW voltage)
digitalWrite(13, LOW);
delay(1000); // Wait for 1 second
}

04750404423 11 Deepanshi
EXPERIMENT 6
AIM: To Demonstrate Autodesk Tinkercad Simulation Platform.

Autodesk Tinkercad is a free online 3D design and modeling tool that is widely used for
creating 3D models, circuits, and simulations. Tinkercad offers an easy-to-use interface
and is particularly useful for beginners and educators to prototype electronics and
develop Arduino projects without the need for physical components.

Key Features of Tinkercad:

1. Circuit Design: Allows users to create and simulate electronic circuits using virtual
components like resistors, LEDs, sensors, and microcontrollers.
2. Arduino Simulation: Users can write and test Arduino code in a simulated
environment, providing instant feedback without needing physical hardware.
3. 3D Design: Users can create 3D models and print them with 3D printers or use
them in other applications.
4. User-Friendly Interface: Intuitive drag-and-drop functionality makes it easy for
beginners to get started with electronics and 3D design.

04750404423 12 Deepanshi
AIM:

04750404423 13 Deepanshi
1. Accessing Tinkercad:

• Go to the Tinkercad website: https://www.tinkercad.com •


Sign up for a free account or log in if you already have one.

2. Creating a New Circuit Project:

a. Navigate to the Circuits Section:


o Once logged in, click on the “Circuits” option in the left sidebar.
b. Create a New Circuit: o Click on the “Create New Circuit” button.

3. Designing a Simple LED Circuit:

a. Adding Components:
o In the components panel on the right, search for and drag the following
components onto the work area:

• Arduino Uno
• LED
• Resistor (220Ω)
• Breadboard (optional for organization) • Jumper Wires

b. Connecting Components:
o Connect the components as follows:
• Connect the long leg (anode) of the LED to digital pin 13 of the
Arduino.
• Connect the short leg (cathode) of the LED to one end of the resistor.
• Connect the other end of the resistor to the GND of the Arduino. c.
Wiring Example: o The circuit should resemble a basic LED blink
circuit.

4. Programming the Arduino:


1. Open the Code Editor: o Click on the “Code” button at the top right corner
of the workspace.

04750404423 14 Deepanshi
2. Write Arduino Code:
o Use the following code to blink the LED:

int ledPin=8; //definition digital 8 pins as pin to control the


LED void setup()
{
pinMode(ledPin,OUTPUT); //Set the digital 8 port mode,
OUTPUT: Output mode
} void
loop() {
digitalWrite(ledPin,HIGH); //HIGH is set to about 5V PIN8
delay(1000); //Set the delay time, 1000 = 1S
digitalWrite(ledPin,LOW); //LOW is set to about 5V PIN8
delay(1000); //Set the delay time, 1000 = 1S }

EXPERIMENT 7
AIM: Controlling the Light Emitting Diode (LED) with a push button.

Materials Required:

1. Arduino Board (e.g., Arduino Uno)


2. Light Emitting Diode (LED)
3. Resistor (220Ω or 330Ω for the LED)
4. Push Button
5. Resistor (10kΩ for the push button, optional for pull-down configuration)
6. Breadboard
7. Jumper Wires
8. USB Cable (to connect Arduino to a computer)

Circuit Setup:
a. Connect the LED:

04750404423 15 Deepanshi
o Connect the longer leg (anode) of the LED to digital pin 9 on the Arduino.
o Connect the shorter leg (cathode) of the LED to one end of the 220Ω
resistor.
o Connect the other end of the resistor to the GND pin on the Arduino.
b. Connect the Push Button:
o Place the push button on the breadboard.
o Connect one terminal of the push button to digital pin 7 on the Arduino. o
Connect the other terminal of the push button to the GND pin on the
Arduino.
o (Optional) Connect a 10kΩ resistor from the same terminal (connected to
pin 7) to the +5V rail to create a pull-up configuration. This keeps the pin
HIGH when the button is not pressed.

// Pin Definitions
const int ledPin = 2; // LED connected to digital pin 9 const
int buttonPin = 3; // Push button connected to digital pin 7

// Variable to hold the button state int


buttonState = 0;

void setup() {
pinMode(ledPin, OUTPUT); // Set the LED pin as output
pinMode(buttonPin, INPUT); // Set the button pin as input
} void
loop() {
buttonState = digitalRead(buttonPin); // Read the state of the push
button

// Check if the button is pressed


if (buttonState == HIGH) {
digitalWrite(ledPin, HIGH); // Turn the LED on
} else {
digitalWrite(ledPin, LOW); // Turn the LED off
}
}

04750404423 16 Deepanshi
EXPERIMENT 8
AIM: Measure the Distance Using Ultrasonic Sensor and Make Led Blink Using Arduino

Materials Required:

1. Arduino Board (e.g., Arduino Uno)


2. Ultrasonic Sensor (HC-SR04)
3. Light Emitting Diode (LED)
4. Resistor (220Ω or 330Ω for the LED)
5. Breadboard
6. Jumper Wires
7. USB Cable (to connect Arduino to a computer)

Circuit Setup:

1. Ultrasonic Sensor (HC-SR04) Pin Configuration:


o VCC: Connect to the 5V pin on the Arduino. o GND: Connect to the
GND pin on the Arduino. o Trig: Connect to digital pin 11 on the Arduino.
o Echo: Connect to digital pin 10 on the Arduino.
2. LED Setup:
o Connect the longer leg (anode) of the LED to digital pin 13 on the Arduino.
o Connect the shorter leg (cathode) to one end of the 220Ω resistor. o
Connect the other end of the resistor to GND.

Circuit Diagram:

The connections should look as follows:

• HC-SR04 Sensor: o VCC → 5V


o GND → GND
o Trig → Digital Pin 11 o
Echo → Digital Pin
10
• LED:

04750404423 17 Deepanshi
o Anode → Digital Pin 13

o Cathode → Resistor → GND

Programming the Arduino:

#include <LiquidCrystal.h>
const int trigPin =
11; const int echoPin =
10;
long duration; int distance;
bool measured = false; int
maxReferenceHeight = 500; int
referenceHeight; int
maxHeight = 220; int
minHeight = 30;
const int rsPin = 2;
const int enablePin = 3;
const int data_4 = 4;
const int data_5 = 5;
const int data_6 = 6;
const int data_7 = 7;

LiquidCrystal lcd(rsPin, enablePin, data_4, data_5, data_6, data_7);


// 16*2 LCD Display | RS - 42, Enable - 44, Data - 46, 48, 50, 52 (R/W -
GND) void
setup() {
// put your setup code here, to run once:
lcd.begin(16, 2); lcd.clear();
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
} void loop() { if
(measured == false){
lcdInitialAlert();
clearTrigger();
triggerON(10);
distance = distanceMeasured();
printDistanceToLCD(distance); measured
= true;
}
} void clearTrigger(){ //
Clears the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
}
void triggerON(int MicroSeconds){
// Sets the trigPin on HIGH state for X micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(MicroSeconds); digitalWrite(trigPin,
LOW);
}

04750404423 18 Deepanshi
int distanceMeasured(){
// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH); // Calculating the distance
distance = duration*0.034/2; Serial.print("Distance: ");
Serial.println(distance);
return distance;
}
void printDistanceToLCD(int distance){
lcd.setCursor(0, 1);
lcd.print("Height : ");
lcd.print(distance); lcd.print("
cm");
} void lcdInitialAlert(){
lcd.clear(); lcd.setCursor(0,
0); lcd.print("Ready To
Measure"); delay(2000);
}

EXPERIMENT 9
AIM: Sense The Available Networks Using Arduino

To sense the available Wi-Fi networks using an Arduino, you can use an ESP8266 or
ESP32 microcontroller, which are Arduino-compatible and have built-in Wi-Fi
capabilities.

04750404423 19 Deepanshi
Hardware Required:

• ESP8266 NodeMCU or ESP32 development board.


• USB cable for connecting the board to your computer.
• Arduino IDE installed with ESP8266/ESP32 board support.

Steps:

1. Install ESP8266/ESP32 Support in Arduino IDE:


2. Open Arduino IDE, go to File > Preferences, and paste this URL in the "Additional
Board Manager URLs" field:
http://arduino.esp8266.com/stable/package_esp8266com_index.json for
ESP8266
or
https://dl.espressif.com/dl/package_esp32_index.json for ESP32

3. Go to Tools > Board > Boards Manager and search for ESP8266 or ESP32, then
click Install.
4. Connect ESP8266/ESP32 to your computer.

Code to Scan Wi-Fi Networks:

#include "ESP8266WiFi.h" // Use "WiFi.h" if using ESP32

void setup() {
Serial.begin(115200); // Start Serial communication for output
WiFi.mode(WIFI_STA); // Set WiFi mode to station (client)
WiFi.disconnect(); // Disconnect from any previous Wi-Fi delay(100);

Serial.println("Scanning for available Wi-Fi networks...");

int numberOfNetworks = WiFi.scanNetworks(); // Perform network scan

if (numberOfNetworks == 0) {
Serial.println("No networks found.");
} else {
Serial.println("Networks found: "); for
(int i = 0; i < numberOfNetworks; i++) {
// Print SSID and signal strength
Serial.print(i + 1);
Serial.print(": ");
Serial.print(WiFi.SSID(i));
Serial.print(" (Signal strength: ");
Serial.print(WiFi.RSSI(i));
Serial.println(" dBm)"); delay(10);
}
}
}
void loop() {
04750404423 20 Deepanshi
}

5. Upload the Code:

• Select the correct board and port: Go to Tools > Board and choose the
appropriate ESP8266/ESP32 board, and select the correct port under Tools >
Port.
• Upload the sketch to the board.

6. Monitor the Output:

• Open the Serial Monitor from Tools > Serial Monitor in Arduino IDE. Set the
baud rate to 115200 to see the available Wi-Fi networks along with their signal
strength.

EXPERIMENT 10
Aim: Write a program to blink multiple LEDs using: •
Without breadboard
• With breadboard.

Without a Breadboard (Direct Pin Connections)

Hardware Required:

04750404423 21 Deepanshi
• Arduino Uno or similar.
• Multiple LEDs (e.g., 3 LEDs).
• Resistors (220Ω or 330Ω) for each LED.
• Jumper wires.

Connections:

• LED Anode (+): Connect each LED's anode to a digital pin on the Arduino (e.g.,
pins 9, 10, 11).
• LED Cathode (-): Connect the cathode to a resistor, and the other end of the resistor
to GND.

Here is an example of how you would connect:

• LED 1 Anode to pin 9, cathode to GND via a resistor.


• LED 2 Anode to pin 10, cathode to GND via a resistor.
• LED 3 Anode to pin 11, cathode to GND via a resistor.

Code:

int led1 = 9; // Pin for LED 1 int


led2 = 10; // Pin for LED 2 int
led3 = 11; // Pin for LED 3
void setup() {
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
} void
loop() {
digitalWrite(led1, HIGH); // Turn LED 1 on
delay(500); // Wait for 500ms
digitalWrite(led1, LOW); // Turn LED 1 off
digitalWrite(led2, HIGH); // Turn LED 2 on
delay(500); digitalWrite(led2, LOW);
digitalWrite(led3, HIGH); // Turn LED 3 on
delay(500);
digitalWrite(led3, LOW);
}

04750404423 22 Deepanshi
With a Breadboard

Hardware Required:

• Arduino Uno or similar.


• Multiple LEDs (e.g., 3 LEDs).
• Resistors (220Ω or 330Ω) for each LED.
• Breadboard.
• Jumper wires.

Connections:

• Place the LEDs on the breadboard.


• Connect the anode (+) of each LED to different digital pins on the Arduino (e.g.,
pins 9, 10, 11) via jumper wires.
• Connect the cathode (-) of each LED to one end of a resistor.
• Connect the other end of each resistor to the GND rail of the breadboard.
• Connect the GND rail of the breadboard to the Arduino's GND pin.

Code:

int led1 = 9; // Pin for LED 1 int


led2 = 10; // Pin for LED 2 int
led3 = 11; // Pin for LED 3
void setup() {
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
} void
loop() {
digitalWrite(led1, HIGH); // Turn LED 1 on

04750404423 23 Deepanshi
delay(500); // Wait for 500ms
digitalWrite(led1, LOW); // Turn LED 1 off

digitalWrite(led2, HIGH); // Turn LED 2 on


delay(500);
digitalWrite(led2, LOW);

digitalWrite(led3, HIGH); // Turn LED 3 on


delay(500);
digitalWrite(led3, LOW);
}

04750404423 24 Deepanshi
AIM:
EXPERIMENT 11
Interface DHT11 Sensor for temperature and humidity monitoring.

The DHT11 sensor is commonly used to measure temperature and humidity.

Hardware Required:

• Arduino Uno or similar


• DHT11 temperature and humidity sensor
• Resistor (10kΩ)
• Jumper wires
• Breadboard (optional) DHT11 Sensor Pinout:

• VCC: Power (3.3V to 5V)


• Data: Data pin (to be connected to an Arduino digital pin)
• GND: Ground

Circuit Connections:

1. Connect the VCC pin of the DHT11 to the 5V pin on the Arduino.
2. Connect the GND pin of the DHT11 to the GND of the Arduino.
3. Connect the Data pin of the DHT11 to digital pin 2 of the Arduino.
4. (Optional) Place a 10kΩ pull-up resistor between the Data pin and VCC to stabilize
the signal.

Code:

To use the DHT11, you need to install the DHT sensor library. Follow these steps:

1. Open Arduino IDE.


2. Go to Sketch > Include Library > Manage Libraries.
3. In the Library Manager, search for DHT sensor library, and install the one by
Adafruit.

#include "DHT.h"

#define DHTPIN 2 // Pin connected to the Data pin of DHT11


#define DHTTYPE DHT11 // DHT11 sensor type

DHT dht(DHTPIN, DHTTYPE);

void setup() {
Serial.begin(9600); dht.begin();
} void
loop() { //
Wait a few
seconds

04750404423 25 Deepanshi
between
measurements
delay(2000);

// Read humidity (in %)


float humidity = dht.readHumidity();

// Read temperature in Celsius (the default)


float temperature = dht.readTemperature();

// Check if any reads failed


if (isnan(humidity) || isnan(temperature)) {
Serial.println("Failed to read from DHT sensor!"); return;
}

// Print the results to the Serial Monitor


Serial.print("Humidity: ");
Serial.print(humidity);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" °C");
}

EXPERIMENT 12
Write a program to blink an LED based on input from a PIR motion sensor.

Hardware Required:

• Arduino Uno or similar


• PIR motion sensor

04750404423 26 Deepanshi
AIM:
• LED
• Resistor (220Ω or 330Ω)
• Jumper wires
• Breadboard (optional)

PIR Sensor Pinout:

• VCC: Power (3.3V to 5V)


• OUT: Output pin (connect to Arduino digital pin)
• GND: Ground

Circuit Connections:

1. PIR sensor:
o Connect the VCC pin of the PIR sensor to the 5V pin on the Arduino. o
Connect the GND pin of the PIR sensor to the GND of the Arduino.
o Connect the OUT pin of the PIR sensor to digital pin 2 of the Arduino.
2. LED:
o Connect the anode (+) of the LED to digital pin 13 of the Arduino. o
Connect the cathode (-) of the LED to a 220Ω resistor, and the other
end of the resistor to GND.

Code:

int pirPin = 2; // PIR sensor output pin connected to digital pin 2 int
ledPin = 13; // LED pin connected to digital pin 13
void setup()
{
pinMode(pirPin, INPUT); // Set PIR pin as input
pinMode(ledPin, OUTPUT); // Set LED pin as output
Serial.begin(9600); // Start the serial communication
} void
loop() {
int pirState = digitalRead(pirPin); // Read the state of the PIR sensor

if (pirState == HIGH) { // Motion detected


Serial.println("Motion detected!");

// Blink the LED 3 times


for (int i = 0; i < 3; i++) {
digitalWrite(ledPin, HIGH); // Turn LED on
delay(500); // Wait 500ms
digitalWrite(ledPin, LOW); // Turn LED off
delay(500); // Wait 500ms
}
} else {
Serial.println("No motion");
digitalWrite(ledPin, LOW); // Keep LED off if no motion detected

04750404423 27 Deepanshi
}
delay(1000); // Wait for 1 second before checking the sensor again }

04750404423 28 Deepanshi
AIM:
EXPERIMENT 13
Interface Three LEDs with an Ultrasonic Sensor to display proximity-based actions.

Hardware Required:

• Arduino Uno or similar


• HC-SR04 Ultrasonic Sensor
• 3 LEDs (Red, Yellow, Green)
• 3 Resistors (220Ω)
• Jumper wires
• Breadboard (optional)

Ultrasonic Sensor Pinout:

• VCC: Connect to Arduino 5V


• Trig: Trigger pin (connect to digital pin 9)
• Echo: Echo pin (connect to digital pin 8)
• GND: Ground

Circuit Connections:

1. Ultrasonic Sensor:
o VCC to 5V on Arduino o GND to GND on Arduino
o Trig to digital pin 9 on Arduino o Echo to
digital pin 8 on Arduino
2. LEDs:
o Green LED:
▪ Anode (+) to digital pin 3
▪ Cathode (-) to GND (via a 220Ω resistor) o Yellow
LED:
▪ Anode (+) to digital pin 4
▪ Cathode (-) to GND (via a 220Ω resistor) o Red LED:
▪ Anode (+) to digital pin 5
▪ Cathode (-) to GND (via a 220Ω resistor)

Working Logic:

• Green LED: Lights up if the object is far (e.g., distance > 100 cm).
• Yellow LED: Lights up if the object is at a moderate distance (e.g., between 50 cm
and 100 cm).
• Red LED: Lights up if the object is close (e.g., distance < 50 cm). Code:

const int trigPin = 9; // Trigger pin of Ultrasonic Sensor const


int echoPin = 8; // Echo pin of Ultrasonic Sensor const int
greenLED = 3; // Green LED pin const int yellowLED = 4;// Yellow

04750404423 29 Deepanshi
LED pin const int redLED = 5; // Red LED pin long duration; int
distance;

void setup() {
pinMode(trigPin, OUTPUT); // Set trigPin as output
pinMode(echoPin, INPUT); // Set echoPin as input pinMode(greenLED,
OUTPUT); // Set green LED as output pinMode(yellowLED, OUTPUT);//
Set yellow LED as output pinMode(redLED, OUTPUT); // Set red LED
as output Serial.begin(9600); // Start the serial
communication
}
void loop() { // Clear the
trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Send a 10 microsecond pulse to trigger the sensor
digitalWrite(trigPin, HIGH); delayMicroseconds(10);
digitalWrite(trigPin, LOW);

// Read the echoPin, which gives the time in microseconds


duration = pulseIn(echoPin, HIGH);

// Calculate the distance (Speed of sound = 34300 cm/s, divide by 2 to


get one-way)
distance = duration * 0.034 / 2;
// Display the distance on the serial monitor
Serial.print("Distance: ");
Serial.print(distance);
Serial.println(" cm");

// Proximity-based actions
if (distance > 100) {
digitalWrite(greenLED, HIGH); // Object is far
digitalWrite(yellowLED, LOW); digitalWrite(redLED,
LOW);
}
else if (distance <= 100 && distance > 50) {
digitalWrite(greenLED, LOW);
digitalWrite(yellowLED, HIGH); // Object is moderately close
digitalWrite(redLED, LOW);
}
else if (distance <= 50) {
digitalWrite(greenLED, LOW);
digitalWrite(yellowLED, LOW);
digitalWrite(redLED, HIGH); // Object is very close
}
delay(500); // Wait for 500ms before the next measurement
}

04750404423 30 Deepanshi
EXPERIMENT 14
AIM: Write down the steps to demonstrate the setup of Blynk app using Node MCU
(ESP8266).

Here’re the following steps to demonstrate the setup of Blynk app using Node MCU -: a)

Go to the Blynk Cloud

04750404423 31 Deepanshi
b) Login and Create an Account if you don’t have one.

Go to developer zone then create a template

c) Write Name (with default board to be NodeMCUESP32), then Done.

04750404423 32 Deepanshi
d) A template ID and Template name will be generated

e) Create a Datastream From Datastream Tab and set the pins

04750404423 33 Deepanshi
f) Now create a Web dashboard from tab & Add widget from widget box by drag & drop

g) Now go to Setting of Widget added and set the datastream to that and save

h) Final Layout

04750404423 34 Deepanshi
04750404423 35 Deepanshi
EXPERIMENT 15
AIM: Write a program for controlling LED on/off using Blynk app.

Here’s a simple Arduino program that demonstrates how to control an LED using the
Blynk app and NodeMCU (ESP8266). The program will allow you to toggle an LED on or
off from your smartphone through the Blynk app.

Hardware Required:

• NodeMCU (ESP8266)
• LED
• Resistor (220Ω)
• Breadboard and jumper wires (optional)

Circuit Connections:

1. LED:
o Anode (long leg) connected to D2 (GPIO4) on NodeMCU.
o Cathode (short leg) connected to GND via a 220Ω resistor.

Steps:

1. Install the Blynk app on your smartphone (refer to previous instructions).


2. Create a new project on Blynk and select ESP8266 as the hardware.
3. Add a Button widget in the app and link it to Virtual Pin V1 (configured as a
switch).
4. Copy the auth token provided by Blynk and paste it into the code below.

Code:

#include <ESP8266WiFi.h> #include


<BlynkSimpleEsp8266.h> char auth[] = "Your
Authentication Token"; char ssid[] = "Your
Wi-Fi SSID"; char pass[] = "Your Wi-Fi
Password"; void setup()
{
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
pinMode(D1,OUTPUT);
} void
loop()
{
Blynk.run();
}
BLYNK_WRITE(V1)
{ int pinValue = param.asInt();
if (pinValue == 1)
{ digitalWrite(D1, HIGH);

04750404423 36 Deepanshi
}
else
{ digitalWrite(D1, LOW);
}
}

How to Test:

1. Upload the code to your NodeMCU using the Arduino IDE.


2. Open the Blynk app on your phone and press the button widget to control the LED.
o When you press the button in the app, the LED will turn on. o
Releasing the button will turn the LED off.

04750404423 37 Deepanshi

You might also like