0% found this document useful (0 votes)
26 views30 pages

IOT Merged

The document describes a practical lab report on various Internet of Things experiments conducted using Arduino. It includes programs for blinking an LED, reading temperature from an LM35 sensor, fading an LED brightness, controlling devices over Blynk, and using ultrasonic sensors with a servo motor to build a smart dustbin.

Uploaded by

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

IOT Merged

The document describes a practical lab report on various Internet of Things experiments conducted using Arduino. It includes programs for blinking an LED, reading temperature from an LM35 sensor, fading an LED brightness, controlling devices over Blynk, and using ultrasonic sensors with a servo motor to build a smart dustbin.

Uploaded by

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

Guru Gobind Singh Indraprastha University

Sector -16 C, Dwarka, Delhi, India

Practical XII - IOT Lab


BCA-372
By
Name: Tushar Bajaj
BaNo:
Enrolment Bajaj
01324302021
1
Under the guidance:
Ms. Sonam Barak
(Assistant Professor)

Sirifort Institute of Management Studies


Plot No.8, Institutional Area Rohini Sector-25, New Delhi 110085.
Index
Page
S.NO Problem Statement Date Signature
No.
1. Study and Install IDE of Arduino . 1-4

2. Write the steps to add libraries in 5-9


Arduino and setup Arduino IDE for
programming.
3. Write a program using Arduino for 10
Blink LED.

4. Write a program for monitoring 11


Temperature using Arduino and
LM35 Temperature Sensors.

5. Write a program that shows how to 12


fade an LED on pin 9 using the
Analog. Write() function.

6. Write a program of Fade LED using 13-15


NodeMCU(ESP8266) and blynk app.

7. Write a program for controlling bulb 16-20


on/off by using Blynk app.

8. Write a program using Arduino for 21-22


Servo Motor(HC-SR04).

9. Write a program using Arduino for 23-24


Ultrasonic sensor.

10. Write a program for Arduino by 25-26


Ultrasonic sensor and servo
motor(HC- SR04), and make a smart
dustbin.
Sirifort Institute Of Management Studies (SIMS)

PRACTICAL 1

Study and Install IDE of Arduino.

Hardware Components:
• Arduino Uno: Specifically chosen for its widespread availability, ease of use,
and compatibility with a wide range of sensors and actuators. Its versatility
allows for future expansion and integration with additional components.

• Soil Moisture Sensors: Utilized to measure soil moisture content accurately.


These sensors can be analog or digital and come in various forms like resistive
or capacitive. They provide essential data for determining when and how much
to water the plants.

• Water Pump: A submersible water pump is often used in garden irrigation


systems. Its flow rate and capacity should match the garden's size and watering
requirements.
• Temperature and Humidity Sensor: Provides additional environmental data
crucial for plant health. Arduino-compatible sensors like the DHT series or the
BME280 are commonly used for this purpose.

• LCD Display: Allows for real-time monitoring of important parameters such as


soil moisture levels, temperature, humidity, and system status. Users can easily
observe and interpret the data displayed on the screen.

Software Development:
➢ Arduino IDE: Provides a user-friendly interface for writing, compiling, and
uploading code to the Arduino board. It supports the C++ programming
language, making it accessible to developers of varying skill levels.
➢ Programming Logic: The firmware developed for the Arduino board
includes algorithms for sensor data acquisition, data processing,
decisionmaking regarding irrigation schedules, and control of the water
pump.
➢ Algorithm: The irrigation algorithm considers factors such as soil moisture
thresholds, plant types, weather forecasts, and historical data to determine
the optimal watering schedule and duration. It may incorporate techniques
like threshold-based control, PID control, or machine learning for adaptive
irrigation management.

Tushar Bajaj 1 01324302021


Sirifort Institute Of Management Studies (SIMS)

Installation

1. Download from the website https://www.arduino.cc/en/software

2. Extract the file


Tushar Bajaj 2 01324302021
Sirifort Institute Of Management Studies (SIMS)

3. Open Arduino IDE.exe


Tushar Bajaj 3 01324302021
Sirifort Institute Of Management Studies (SIMS)

Tushar Bajaj 4 01324302021


Sirifort Institute Of Management Studies (SIMS)

PRACTICAL 2

Write the steps to add libraries in Arduino and setup Arduino IDE for
programming.

1. Write the steps to add libraries in Arduino and setup Arduino IDE for programming.

I) Using library Manager


a) To install a new library into your Arduino IDE you can use the Library Manager
(available from IDE version 1.6.2). Open the IDE and click to the "Sketch" menu
and then Include Library > Manage Libraries.

b) Then the Library Manager will open and you will find a list of libraries that are
already installed or ready for installation. In this example we will install the
Bridge library. Scroll the list to find it, click on it, then select the version of the
library you want to install. Sometimes only one version of the library is
available. If the version selection menu does not appear, don't worry: it is
normal.

Tushar Bajaj 5 01324302021


Sirifort Institute Of Management Studies (SIMS)

a) Finally click on install and wait for the IDE to install the new library.
Downloading may take time depending on your connection speed. Once it has
finished, an Installed tag should appear next to the Bridge library. You can
close the library manager.

You can now find the new library available in the Sketch > Include Library menu. If you
want to add your own library to Library Manager, follow these instructions.

Tushar Bajaj 6 01324302021


Sirifort Institute Of Management Studies (SIMS)
II) Importing a .zip Library

Libraries are often distributed as a ZIP file or folder. The name of the folder is the name of
the library. Inside the folder will be a .cpp file, a .h file and often a keywords.txt file,
examples folder, and other files required by the library. Starting with version 1.0.5, you
can install 3rd party libraries in the IDE. Do not unzip the downloaded library, leave it as
is.

a) In the Arduino IDE, navigate to Sketch > Include Library > Add .ZIP Library. At
the top of the drop down list, select the option to "Add .ZIP Library''.

a) You will be prompted to select the library you would like to add. Navigate to
the .zip file's location and open it.

Tushar Bajaj 7 01324302021


Sirifort Institute Of Management Studies (SIMS)
b) Return to the Sketch > Include Library menu. menu. You should now see the
library at the bottom of the drop-down menu. It is ready to be used in your sketch.
The zip file will have been expanded in the libraries folder in your Arduino sketches
directory.

II) Manual installation

When you want to add a library manually, you need to download it as a ZIP file, expand
it and put in the proper directory. The ZIP file contains all you need, including usage
examples if the author has provided them. The library manager is designed to install this
ZIP file automatically as explained in the former chapter, but there are cases where you
may want to perform the installation process manually and put the library in the libraries
folder of your sketchbook by yourself.

You can find or change the location of your sketchbook folder at File> Preferences >
Sketchbook location.

a) Go to the directory where you have downloaded the ZIP file of the library

Tushar Bajaj 8 01324302021


Sirifort Institute Of Management Studies (SIMS)
b) Extract the ZIP file with all its folder structure in a temporary folder, then select the
main folder, that should have the library name

c) Copy it in the "libraries" folder inside your sketchbook.

d) `Start the Arduino Software (IDE), go to Sketch > Include Library. Verify that the
library you just added is available in the list.

Tushar Bajaj 9 01324302021


Sirifort Institute Of Management Studies (SIMS)

PRACTICAL 3

Write a program using Arduino for Blink LED.

Code:
void setup() {

pinMode(13, OUTPUT);

void loop()
{ digitalWrite(13, HIGH);
delay(500);
digitalWrite(13, LOW);
delay(500);

Tushar Bajaj 10 01324302021


Sirifort Institute Of Management Studies (SIMS)

PRACTICAL 4

Write a program for monitoring Temperature using Arduino and LM35


Temperature Sensors.

Code:
const int lm35_pin A1; void
setup() {

Serial.begin(9600);

} void loop()
{ int
temp_adc_val; int
temp_val;

temp_adc_val = temp_vale_adc*4.88;
temp_val = temp_adc_val/10;

Serial.println("Temperature=");
Serial.println(temp_val);
Serial.println("Degree Celcius"); delay(1000);

Tushar Bajaj 11 01324302021


Sirifort Institute Of Management Studies (SIMS)

PRACTICAL 5

Write a program that shows how to fade an LED on pin 9 using the Analog.
Write() function.

Code:
int brightness = 0; int
fadeamount = 5;
void setup() {

pinMode(9,OUTPUT);

} void loop()
{ analogWrite(9,brightness);
brightness = brightness + fadeamount;
if(brightness>=255 || brightness>=0)
{ fadeamount = -fadeamount;

} delay(30);

Tushar Bajaj 12 01324302021


Sirifort Institute Of Management Studies (SIMS)

PRACTICAL 6

Write a program of Fade LED using NodeMCU(ESP8266) and blynk app.

Hardware Setup
Connect an LED to your NodeMCU board. Connect the cathode (short leg) of the LED to a
current-limiting resistor (e.g., 220 ohms), and connect the other end of the resistor to GPIO
pin D1.

Connect the anode (long leg) of the LED to the 3.3V pin on the NodeMCU board.

Blynk Setup
Install the Blynk app on mobile device (iOS or Android) and create a new Blynk project.

In the Blynk app, add a "Slider" widget to control the LED brightness. Assign this widget to
V1 (Virtual pin 1).

Code:
#include <ESP8266WiFi.h>

#include <BlynkSimpleEsp8266.h>

// Set your WiFi credentials char


auth[] = "YourAuthToken"; char
Tushar Bajaj 13 01324302021
Sirifort Institute Of Management Studies (SIMS)
ssid[] = "YourWiFiSSID"; char
pass[] = "YourWiFiPassword";

// Define the pin connected to the LED

#define LED_PIN D1 // You can change this pin as per your connection

void setup() {

// Initialize Serial Monitor

Serial.begin(9600);

// Connect to WiFi

Blynk.begin(auth, ssid, pass);

// Initialize LED pin as an output

pinMode(LED_PIN, OUTPUT);

void loop() {

Blynk.run(); // Continuously check for Blynk commands

// Fading effect for (int brightness = 0; brightness <= 255; brightness+


+) { analogWrite(LED_PIN, brightness); // Set LED brightness using
PWM delay(10); // Small delay for smooth fading

} for (int brightness = 255; brightness >= 0; brightness--)


{ analogWrite(LED_PIN, brightness); // Set LED brightness using
PWM delay(10); // Small delay for smooth fading

}
Tushar Bajaj 14 01324302021
Sirifort Institute Of Management Studies (SIMS)
}

Steps To Follow:

Tushar Bajaj 15 01324302021


Sirifort Institute Of Management Studies (SIMS)

PRACTICAL 7

Write a program for controlling bulb on/off by using Blynk app.

Code:
#include <ESP8266WiFi.h>

#include <BlynkSimpleEsp8266.h>

// WiFi credentials char ssid[] =


"YourWiFiSSID"; char pass[] =
"YourWiFiPassword";

Tushar Bajaj 16 01324302021


Sirifort Institute Of Management Studies (SIMS)
// Blynk authentication token char
auth[] = "YourAuthToken";

// Pin connected to the LED const


int ledPin = D1;

void setup()
{ Serial.begin(9600);
pinMode(ledPin, OUTPUT);

// Connect to WiFi

Blynk.begin(auth, ssid, pass);

void loop() {

Blynk.run();

// Blynk Virtual Button handler

BLYNK_WRITE(V1) {

int pinValue = param.asInt(); // Get value of virtual button (0 or 1)

if (pinValue == 1) { // Turn
on the LED
digitalWrite(ledPin, HIGH);

Serial.println("LED ON");

Tushar Bajaj 17 01324302021


Sirifort Institute Of Management Studies (SIMS)
} else {

// Turn off the LED


digitalWrite(ledPin, LOW);

Serial.println("LED OFF");

Blynk App Dashboard Setup for Controlling LED

To control LED with Blynk app, download and install the Blynk app from Google or Apple
app store.

Then, if you are new to Blynk app, create a new account by using your Email and password.

After sign up click on ‘New Project’ to start your project.

I) Select your board and example code, as shown below:

Tushar Bajaj 18 01324302021


Sirifort Institute Of Management Studies (SIMS)

II) After these steps click on ‘Create’ button to form your project.

NODE MCU Setup for Blynk App

Tushar Bajaj 19 01324302021


Sirifort Institute Of Management Studies (SIMS)
I) In your browser search Blynk code generator then open Blynk example browser

II) Open Arduino IDE and select Tools option as shown below:

Tushar Bajaj 20 01324302021


Sirifort Institute Of Management Studies (SIMS)

PRACTICAL 8

Tushar Bajaj 21 01324302021


Sirifort Institute Of Management Studies (SIMS)

Write a program using Arduino for Servo Motor(HC-SR04).

Code:
#include "Servo.h"

Servo myservo;

#define servoPin 9

void setup() { myservo.attach(servoPin);

void loop()
{ myservo.write(90);
delay(1000);
myservo.write(180);
delay(1000);
myservo.write(0);
delay(1000);

for (int angle = 0; angle <= 180; angle += 1) {


myservo.write(angle); delay(15);

for (int angle = 180; angle >= 0; angle -= 1)


{ myservo.write(angle); delay(15);

} delay(1000);

Tushar Bajaj 22 01324302021


Sirifort Institute Of Management Studies (SIMS)

PRACTICAL 9

Write a program using Arduino for Ultrasonic sensor.


Tushar Bajaj 23 01324302021
Sirifort Institute Of Management Studies (SIMS)

Code:
int time;

int distance; int trigPin= 12; int


echoPin= 13;

void setup() { Serial.begin(9600);


pinMode(trigPin, OUTPUT); pinMode(echoPin,
INPUT);

void loop() { digitalWrite(trigPin,


HIGH); delay(1000);
digitalWrite(trigPin,LOW);
time= pulseIn(echoPin,HIGH);
distance= time*0.0343;

Serial.println(distance/2);

Tushar Bajaj 24 01324302021


Sirifort Institute Of Management Studies (SIMS)

PRACTICAL 10

Tushar Bajaj 25 01324302021


Sirifort Institute Of Management Studies (SIMS)

Write a program for Arduino by Ultrasonic sensor and servo motor(HC-


SR04), and make a smart dustbin.

Code:
#include <Servo.h>
Servo myservo; int
time; int distance,
dist; int trigPin =
12; int echoPin =
13;

void setup() { Serial.begin(9600);


pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
myservo.attach(11);

void loop() {

digitalWrite(trigPin, HIGH); delay(1000);

digitalWrite(trigPin, LOW);
time = pulseIn(echoPin, HIGH);
distance = time * 0.0343; dist =
distance/2; Serial.println(dist);
if(dist<=100)
{ myservo.write(90);
}
else{ myservo.writ
e(0);

Tushar Bajaj 26 01324302021


Sirifort Institute Of Management Studies (SIMS)
}

delay(1000); }

Tushar Bajaj 27 01324302021

You might also like