0% found this document useful (0 votes)
119 views78 pages

Iot Lab Manual

Uploaded by

capitalistvishnu
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)
119 views78 pages

Iot Lab Manual

Uploaded by

capitalistvishnu
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/ 78

Rajiv Gandhi University of Knowledge Technologies-A

Srikakulam

IoT LAB MANUAL


E2 SEM-1

Department Of Electronics and Communication Engineering 1


Department Of Electronics and Communication Engineering 2
Department Of Electronics and Communication Engineering 3
PREFACE
• Introduction to Internet of Things (IoT):
The Internet of Things (IoT) represents a network of interconnected
devices infused with sensors, software, and other technologies,
facilitating data collection and exchange. IoT has emerged as a
transformative force, reshaping various industries and daily routines,
fostering novel interactions with technology and the environment.

Uses of IoT:
IoT's utility extends across diverse sectors:
• Smart Home Automation: IoT empowers homeowners to remotely
manage appliances, lighting, security systems, and climate control.
• Industrial IoT (IoT): Industries leverage IoT for predictive maintenance,
real-time equipment monitoring, inventory tracking, and supply chain
optimization.
• Healthcare: IoT facilitates remote patient monitoring, smart medical
devices, medication adherence tracking, and personalized healthcare
solutions.
• Smart Cities: Urban landscapes benefit from IoT through enhanced
infrastructure, traffic management, waste management, environmental
monitoring, and public safety measures.

➢ EXPERIMENT DESCRIPTIONS:
✓ Getting Started with IoT Devices
o Overview: This experiment introduces configuring IoT devices,
gathering sensor data transmitting it to the cloud, and visualizing it
through a dashboard.

Department Of Electronics and Communication Engineering 4


✓ IoT Application Development with Particle Hardware
o Overview: we delve into IoT application development using
Particle hardware, including platform exploration, code
composition, deployment, and testing on Particle devices.
✓ Exploring Arduino Board and IDE
o Overview: Learners navigate Arduino board setup, IDE usage,
sketch composition, code verification, upload, and customization.
✓ Interfacing Sensors and Displays with Arduino
o Overview: Participants delve into sensor types, circuit
connectivity, sketching for sensor data retrieval, and interfacing
displays for practical applications.
✓ Introduction to Bluetooth Communication
o Overview: This experiment acquaints with Bluetooth modules,
establishing one-way and two-way communication between
Arduino boards, and wireless LED control.
✓ Introduction to Wi-Fi Communication
o Overview: we explore Wi-Fi module integration, local network
device control, and practical implications of Wi-Fi-enabled
Arduino projects.

Department Of Electronics and Communication Engineering 5


➢ SOME BASIC SENSORS

1) IR Sensor: An IR sensor detects infrared radiation emitted or reflected by


objects in its field of view. It is commonly used for proximity sensing,
object detection, and motion detection in applications such as security
systems, automated lighting, and obstacle detection in robotics.

2) Ultrasonic Sensor: An ultrasonic sensor uses ultrasonic waves to


measure distance to an object by emitting high-frequency sound waves
and calculating the time it takes for the waves to bounce back. It is widely
used for proximity sensing, object detection, and navigation in robotics,
smart parking systems, and industrial automation.

3) PIR Sensor: A PIR sensor detects changes in infrared radiation caused by


the movement of objects or living beings within its detection range. It is
commonly used for motion detection in security systems, automatic
lighting, and energy-saving applications.

4) Servo Motor: A servo motor is a rotary actuator that allows precise


control of angular position. It is commonly used in IoT projects for
controlling the position of mechanical devices such as robotic arms,
camera gimbals, and remote-controlled vehicles

5) Arduino Microcontroller: Arduino is an open-source electronics


platform based on easy-to-use hardware and software. Arduino boards
are equipped with digital and Analog input/output pins that can be
programmed to interface with sensors, control actuators, and
communicate with other devices.

Department Of Electronics and Communication Engineering 6


6) NodeMCU (ESP8266) Development Board: NodeMCU is a low-cost
open-source IoT platform based on the ESP8266 Wi-Fi module. It
provides built-in Wi-Fi connectivity, making it suitable for IoT projects
that require wireless communication and internet connectivity.

➢ Arduino:
• Arduino is an open-source electronics platform that allows you to create
interactive projects.
• It consists of a microcontroller (usually an ATMega chip) and a
development environment for writing and uploading code. With
Arduino, you can build various electronic devices, from simple LED
blinkers to complex robots.

➢ Wokwi:
• Wokwi is an online Arduino and ESP32 simulator.
• It’s designed for makers by makers and provides a virtual environment
where you can test your Arduino code without needing physical
hardware. Wokwi supports various Arduino boards, including Uno,
Mega, ESP32, and even Raspberry Pi Pico. You can create circuits,
connect components, and simulate interactions—all within your web
browser.

➢ Tinkercad:
• Tinkercad is another popular platform for electronics and 3D design.
• It’s user-friendly and offers a free, easy-to-use app for creating 3D
models, designing circuits, and coding.

Department Of Electronics and Communication Engineering 7


• While Tinkercad is great for beginners, it has limitations—for example,
it doesn’t fully support all Arduino board types like the Nano or Mega1.
Still, it’s an excellent starting point for learning and experimenting.

➢ Installing Arduino IDE on Ubuntu and Windows:


✓ Ubuntu:
• To install the Arduino IDE on Ubuntu, follow these steps:
Step1: Download the Arduino IDE:
• Visit the official Arduino download page and choose the appropriate
version (32-bit or 64-bit) for your system.
• Download the ZIP file.
Step2: Extract the Archive:
• Right-click on the downloaded ZIP file and select “Extract” to unzip
the contents.
• Choose a suitable location for the extracted files (e.g., your home
folder).
Step3: Launch Arduino IDE:
• Navigate to the extracted folder.
• Double-click on the arduino-ide file to start the application.
That’s it! You’re all set to write and upload code to your Arduino board
using the Arduino IDE

➢ Windows:
Download the IDE:

Department Of Electronics and Communication Engineering 8


• Visit the Arduino website and download the Windows installer (.exe
file).
• Double-click the downloaded file to start the installation process.
• Follow the instructions in the installation guide

Department Of Electronics and Communication Engineering 9


Table of Contents
Serial Number Topic Name Page Number

1 Blinking an LED Using Arduino. 10-14

2 Traffic Light Simulation using Arduino. 14-19

3 Relay Interfaced with Arduino. 20-25

4 Smart Street Light using LDR and Arduino. 26-30

5 Sound Sensing using Sound Sensor with Arduino 30-34


Soil Moisture Detection using Soil Moisture
6 Sensor and Displaying in Serial Monitor. 35-38

Arduino Interfacing with Servo Motor


7 39-42
Distance Measurement with Ultrasonic Sensor
and Display on LCD using Arduino with I2C
8 Interface. 43-49

9 RFID 50-54

LED Control using Bluetooth Module with


10 Arduino. 54-59

Sending Data from Smartphone to Arduino using


11 Bluetooth Module. 60-64
LED Controlling with WiFi Module and Web Page
12 Interface. 65-71
Temperature and Humidity Monitoring with WiFi
Module and
13 Web Page Interface. 72-78

Department Of Electronics and Communication Engineering 10


Experiment:1
Arduino Interfacing with Single LED

1. Experiment Title
• Blinking an LED Using Arduino

2. Objective
• To learn how to interface an LED with an Arduino board and make it
blink using simple code.

3. Materials Required
Hardware Components
• Arduino Uno board
• LED
• Resistor (220Ω)-(optional)
• Breadboard
• Jumper wires

Software Tools and Libraries


• Arduino IDE

4. Circuit Diagram

Department Of Electronics and Communication Engineering 11


Visual Representation

Explanation of Connections
• Connect the anode (long leg) of the LED to digital pin 13 on the Arduino.
• Connect the cathode (short leg) of the LED to one end of the resistor.
• Connect the other end of the resistor to the GND pin on the Arduino.

5. Step-by-Step Instructions

Step 1: Setting Up the Hardware


• Place the LED on the breadboard.
• Connect the anode of the LED to pin 13 on the Arduino using a jumper
wire.
• Connect the cathode of the LED to one end of the resistor.
• Connect the other end of the resistor to the GND pin on the Arduino.

Step 2: Writing the Code

//cpp
//Copy code
// Define the LED pin
const int LEDpin = 13;

void setup() {
// Initialize the digital pin as an output

Department Of Electronics and Communication Engineering 12


pinMode(LEDpin, OUTPUT);
}

void loop() {
digitalWrite(LEDpin, HIGH); // Turn the LED on
delay(1000); // Wait for a second
digitalWrite(LEDpin, LOW); // Turn the LED off
delay(1000); // Wait for a second
}

• Key Functions:
• pinMode(): Configures the specified pin to behave as an input or an
output.
• digitalWrite(): Writes a HIGH or LOW value to a digital pin.
• delay(): Pauses the program for the amount of time (in milliseconds)
specified as parameter.
Step 3: Uploading the Code
• Connect the Arduino to your computer using a USB cable.
• Open the Arduino IDE and paste the code.
• Select the correct board and port from the Tools menu.
• Click the Upload button to transfer the code to the Arduino.

Step 4: Running the Experiment


• After the code is uploaded, the LED should start blinking, turning on and
off every second.

6. Data Collection and Analysis


• For this basic experiment, data collection is not required. However, you
can observe the LED's blinking pattern to ensure it matches the code.

7. Expected Results
• The LED will turn on for one second and then turn off for one second,
repeatedly.

8. Troubleshooting

Department Of Electronics and Communication Engineering 13


• LED not blinking: Check the connections, ensure the LED is not damaged,
and verify the code is correctly uploaded.
• Arduino not detected: Ensure the USB cable is properly connected and
the correct port is selected in the Arduino IDE.
9. Extensions and Modifications
• Change Blinking Pattern: Modify the delay values in the code to change
the LED's blinking speed.
• Multiple LEDs: Add more LEDs to different pins and control them with
separate code sections.

10. Conclusion
• This experiment teaches the basics of interfacing an LED with an Arduino
and controlling it using simple code. It lays the foundation for more complex
projects involving sensors and actuators.

11.Applications
• Status Indicators:
Use LEDs to show the status of a process or system (e.g.,
power on/off, error states).
• Communication:
Implement simple visual communication between devices or
systems using blinking patterns.

12. References
• Robotics Backend - Arduino LED Tutorial
• Robocraze - Interfacing LED with Arduino Complete Guide
• GeeksforGeeks - LED Blinking Using Arduino
• Arduino Documentation - Blink
• Instructables - Blink an LED With Digital Output
• Srituhobby - How to Blink an LED Bulb Using Arduino

Department Of Electronics and Communication Engineering 14


Experiment:2
Arduino Interfacing with Multiple LEDs

Experiment: Traffic Light Simulation using Arduino


1. Experiment Title
• Traffic Light Simulation using Arduino
2. Objective
• Simulate a basic traffic light system using Arduino to control the
sequence of traffic lights: red, yellow, and green.

3. Materials Required
Hardware Components:
• Arduino Uno
• 3 LEDs (Red, Yellow, Green)
• Resistors (220 ohms)-(optional)
• Breadboard
• Jumper wires
• USB cable
Software Tools and Libraries:
• Arduino IDE

Department Of Electronics and Communication Engineering 15


4. Circuit Diagram

Connections:
Red LED:
• Anode (+) to Digital Pin 8 on Arduino
• Cathode (-) through 220-ohm resistor to GND
Yellow LED:
• Anode (+) to Digital Pin 9 on Arduino
• Cathode (-) through 220-ohm resistor to GND

Green LED:
• Anode (+) to Digital Pin 10 on Arduino
• Cathode (-) through 220-ohm resistor to GND
5. Step-by-Step Instructions
Step 1: Setting Up the Hardware
• Place the LEDs (Red, Yellow, Green) on the breadboard.
• Connect the anode (+) of the Red LED to Digital Pin 8, Yellow LED to
Digital Pin 9, and Green LED to Digital Pin 10 on the Arduino.

Department Of Electronics and Communication Engineering 16


• Connect the cathode (-) of each LED through a 220-ohm resistor to the
GND rail on the breadboard.
Step 2: Writing the Code
• Open the Arduino IDE.
//cpp
//Copy code
void setup() {
pinMode(8, OUTPUT); // Red LED
pinMode(9, OUTPUT); // Yellow LED
pinMode(10, OUTPUT); // Green LED
}
void loop() {
// Red light (Stop)
digitalWrite(8, HIGH);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
delay(5000); // 5 seconds delay

// Red and Yellow lights (Prepare to go)


digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
digitalWrite(10, LOW);
delay(2000); // 2 seconds delay

// Green light (Go)


digitalWrite(8, LOW);

Department Of Electronics and Communication Engineering 17


digitalWrite(9, LOW);
digitalWrite(10, HIGH);
delay(5000); // 5 seconds delay

// Yellow light (Prepare to stop)


digitalWrite(8, LOW);
digitalWrite(9, HIGH);
digitalWrite(10, LOW);
delay(2000); // 2 seconds delay
}

Step 3: Uploading the Code


• Connect the Arduino to your computer using a USB cable.
• Select the correct board and port in the Arduino IDE under Tools >
Board > Arduino Uno and Tools > Port > select the appropriate port.
• Click on the upload button to upload the code to the Arduino.
Step 4: Running the Experiment
• Once the code is uploaded, the traffic light simulation will start
automatically.
• Observe the LEDs on the breadboard to see the traffic light sequence:
Red, Red-Yellow, Green, Yellow.
6. Data Collection and Analysis
• No data collection is required for this experiment.

Department Of Electronics and Communication Engineering 18


7. Expected Results
• The LEDs should simulate a typical traffic light sequence: Red for 5
seconds, Red-Yellow for 2 seconds, Green for 5 seconds, Yellow for 2
seconds, and repeat.
8. Troubleshooting
• LEDs not lighting up:
• Check the connections of LEDs and resistors.
• Ensure correct pin numbers in the code match physical connections.
9. Extensions and Modifications
Pedestrian Crossing Signal:
Add a pedestrian LED that turns on during the red light phase.
Traffic Density Simulation:
Introduce a button or sensor to simulate traffic density affecting light
timings.
Advanced Traffic Management:
Implement traffic light synchronization for multiple intersections.
10. Conclusion
Successfully simulated a traffic light system using Arduino, understanding
basic control of LEDs and timing sequences.
Gained practical knowledge of Arduino programming for simulating real-
world systems.
Explored applications of traffic management and signal control systems in
urban planning and smart city initiatives.
11. Applications
Traffic Management:

Department Of Electronics and Communication Engineering 19


• Use in educational simulations for traffic engineering and management
studies.
Smart Cities:
• Implement as part of smart city infrastructure for efficient traffic flow
and management.
Education and Training:
• Demonstrate principles of traffic light control and urban planning in
educational settings.
12. References
• Arduino Documentation
• Traffic Light Control Systems literature and educational resources.

Experiment:3
Relay Interfaced with Arduino

Experiment: Relay Interfaced with Arduino


1. Experiment Title
• Relay Interfaced with Arduino

Department Of Electronics and Communication Engineering 20


2. Objective
• To control a relay module using Arduino and demonstrate its
application in switching electrical devices.
3. Materials Required
Hardware Components:
• Arduino Uno
• Relay Module
• LED (for indication)
• Breadboard
• Jumper wires
• USB cable
• Software Tools Required:
Arduino IDE

Department Of Electronics and Communication Engineering 21


4. Circuit Diagram
Circuit Diagram:

• Connect the components as shown in the circuit diagram:


Connections:
• Relay Module: VCC to 5V
• GND to GND
• IN to Digital Pin 8

LED (Optional): Anode to Digital Pin 9 (through a current-limiting
resistor)
• Anode to Digital Pin 9 (through a current-limiting resistor)
• Cathode to GND
5. Step-by-Step Instructions
Step 1: Setting Up the Hardware

Department Of Electronics and Communication Engineering 22


• Connect the relay module and LED to the Arduino as per the circuit
diagram.
Step 2: Writing the Code
Write the Arduino code to control the relay module:
//Copy code

int relayPin =8;


int ledPin=9;
void setup()
{
pinMode(relayPin,OUTPUT);
pinMode(ledPin,OUTPUT);
digitalWrite(relayPin,LOW);
//Ensure relay is off at startup
}
void loop()
{
digitalWrite(relayPin,HIGH);
//Turn relay on
digitalWrite(ledpin,HIGH);
//turn LED on
delay(5000);
//Keep relay on for 5 seconds
digitalWrite(relayPin,LOW);
//Turn relay off
digitalWrite(ledPin,LOW);

Department Of Electronics and Communication Engineering 23


//Turn LED off
delay(5000);
//Keep relay off for 5 seconds
}

Step 3: Uploading the Code


• Connect the Arduino to your computer using a USB cable.
• Select the correct board and port in the Arduino IDE under Tools >
Board > Arduino Uno and Tools > Port > select the appropriate port.
• Click on the upload button to upload the code to the Arduino.
Step 4: Testing the Circuit
• Once the code is uploaded, observe the relay and LED turning on and
off in 5-second intervals.

6. Data Collection and Analysis


• Monitor the behavior of the relay and LED to ensure proper switching.
• Verify the relay operation by connecting a low-power device or
indicator to the relay output.
7. Expected Results
• The relay and LED should turn on and off at 5-second intervals,
demonstrating the control of an external device using Arduino.
8. Troubleshooting
Relay Issues:

Department Of Electronics and Communication Engineering 24


• Check the wiring connections and ensure they match the circuit
diagram.
• Verify the relay module specifications and compatibility with Arduino.
• Code Issues:
• Ensure the correct pin numbers are used in the code. Debug any issues
using Serial Monitor output.

9. Extensions and Modifications


• Remote Control: Implement remote control of the relay using Bluetooth
or WiFi modules.
• Multiple Relays: Expand the project to control multiple relays for
advanced applications.
• Sensor Integration: Use sensors to trigger the relay based on
environmental conditions (e.g., temperature, light).
10. Conclusion
• Successfully interfaced a relay module with Arduino to control an
external device.
• Demonstrated the use of Arduino for switching applications in various
projects.
• Explored potential applications in home automation and industrial
control.
11. Applications

• Home Automation: Control lights, fans, and other appliances remotely.


• Industrial Control: Manage machinery and equipment in an industrial
setup.

Department Of Electronics and Communication Engineering 25


• Security Systems: Activate alarms or other security devices based on
sensor input.
12. References
• Arduino Documentation and Resources
• Relay Module datasheet and related documentation

Experiment:4
SERVO MOTOR Interfaced with Arduino

Interfacing an Arduino with a servo motor


Experiment Outline
1. Experiment Title
• Arduino Interfacing with Servo Motor

2. Objective
• Control a servo motor using Arduino to demonstrate motor rotation
based on input signals.

Department Of Electronics and Communication Engineering 26


3. Materials Required
Hardware Components:
• Arduino Uno
• Servo Motor (e.g., SG90)
• Jumper wires
• USB cable
• Software Tools and Libraries:
• Arduino IDE

4. Circuit Diagram:

• Connect the control wire (usually orange or yellow) of the servo motor
to Arduino Digital Pin 9.

Department Of Electronics and Communication Engineering 27


• Connect the power (red) and ground (black or brown) wires of the
servo motor to Arduino 5V and GND respectively.
5. Step-by-Step Instructions
Step 1: Setting Up the Hardware
Connect the servo motor to the Arduino as per the circuit diagram.
Step 2: Writing the Code
arduino
Copy code
#include <Servo.h>
Servo myServo; // Create a servo object
void setup() {
myServo.attach(9); // Attach the servo to digital pin 9
}
void loop() {
// Sweep the servo from 0 to 180 degrees
for (int pos = 0; pos <= 180; pos += 1) {
myServo.write(pos); // Set the servo position
delay(15); // Wait for the servo to reach the position
}
delay(1000); // Wait for a second

// Sweep the servo from 180 to 0 degrees


for (int pos = 180; pos >= 0; pos -= 1) {
myServo.write(pos); // Set the servo position

Department Of Electronics and Communication Engineering 28


delay(15); // Wait for the servo to reach the position
}
delay(1000); // Wait for a second
}

Step 3: Uploading the Code


Connect the Arduino to your computer using a USB cable.
Select the correct board and port in the Arduino IDE.
Click on the upload button to upload the code to the Arduino.
Step 4: Running the Experiment
Observe the servo motor sweeping back and forth between 0 to
180 degrees.
6. Data Collection and Analysis
• Observe the servo motor's movement and behavior.
• Measure angles if needed using a protractor or other angle
measurement tool.
7. Expected Results
• The servo motor should smoothly sweep from 0 to 180 degrees and
back repeatedly.
8. Troubleshooting
• Ensure the servo motor is correctly powered and connected to the
Arduino.
• Check servo library inclusion (#include <Servo.h>) and servo pin
assignment (myServo.attach(9);).
9. Extensions and Modifications

Department Of Electronics and Communication Engineering 29


• Experiment with different angle ranges and sweep speeds.
• Control the servo motor based on sensor inputs (e.g., potentiometer,
light sensor).
10. Conclusion
• Successfully interfaced a servo motor with Arduino and controlled
its movement.
• Gained understanding of servo motor control using Arduino and
servo library.
11. Applications
• Robotics and Automation
• Remote Control Systems
• Camera and Gimbal Stabilization
12. References
• Arduino Documentation
• Servo motor datasheets and resources on motor control

Experiment:5

Arduino Interfacing with LDR

Experiment: Smart Street Light using LDR and Arduino


1. Experiment Title
• Smart Street Light using LDR and Arduino
Department Of Electronics and Communication Engineering 30
2. Objective
• Create a smart light system that automatically turns on when it gets dark
using an LDR (Light Dependent Resistor) and Arduino.
3. Materials Required
Hardware Components:
• Arduino Uno
• LDR (Light Dependent Resistor)
• LED
• Resistor (220 ohms for LED, 10k ohms for LDR)
• Breadboard
• Jumper wires
• USB cable
Software Tools and Libraries:
• Arduino IDE
4. Circuit Diagram

Connections:
LDR:
• One leg to 5V on Arduino
• Other leg to A0 (analog pin) on Arduino through a 10k ohm resistor
• Connect the junction of LDR and resistor to GND on Arduino

Department Of Electronics and Communication Engineering 31


LED:
• Anode (long leg) to Digital Pin 13 on Arduino through a 220-ohm resistor
• Cathode (short leg) to GND on Arduino
5. Step-by-Step Instructions
Step 1: Setting Up the Hardware
• Place the LDR and the resistors on the breadboard.
• Connect one leg of the LDR to 5V on the Arduino.
• Connect the other leg of the LDR to A0 on the Arduino through a 10k ohm
resistor.
• Connect the junction of the LDR and resistor to GND on the Arduino.
• Connect the anode (long leg) of the LED to Digital Pin 13 on the Arduino through
a 220-ohm resistor.
• Connect the cathode (short leg) of the LED to GND on the Arduino.
Step 2: Writing the Code
• Open the Arduino IDE.
//Copy code
int ledPin = 13; // LED connected to digital pin 13
int ldrPin = A0; // LDR connected to analog pin A0
int ldrValue = 0; // Variable to store the value from the LDR
void setup() {
pinMode(ledPin, OUTPUT); // Set the LED pin as output
Serial.begin(9600); // Begin serial communication for debugging
}
void loop() {
ldrValue = analogRead(ldrPin); // Read the value from the LDR
Serial.println(ldrValue); // Print the LDR value to the Serial Monitor
if (ldrValue < 500) { // If it is dark (adjust threshold value as needed)

Department Of Electronics and Communication Engineering 32


digitalWrite(ledPin, HIGH); // Turn on the LED
} else {
digitalWrite(ledPin, LOW); // Turn off the LED
}
delay(100); // Small delay to stabilize readings
}

Step 3: Uploading the Code


• Connect the Arduino to your computer using a USB cable.
• Select the correct board and port in the Arduino IDE under Tools > Board >
Arduino Uno and Tools > Port > select the appropriate port.
• Click on the upload button to upload the code to the Arduino.
Step 4: Running the Experiment
• Once the code is uploaded, open the Serial Monitor by clicking on the magnifying
glass icon in the top right corner of the Arduino IDE.
• Cover the LDR to simulate darkness.
• Observe the LED turning on when the LDR is covered and turning off when it is
exposed to light.
6. Data Collection and Analysis
• Observe the LDR values displayed on the Serial Monitor.
• Ensure the LED responds appropriately to changes in light intensity.
7. Expected Results
The LED should turn on when the LDR detects darkness (low light levels) and
turn off when there is sufficient light.
8. Troubleshooting
• LED Not Turning On:
Check all connections, especially power and ground.

Department Of Electronics and Communication Engineering 33


Ensure the LDR connections are correct and providing accurate light
readings.
• Incorrect Threshold:
Adjust the threshold value in the code to match the desired light sensitivity.
9. Extensions and Modifications
• Multiple LEDs:
Control multiple LEDs in different areas using additional LDRs.
• Advanced Features:
Integrate a timer to keep the light on for a specified duration after detecting
darkness.
• IoT Integration:
Connect the smart light system to the internet for remote monitoring and control.
10. Conclusion
• Successfully created a smart light system using an LDR and Arduino.
• Learned how to interface an LDR and control an LED based on light
intensity.
• Explored potential improvements and advanced features for smart home
integration.
11. Applications
• Home Automation:
Use in homes for automatic lighting in rooms, hallways, and outdoor areas.
• Security Systems:
Implement in security systems to turn on lights when it gets dark for better
visibility.
• Energy Saving:
Use in offices and public places to save energy by turning off lights when
there is enough natural light.
12. References

Department Of Electronics and Communication Engineering 34


• Arduino Documentation

Department Of Electronics and Communication Engineering 35


Experiment:6
Arduino Interfacing with Soil Moisture Sensor

Experiment:
• Soil Moisture Detection using Soil Moisture Sensor and Displaying in Serial
Monitor
1. Experiment Title
• Soil Moisture Detection using Soil Moisture Sensor and Displaying in Serial
Monitor
2. Objective
• Interface a soil moisture sensor with Arduino to measure soil moisture levels and
display the readings in the Serial Monitor.
3. Materials Required
Hardware Components:
• Arduino Uno
• Soil Moisture Sensor (e.g., FC-28)
• Jumper wires
• USB cable
Software Tools and Libraries:
• Arduino IDE
4. Circuit Diagram:

Department Of Electronics and Communication Engineering 36


• Connect the VCC and GND of the soil moisture sensor to Arduino 5V and GND
respectively. Connect the sensor's analog output (AO) to Arduino Analog Pin A0.
5. Step-by-Step Instructions
Step 1: Setting Up the Hardware
• Connect the soil moisture sensor to the Arduino as per the circuit diagram.
• Ensure the sensor is properly inserted into the soil to measure moisture levels.
Step 2: Writing the Code
• Open Arduino IDE.
//Copy code
// Define the analog pin for soil moisture sensor
const int soilMoisturePin = A0;
void setup() {
Serial.begin(9600); // Initialize serial communication
}
void loop() {
int soilMoistureValue = analogRead(soilMoisturePin); // Read analog
value from soil moisture sensor
Serial.print("Soil Moisture Value: ");
Serial.println(soilMoistureValue); // Print the soil moisture value
delay(1000); // Delay for readability
}

Step 3: Uploading the Code


• Connect the Arduino to your computer using a USB cable.

Department Of Electronics and Communication Engineering 37


• Select the correct board and port in the Arduino IDE under Tools > Board >
Arduino Uno and Tools > Port > select the appropriate port.
• Click on the upload button to upload the code to the Arduino.
Step 4: Running the Experiment
• Open the Serial Monitor in the Arduino IDE or press Ctrl + Shift + M.
• The Serial Monitor will display continuous readings of soil moisture values.
• Observe the readings as you adjust the soil moisture sensor in different soil
conditions.
6. Data Collection and Analysis
• Monitor and record the soil moisture values displayed in the Serial Monitor.
• Compare readings between different soil conditions (dry, moist, wet).
7. Expected Results
• The Serial Monitor should display numerical values representing soil moisture
levels read by the sensor.
8. Troubleshooting
• No Serial Output:
Ensure the Serial.begin() baud rate (9600 in this case) matches the baud rate set
in the Serial Monitor.
• Check connections between Arduino and soil moisture sensor.
9. Extensions and Modifications
Calibration:
• Calibrate the sensor readings for specific soil types and conditions.
Data Logging:
• Implement data logging to store soil moisture readings over time.

Visualization:
• Create graphs or charts using software like Excel for better data visualization.
10. Conclusion
Department Of Electronics and Communication Engineering 38
• Successfully interfaced a soil moisture sensor with Arduino to measure and
display soil moisture levels in the Serial Monitor.
• Understood the basics of analog sensor interfacing and serial communication
with Arduino.
• Explored potential applications in agriculture, gardening, and environmental
monitoring.
11. Applications
• Agricultural Monitoring: Monitor soil moisture levels to optimize irrigation
schedules.
• Research and Education: Use in educational projects to study plant growth and
water requirements.
• Environmental Monitoring: Implement in projects to monitor soil health and
water conservation efforts.
12. References
• Arduino Documentation and Resources
• Soil moisture sensor datasheets and relevant resources on sensor interfacing
with microcontrollers.

Department Of Electronics and Communication Engineering 39


Experiment:7
Arduino Interfacing with Sound Sensor

Experiment: Sound Sensing using Sound Sensor with Arduino


1. Experiment Title
• Sound Sensing using Sound Sensor with Arduino
2. Objective
• Detect sound using a sound sensor module and control an LED to turn on
when sound is detected and off when no sound is detected.
3. Materials Required
Hardware Components:
• Arduino Uno
• Sound Sensor Module (e.g., KY-038 or LM393)
• LED
• Resistor (220 ohms)
• Breadboard
• Jumper wires
• USB cable
Software Tools and Libraries:
• Arduino IDE

4. Circuit Diagram

Department Of Electronics and Communication Engineering 40


1. Connect the VCC and GND of the sound sensor module to Arduino 5V and GND
respectively.
2. Connect the digital output (DO) of the sound sensor to Arduino Digital Pin 2.

3. Connect the positive leg of the LED to Arduino Digital Pin 3 through a 220-ohm
resistor. Connect the negative leg of the LED to GND.
5. Step-by-Step Instructions
Step 1: Setting Up the Hardware
• Connect the sound sensor and LED to the Arduino as per the circuit diagram.
• Ensure the connections are secure and the components are correctly oriented.
Step 2: Writing the Code
• Open Arduino IDE.
Copy code
// Define pins
const int soundSensorPin = 2; // Digital pin for sound sensor
const int ledPin = 3; // Digital pin for LED
void setup() {
pinMode(soundSensorPin, INPUT); // Set sound sensor pin as input
pinMode(ledPin, OUTPUT); // Set LED pin as output
}

Department Of Electronics and Communication Engineering 41


void loop() {
int soundSensorValue = digitalRead(soundSensorPin); // Read sound
sensor value (HIGH or LOW)
if (soundSensorValue == HIGH) {
digitalWrite(ledPin, HIGH); // Turn LED on if sound is detected
} else {
digitalWrite(ledPin, LOW); // Turn LED off if no sound is detected
}
}

Step 3: Uploading the Code


• Connect the Arduino to your computer using a USB cable.
• Select the correct board and port in the Arduino IDE under Tools > Board >
Arduino Uno and Tools > Port > select the appropriate port.
• Click on the upload button to upload the code to the Arduino.
Step 4: Running the Experiment
• After uploading, observe the LED connected to pin 3.
• Make noises near the sound sensor and observe the LED turning on when sound
is detected and off when no sound is detected.
6. Data Collection and Analysis
• Observe the LED behavior based on sound sensor readings.
• Note the sensitivity of the sound sensor and its response to different sound levels.
7. Expected Results
• The LED should turn on when sound is detected by the sound sensor and
turn off when no sound is present.
8. Troubleshooting
LED Not Responding:

Department Of Electronics and Communication Engineering 42


• Check connections between Arduino, sound sensor, and LED.
• Ensure the sound sensor is properly powered and positioned.
9. Extensions and Modifications
• Sound Thresholds: Adjust the sensitivity threshold in the code to detect louder or
quieter sounds.
• Sound Notification System: Integrate with a buzzer to create an audible alert
when sound is detected.
10. Conclusion
• Successfully implemented sound sensing using a sound sensor module with
Arduino.
• Learned to control an LED based on digital input from the sensor.
• Explored applications in sound detection for home automation and security
systems.
11. Applications
• Home Automation: Trigger lights or appliances based on sound events.
• Security Systems: Sound-based intrusion detection and alert systems.
• Environmental Monitoring: Detect sound levels in environmental monitoring
projects.

12. References
• Arduino Documentation and Resources
• Sound sensor module datasheets and relevant resources on sensor interfacing
with microcontrollers.

Department Of Electronics and Communication Engineering 43


Experiment:8
Arduino Interfacing with Ultrasonic Sensor and LCD-I2C

Experiment:
Distance Measurement with Ultrasonic Sensor and Display on LCD using Arduino
with I2C Interface
1. Experiment Title
• Distance Measurement with Ultrasonic Sensor and Display on LCD using Arduino
with I2C Interface
2. Objective
• Learn how to interface an ultrasonic sensor with Arduino to measure distance
and display it on a 16x2 LCD using an I2C module.
3. Materials Required
Hardware Components:
• Arduino Uno
• HC-SR04 Ultrasonic Sensor
• 16x2 LCD display with I2C backpack (e.g., PCF8574)
• I2C module
• Breadboard
• Jumper wires

Department Of Electronics and Communication Engineering 44


• USB cable
Software Tools and Libraries:
• Arduino IDE
• LiquidCrystal_I2C library
• NewPing library (for HC-SR04)
4. Circuit Diagram
Connections:

Ultrasonic Sensor (HC-SR04):


• VCC to Arduino 5V
• GND to Arduino GND
• Trig to Arduino Digital Pin 2
• Echo to Arduino Digital Pin 3
I2C Module:
• SDA to Arduino A4
• SCL to Arduino A5

Department Of Electronics and Communication Engineering 45


• VCC to Arduino 5V
• GND to Arduino GND
• LCD Display (with I2C Backpack):
• Connect the I2C module to the LCD as per its specification.
5. Step-by-Step Instructions
Step 1: Setting Up the Hardware
• Connect the ultrasonic sensor to the Arduino and ensure the I2C module is
connected to the LCD display.
• Verify all connections according to the circuit diagram.
Step 2: Installing Libraries
• Open Arduino IDE.
• Go to Sketch > Include Library > Manage Libraries.
• Search and install the following libraries:
• LiquidCrystal_I2C by Frank de Brabander
• NewPing by Tim Eckel

Step 3: Writing the Code


copycode
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <NewPing.h>
// Define pins for I2C LCD

Department Of Electronics and Communication Engineering 46


LiquidCrystal_I2C lcd(0x27, 16, 2); // Set the LCD address to 0x27 for a 16
chars and 2 line display
// Define pins for ultrasonic sensor
#define TRIGGER_PIN 2
#define ECHO_PIN 3
#define MAX_DISTANCE 200 // Maximum distance we want to ping for (in
centimeters). Maximum sensor distance is rated at 400-500cm.
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);
// NewPing setup of pins and maximum distance.
void setup() {
lcd.init(); // Initialize the LCD
lcd.backlight(); // Turn on the backlight
lcd.setCursor(0, 0); // Set cursor to first column (0) and first row (0)
lcd.print("Distance:"); // Print initial message on LCD
}
void loop() {
delay(500); // Wait 500ms between pings (this is a safety margin to avoid
overloading the sensor)
unsigned int distance = sonar.ping_cm(); // Send ping, get distance in cm
(0 = outside set distance range)
if (distance == 0) {
lcd.setCursor(0, 1); // Set cursor to first column (0) and second row (1)
lcd.print("Out of Range "); // Print out of range message
} else {
lcd.setCursor(10, 0); // Set cursor to eleventh column (10) and first row
(0)
lcd.print(" "); // Clear previous distance

Department Of Electronics and Communication Engineering 47


lcd.setCursor(10, 0); // Reset cursor to eleventh column (10) and first
row (0)
lcd.print(distance); // Print the distance
lcd.print(" cm "); // Print unit
}
}

Step 4: Uploading the Code


• Connect the Arduino to your computer using a USB cable.
• Select the correct board and port in the Arduino IDE under Tools > Board >
Arduino Uno and Tools > Port > select the appropriate port.
• Click on the upload button to upload the code to the Arduino.
Step 5: Running the Experiment
• Once the code is uploaded, the LCD should display the measured distance in
centimeters.
• Move objects closer to or farther from the ultrasonic sensor to see the distance
measurement change on the LCD.
6. Data Collection and Analysis
• Observe and record the distance measurements displayed on the LCD.
• Note any variations in measurements based on the distance of objects from the
sensor.
7. Expected Results
• The LCD should continuously display the distance measured by the ultrasonic
sensor in centimeters.
8. Troubleshooting
No Display on LCD:
• Check the connections between the Arduino, I2C module, and LCD.
• Ensure the I2C address in the code (0x27) matches your module.

Department Of Electronics and Communication Engineering 48


Inaccurate Distance Measurements:
• Verify the connections and ensure the ultrasonic sensor is placed correctly.
• Adjust the MAX_DISTANCE constant in the code if necessary.
9. Extensions and Modifications
• Temperature Compensation:
Incorporate a temperature sensor to adjust distance measurements based on
ambient temperature.
• Multiple Sensors:
Interface multiple ultrasonic sensors to monitor distances in different directions.

• Data Logging:
Store distance measurements in an SD card module or transmit them wirelessly
using Wi-Fi or Bluetooth.
10. Conclusion
• Successfully interfaced an ultrasonic sensor with Arduino to measure and display
distances on a 16x2 LCD using an I2C module.
• Learned how to use the NewPing library for accurate distance measurements and
the LiquidCrystal_I2C library for simplified LCD control.
• Explored potential improvements and advanced features for distance
measurement projects.
11. Applications
Smart Parking Systems:
• Monitor vehicle distances in parking lots to assist drivers in parking.
Obstacle Avoidance:
• Integrate into robotic systems to detect and avoid obstacles.
Industrial Automation:
• Measure distances in manufacturing processes for quality control and safety.
12. References

Department Of Electronics and Communication Engineering 49


1. Arduino Documentation
2.LiquidCrystal_I2C Library
3.DocumentationNewPing Library Documentation

Experiment:9
Arduino Interfacing with RFID
Experiment Outline
1. Experiment Title
• Arduino Interfacing with RFID Reader
2. Objective
• Use Arduino to read RFID tags and display tag information on the Serial
Monitor.
3. Materials Required
Hardware Components:
• Arduino Uno
• RFID Reader Module (e.g., MFRC522)
• RFID Tags (compatible with the reader)
• Jumper wires

Department Of Electronics and Communication Engineering 50


• USB cable
• Software Tools and Libraries:
• Arduino IDE
• MFRC522 Library (for interfacing with the RFID reader
module)

4. Circuit Diagram

• Connect the MFRC522 RFID reader module to Arduino as per the datasheet or
module instructions.
• Typically, connections include SPI pins (MOSI, MISO, SCK, SS) and power (5V and
GND).
5. Step-by-Step Instructions
Step 1: Setting Up the Hardware

Department Of Electronics and Communication Engineering 51


• Connect the RFID reader module to the Arduino SPI pins and power as per the
circuit diagram.
Step 2: Writing the Code
arduino
Copy code
#include <SPI.h>
#include <MFRC522.h>
#define SS_PIN 10 // Arduino digital pin connected to RFID / NSS pin
#define RST_PIN 9 // Arduino digital pin connected to RFID / RST pin
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance
void setup() {
Serial.begin(9600); // Initialize serial communication
SPI.begin(); // Initialize SPI bus
mfrc522.PCD_Init(); // Initialize MFRC522 RFID reader
Serial.println("RFID Reader Initialized");
}
void loop() {
// Look for new RFID cards
if ( ! mfrc522.PICC_IsNewCardPresent() || ! mfrc522.PICC_ReadCardSerial() ) {
delay(50);
return;
}
// Show UID on Serial Monitor
Serial.print("Tag UID:");
for (byte i = 0; i < mfrc522.uid.size; i++) {
Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");

Department Of Electronics and Communication Engineering 52


Serial.print(mfrc522.uid.uidByte[i], HEX);
}
Serial.println();
mfrc522.PICC_HaltA(); // Halt PICC
mfrc522.PCD_StopCrypto1(); // Stop encryption on PCD
delay(1000); // Wait for 1 second before scanning for another card
}

Step 3: Uploading the Code


• Connect the Arduino to your computer using a USB cable.
• Select the correct board and port in the Arduino IDE.
• Click on the upload button to upload the code to the Arduino.
Step 4: Running the Experiment
• Open the Serial Monitor in the Arduino IDE or use the shortcut Ctrl + Shift +M.
• Hold an RFID tag near the reader module.
• The Serial Monitor will display the UID (Unique Identifier) of the detected
RFID tag.
• Data Collection and Analysi
• Record and analyze different RFID tag UIDs detected by the Arduino.
• Expected Results
• The Serial Monitor should display the UID of RFID tags when they are brought
near the RFID reader module.
6. Troubleshooting
• Ensure correct wiring of SPI pins and power connections.
• Check library inclusion (#include <MFRC522.h>) and initialization
(mfrc522.PCD_Init();).

Department Of Electronics and Communication Engineering 53


7. Extensions and Modifications
• Implement access control or authentication based on RFID tag UID.
• Interface with a database or web service to log RFID tag detections.
8. Conclusion
• Successfully interfaced an RFID reader module with Arduino to read RFID tags.
• Learned about SPI communication and RFID technology.
9. Applications
• Access Control Systems
• Inventory Management
• Asset Tracking
10. References
• Arduino Documentation
• MFRC522 RFID reader module datasheet and resources

Experiment:10
Arduino Interfacing with Bluetooth Module

Experiment:
LED Control using Bluetooth Module with Arduino
1. Experiment Title

Department Of Electronics and Communication Engineering 54


• LED Control using Bluetooth Module with Arduino

2. Objective
• Control an LED wirelessly via Bluetooth using a mobile app, demonstrating
basic Bluetooth communication with Arduino.
3. Materials Required
Hardware Components:
• Arduino Uno
• HC-05 Bluetooth Module
• LED
• Resistor (220 ohms)
• Breadboard
• Jumper wires
• USB cable
Software Tools Required:
• Arduino IDE
• Bluetooth Module Library
• Serial Communication Library
• Bluetooth Terminal App
4. Circuit Diagram

Department Of Electronics and Communication Engineering 55


Connections:
• Connect the anode (+) of the LED through a 220-ohm resistor to Arduino digital
pin 7.
• Connect the cathode (-) of the LED to GND.
• Connect the TX pin of the Bluetooth module (HC-05) to Arduino RX (pin 0).
• Connect the RX pin of the Bluetooth module to Arduino TX (pin 1).
• Ensure the Bluetooth module is properly powered and connected.
5. Step-by-Step Instructions
Step 1: Setting Up the Hardware
• Connect the LED and Bluetooth module to Arduino as per the circuit diagram.
• Ensure all connections are secure and correct.
Step 2: Writing the Code
• Install a Bluetooth terminal app (e.g., "Arduino Bluetooth Controller") on
your smartphone.
//Copy code
// Include necessary libraries
#include <SoftwareSerial.h>
// Define pin numbers

Department Of Electronics and Communication Engineering 56


#define ledPin 7 // Pin connected to LED
#define bluetoothTx 1 // Bluetooth TX to Arduino RX
#define bluetoothRx 0 // Bluetooth RX to Arduino TX

// Create a SoftwareSerial object for Bluetooth communication


SoftwareSerial bluetooth(bluetoothRx, bluetoothTx);

void setup() {
// Initialize serial communication for debugging
Serial.begin(9600);
pinMode(ledPin, OUTPUT); // Set LED pin as output
// Set up Bluetooth communication
bluetooth.begin(9600);
}
void loop() {
// Check if data is available to read from Bluetooth
if (bluetooth.available()) {
char command = bluetooth.read(); // Read the incoming data from
Bluetooth
Serial.print("Received command: ");
Serial.println(command)
// Perform action based on received command
if (command == '1') {
digitalWrite(ledPin, HIGH); // Turn LED ON
Serial.println("LED ON");
} else if (command == '0') {

Department Of Electronics and Communication Engineering 57


digitalWrite(ledPin, LOW); // Turn LED OFF
Serial.println("LED OFF");
}
}
}

Step 3: Uploading the Code


• Connect the Arduino to your computer using a USB cable.
• Select the correct board and port in the Arduino IDE under Tools > Board >
Arduino Uno and Tools > Port > select the appropriate port.
• Click on the upload button to upload the code to the Arduino.
Step 4: Running the Experiment
• Power on the Arduino.
• Open the Bluetooth terminal app on your smartphone and pair it with the HC-05
Bluetooth module.
• Send '1' to turn on the LED and '0' to turn off the LED from the app.
6. Data Collection and Analysis
• Monitor the serial monitor output to debug and verify commands received from
the Bluetooth module.
7. Expected Results
• The LED should turn on or off based on the commands sent from the Bluetooth
terminal app.
8. Troubleshooting
• Bluetooth Connection Issues:
• Check Bluetooth module connections (TX to RX, RX to TX) and ensure they are
correctly connected.
• Ensure the Bluetooth module is paired with the correct device and within range.
9. Extensions and Modifications

Department Of Electronics and Communication Engineering 58


• Multiple LEDs: Control multiple LEDs or other actuators using additional pins and
commands.
• PWM Control: Implement brightness control for LEDs using PWM signals.
• Mobile App Development: Create a custom mobile app for more advanced control
features.
10. Conclusion
• Successfully implemented wireless LED control using a Bluetooth module with
Arduino.
• Explored the basics of serial communication over Bluetooth and its application in
remote control systems.
• Explored potential applications in home automation and IoT projects.

11. Applications
• Home Automation: Control lights and appliances wirelessly.
• Robotics: Integrate into robotic systems for remote operation.
• IoT Projects: Enable remote monitoring and control of devices via Bluetooth
connectivity.
12. References
• Arduino Documentation and Resources
• HC-05 Bluetooth Module datasheet and related documentation on Bluetooth
communication protocols.

Department Of Electronics and Communication Engineering 59


Experiment:11
Arduino Interfacing with Bluetooth and Ultrasonic Sensor
Experiment:
Sending Data from Smartphone to Arduino using Bluetooth Module
1. Experiment Title
• Sending Data from Smartphone to Arduino using Bluetooth Module
2. Objective

Department Of Electronics and Communication Engineering 60


• Send data from a smartphone to an Arduino using a Bluetooth module and
display the received data on the Serial Monitor.
3. Materials Required
Hardware Components:
• Arduino Uno
• HC-05 Bluetooth Module
• Breadboard
• Jumper wires
• USB cable
Software Tools Required:
• Arduino IDE
• Bluetooth Module Library
• Serial Communication Library
• Bluetooth Terminal App

4. Circuit Diagram

• Connect the components as shown in the circuit diagram:


Connections:

Department Of Electronics and Communication Engineering 61


• Connect the TX pin of the Bluetooth module (HC-05) to Arduino RX pin (pin 0).
• Connect the RX pin of the Bluetooth module to Arduino TX pin (pin 1).
• Ensure the Bluetooth module is properly powered and connected.
5. Step-by-Step Instructions
Step 1: Setting Up the Hardware
• Connect the Bluetooth module to Arduino as per the circuit diagram.
• Ensure all connections are secure and correct.
Step 2: Writing the Code
• Install a Bluetooth terminal app (e.g., "Arduino Bluetooth Controller") on your
smartphone.
//Copy code
// Include necessary libraries
#include <SoftwareSerial.h>
// Define pin numbers
#define bluetoothTx 1 // Bluetooth TX to Arduino RX
#define bluetoothRx 0 // Bluetooth RX to Arduino TX
// Create a SoftwareSerial object for Bluetooth communication
SoftwareSerial bluetooth(bluetoothRx, bluetoothTx);
void setup() {
// Initialize serial communication for debugging
Serial.begin(9600);
// Set up Bluetooth communication
bluetooth.begin(9600);
}
void loop() {
// Check if data is available to read from Bluetooth
if (bluetooth.available()) {

Department Of Electronics and Communication Engineering 62


char data = bluetooth.read(); // Read the incoming data from Bluetooth
Serial.print("Received data: ");
Serial.println(data);
}
}

Step 3: Uploading the Code


• Connect the Arduino to your computer using a USB cable.
• Select the correct board and port in the Arduino IDE under Tools > Board >
Arduino Uno and Tools > Port > select the appropriate port.
• Click on the upload button to upload the code to the Arduino.
Step 4: Running the Experiment
• Power on the Arduino.
• Open the Bluetooth terminal app on your smartphone and pair it with the HC-05
Bluetooth module.
• Send any character or string from the app to the Arduino.
• Open the Serial Monitor in the Arduino IDE to see the received data.
6. Data Collection and Analysis
• Monitor the Serial Monitor output to see the data sent from the smartphone and
verify successful transmission.
7. Expected Results
• Data sent from the smartphone should be received by the Arduino and displayed
on the Serial Monitor.
8. Troubleshooting
Bluetooth Connection Issues:
• Ensure Bluetooth module connections (TX to RX, RX to TX) are correctly
connected.
• Ensure the Bluetooth module is paired with the correct device and within range.

Department Of Electronics and Communication Engineering 63


Serial Communication Issues:
• Check baud rates in the code and the Bluetooth app to ensure they match.
• Verify that the correct COM port is selected in the Arduino IDE.
9. Extensions and Modifications
• Data Processing: Implement code to process and respond to different commands
sent from the smartphone.
• Sensor Integration:Use the received data to control sensors or actuators
connected to the Arduino.
• Two-Way Communication:Send data from the Arduino back to the smartphone
for two-way communication.
10. Conclusion
• Successfully demonstrated how to send data from a smartphone to an Arduino
using a Bluetooth module.
• Explored the basics of serial communication over Bluetooth and its application in
wireless control systems.
• Identified potential applications in home automation, robotics, and IoT projects.
11. Applications
• Home Automation: Control home appliances wirelessly from a smartphone.
• Robotics: Send commands to robots and receive sensor data wirelessly.
• IoT Projects: Enable wireless data transmission for various IoT applications.
12. References
1. Arduino Documentation and Resources
2.HC-05 Bluetooth Module datasheet and related documentation on Bluetooth
communication protocols.

Department Of Electronics and Communication Engineering 64


Experiment:12
WEBSERVER with ESP8266 or ESP32

Experiment:
LED Controlling with WiFi Module and Web Page Interface
1. Experiment Title
• LED Controlling with WiFi Module and Web Page Interface using Arduino
2. Objective
• To control an LED connected to an Arduino board through a web page interface
using a WiFi module.
3. Materials Required
Hardware Components:
• Arduino Uno
• ESP8266 WiFi Module
• LED
• Resistor (220 ohms)
• Breadboard
• Jumper wires
Department Of Electronics and Communication Engineering 65
• USB cable
Software Tools and Libraries:
• Arduino IDE
• ESP8266WiFi library

4. Circuit Diagram

LED:
• Anode (+) to digital pin 4 (through a 220-ohm resistor)
• Cathode (-) to GND
5. Step-by-Step Instructions
Step 1: Setting Up the Hardware
• Connect the LED to the Arduino as per the circuit diagram.
• Connect the ESP8266 WiFi module to the Arduino.
Step 2: Writing the Code

Department Of Electronics and Communication Engineering 66


//Copy code
#include <ESP8266WiFi.h>
const char* ssid = "your_SSID"; // Replace with your network SSID
const char* password = "your_PASSWORD"; // Replace with your network
password
WiFiServer server(80);

const int ledPin = 4;

void setup() {
Serial.begin(115200);
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);

// Connect to WiFi network


Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {


delay(1000);
Serial.print(".");
}

Serial.println("");
Serial.println("WiFi connected");

Department Of Electronics and Communication Engineering 67


Serial.println("IP address: ");
Serial.println(WiFi.localIP());

server.begin();
}

void loop() {
WiFiClient client = server.available();
if (client) {
Serial.println("New Client.");
String currentLine = "";
while (client.connected()) {
if (client.available()) {
char c = client.read();
Serial.write(c);
if (c == '\n') {
if (currentLine.length() == 0) {
client.println("HTTP/1.1 200 OK");
client.println("Content-type:text/html");
client.println();

client.print("Click <a href=\"/H\">here</a> to turn the LED


on.<br>");
client.print("Click <a href=\"/L\">here</a> to turn the LED
off.<br>");

client.println();

Department Of Electronics and Communication Engineering 68


break;
} else {
currentLine = "";
}
} else if (c != '\r') {
currentLine += c;
}

if (currentLine.endsWith("GET /H")) {
digitalWrite(ledPin, HIGH);
}
if (currentLine.endsWith("GET /L")) {
digitalWrite(ledPin, LOW);
}
}
}
client.stop();
Serial.println("Client Disconnected.");
}
}

Step 3: Uploading the Code


• Connect the Arduino to your computer using a USB cable.
• Select the correct board and port in the Arduino IDE under Tools > Board >
Arduino Uno and Tools > Port > select the appropriate port.
• Click on the upload button to upload the code to the Arduino.
Step 4: Running the Experiment

Department Of Electronics and Communication Engineering 69


• Power on the Arduino.
• Open a web browser and enter the IP address displayed in the Serial Monitor.
• Use the web page interface to turn the LED on and off.

6. Data Collection and Analysis


• Monitor the Serial Monitor to view connection status and client requests.
• Observe the LED's response to the web page interface.
7. Expected Results
• The LED should turn on when the "Click here to turn the LED on" link is clicked.
• The LED should turn off when the "Click here to turn the LED off" link is clicked.
8. Troubleshooting
WiFi Connection Issues:
• Ensure the WiFi credentials are correct.
• Verify the ESP8266 module connections.
Web Page Not Loading:
• Check the IP address displayed in the Serial Monitor.
• Ensure the device running the web browser is on the same network as the
ESP8266.
9. Extensions and Modifications
• Multiple LEDs: Control multiple LEDs with different web page buttons.
• Sensor Integration: Add sensors to monitor environmental conditions and display
data on the web page.
• Mobile App Development: Develop a mobile app to control the LED and other
connected devices.
10. Conclusion
• Successfully demonstrated how to control an LED using a web page interface and
a WiFi module with Arduino.
• Explored the basics of web server creation and HTTP requests.
Department Of Electronics and Communication Engineering 70
• Identified potential applications in remote device control and smart home
systems.
11. Applications
• Smart Home Systems: Control home appliances and lighting remotely via a web
interface.
• Remote Monitoring and Control: Monitor and control devices in industrial
settings.
• Educational Projects: Teach concepts of IoT and web-based control in
educational environments.
12. References
• Arduino Documentation and Resources
• ESP8266 WiFi Module datasheet and related documentation on WiFi
communication.

Department Of Electronics and Communication Engineering 71


Experiment:13
ESP8266 or ESP32 Interfacing with DHT11

Experiment:
Temperature and Humidity Monitoring with WiFi Module and Web Page
Interface
1. Experiment Title
• Temperature and Humidity Monitoring with WiFi Module and Web Page Interface
using Arduino
2. Objective
• To monitor temperature and humidity levels using a DHT11 sensor connected to
an Arduino board and display the data on a web page through a WiFi module.
3. Materials Required
Hardware Components:
• Arduino Uno
• ESP8266 WiFi Module
• DHT11 Sensor
• Breadboard
• Jumper wires
• USB cable
Software Tools and Libraries:
• Arduino IDE
• DHT sensor library
• ESP8266WiFi library

Department Of Electronics and Communication Engineering 72


4. Circuit Diagram

DHT11 Sensor:
• VCC to 5V
• GND to GND
• Data to digital pin 1
5. Step-by-Step Instructions
Step 1: Setting Up the Hardware
• Connect the DHT11 sensor to the Arduino as per the circuit diagram.
• Connect the ESP8266 WiFi module to the Arduino.
Step 2: Writing the Code
• Install the DHT sensor library from the Library Manager in Arduino IDE.
Copy code
#include <ESP8266WiFi.h>
#include <DHT.h>

#define DHTPIN 2
#define DHTTYPE DHT11

Department Of Electronics and Communication Engineering 73


DHT dht(DHTPIN, DHTTYPE);

const char* ssid = "your_SSID"; // Replace with your network SSID


const char* password = "your_PASSWORD"; // Replace with your network
password

WiFiServer server(80);

void setup() {
Serial.begin(115200);
dht.begin();
WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {


delay(1000);
Serial.print(".");
}

Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());

server.begin();
}

Department Of Electronics and Communication Engineering 74


void loop() {
WiFiClient client = server.available();
if (client) {
Serial.println("New Client.");
String currentLine = "";
while (client.connected()) {
if (client.available()) {
char c = client.read();
Serial.write(c);
if (c == '\n') {
if (currentLine.length() == 0) {
float h = dht.readHumidity();
float t = dht.readTemperature();

client.println("HTTP/1.1 200 OK");


client.println("Content-type:text/html");
client.println();

client.print("Temperature: ");
client.print(t);
client.println(" &#8451;<br>");
client.print("Humidity: ");
client.print(h);
client.println(" %<br>");

client.println();

Department Of Electronics and Communication Engineering 75


break;
} else {
currentLine = "";
}
} else if (c != '\r') {
currentLine += c;
}
}
}
client.stop();
Serial.println("Client Disconnected.");
}
}

Step 3: Uploading the Code


• Connect the Arduino to your computer using a USB cable.
• Select the correct board and port in the Arduino IDE under Tools > Board >
Arduino Uno and Tools > Port > select the appropriate port.
• Click on the upload button to upload the code to the Arduino.
Step 4: Running the Experiment
• Power on the Arduino.
• Open a web browser and enter the IP address displayed in the Serial Monitor.
• The web page should display the current temperature and humidity readings.
6. Data Collection and Analysis
• Monitor the Serial Monitor to view connection status and client requests.
• Observe the temperature and humidity data displayed on the web page.
7. Expected Results

Department Of Electronics and Communication Engineering 76


• The web page should show real-time temperature and humidity readings from
the DHT11 sensor.
8. Troubleshooting
WiFi Connection Issues:
• Ensure the WiFi credentials are correct.
• Verify the ESP8266 module connections.
Web Page Not Loading:
• Check the IP address displayed in the Serial Monitor.
• Ensure the device running the web browser is on the same network as the
ESP8266.
9. Extensions and Modifications
• Data Logging: Store the temperature and humidity data in a database for
historical analysis.
• Alerts: Set up email or SMS alerts for specific temperature or humidity
thresholds.
• Mobile App Development: Develop a mobile app to display the data and control
the system.
10. Conclusion
• Successfully demonstrated how to monitor temperature and humidity using a
DHT11 sensor and display the data on a web page via a WiFi module.
• Explored the basics of web server creation and HTTP requests.
• Identified potential applications in remote environmental monitoring.

11. Applications
• Home Automation: Monitor home environment and control HVAC systems.
• Agriculture: Track temperature and humidity in greenhouses and farms.
• Industrial Monitoring: Monitor environmental conditions in factories and
warehouses.

Department Of Electronics and Communication Engineering 77


12. References
• Arduino Documentation and Resources
• DHT11 Sensor datasheet and related documentation

Department Of Electronics and Communication Engineering 78

You might also like