[go: up one dir, main page]

0% found this document useful (0 votes)
24 views29 pages

Iot File

This document is a practical file for a BCA 6th Semester course on the Internet of Things (IoT), detailing various Arduino and NodeMCU projects. It includes instructions for installing the Arduino IDE, adding libraries, and programming tasks such as blinking an LED, monitoring temperature with sensors, and creating home automation systems using Blynk and IFTTT. The document serves as a comprehensive guide for students to learn and implement IoT concepts through hands-on projects.

Uploaded by

Abhay Sharma
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)
24 views29 pages

Iot File

This document is a practical file for a BCA 6th Semester course on the Internet of Things (IoT), detailing various Arduino and NodeMCU projects. It includes instructions for installing the Arduino IDE, adding libraries, and programming tasks such as blinking an LED, monitoring temperature with sensors, and creating home automation systems using Blynk and IFTTT. The document serves as a comprehensive guide for students to learn and implement IoT concepts through hands-on projects.

Uploaded by

Abhay Sharma
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/ 29

PRACTICAL FILE

ON
Internet of Things (IOT) Lab
BCA 6th Semester
Course code: BCA-372
Session: 2022-25

SUBMITTED TO: SUBMITTED BY:

Mrs. Aditi Sharma Name: Aksh Vats


Assistant Professor, IT Roll No.:00415102022
Class: BCA6thSemester
INDEX

S. P no. Sign
No List of Programs
1 Study and install of Arduino IDE
Write steps to add libraries in Arduino and setup of
2 Arduino IDE for Programming Adding Libraries in
Arduino.
3 Write a program using Arduino for Blink LED.
Write a program using Arduino for monitoring
4
Temperature using LM35.
Write a program using Arduino for monitoring
5
Temperature using DHT11.
Write a program to show how to fade an LED on pin
6
9 using analog Write function.
Write the steps to add blynk libraries for Node
7
MCU and account on IFTTT for home automation.
Write a program of Fade LED using Node MCU
8
(ESP8266) and blynk app.
Write a Program for Arduino by using Ultrasonic
9 Sensors & Servo Motors (HC- SR04) and make a
Smart Dustbin.
Write a Program for controlling RGB LED using
10
Blynk App.
Design an Arduino based Smart Car Wiper System
11
using Rain Sensor and Servo Motors.
Design an Arduino based Smart Agriculture system
12
using Soil Sensor and LED.
Practical 1
Aim: Study and Install of Arduino IDE
Arduino is an open-source hardware and software platform to create interactive projects and
prototypes. It consists of both physical computing hardware (microcontroller boards) and a
development environment (Arduino IDE) for programming these boards.
Arduino IDE: The Arduino Integrated Development Environment (IDE) is a cross-platform
application written in Java, which provides a simple interface for writing, compiling, and
uploading code to Arduino boards. Following steps are followed to install Arduino IDE on
Windows
Step 1. Download Arduino IDE: Visit the official Arduino website at
https://www.arduino.cc/en/software and Click on the "Windows Installer" link to download
the installer (.exe file).
Step 2. Run Installer: Once the download is complete, locate the downloaded file (arduino-
x.x.x-windows.exe) and double-click on it to run the installer.
Step 3. Follow Installation Wizard: Follow the on-screen instructions to complete the
installation. Choose the installation directory and click “Next”. Select additional tasks like
creating a desktop shortcut or associating (optional). Click “Install” to begin the installation
process.
Step 4. Complete Installation: Wait for the installation to finish.

This may take a few moments. Once the installation is complete, click "Close" to exit the
wizard.
Step 5. Launch Arduino IDE: After installation, we can launch the Arduino IDE from the
Start menu or desktop shortcu
Practical 2

Aim: Write steps to add libraries in Arduino and setup of Arduino IDE for Programming
Adding Libraries in Arduino:
Libraries are a collection of code that makes it easy to connect to a sensor, display, module,
etc. For example, the LiquidCrystal library makes it easy to talk to character LCD displays.
There are thousands of libraries available for download directly through the Arduino IDE.
To install libraries in Arduino Launch the Arduino IDE on the computer and go to the
"Sketch" menu at the top of the Arduino IDE window. Select "Include Library" and then
click on "Manage Libraries...".

In the Library Manager, we can search for the desired library by typing its name in the search
bar or we can browse through the list of available libraries.
Click the "Install" button to download and install the required library. After installation, a
confirmation message appears indicating that the library was installed successfully. The
library may now be included in Arduino sketches by going to the "Sketch" menu, selecting
"Include Library", and choosing the installed library from the list.
Setting up Arduino IDE for Programming:
Step 1: Select Board: Connect the Arduino board to the computer using a USB cable. In the
Arduino IDE, go to the "Tools" menu and select the appropriate board from the "Board"
submenu. Choose the board model you are using (e.g., Arduino Uno, Arduino Mega).
Step 2. Select Port: After connecting the Arduino board, go to the "Tools" menu and select
the correct port from the "Port" submenu. If not sure which port corresponds to the Arduino
board, disconnect and reconnect the board to see which port disappears and reappears in the
list.
Step 3. Test Connection: To verify that the Arduino IDE is set up correctly, upload a simple
sketch (e.g., Blink) to your Arduino board.
Open the Blink example sketch (File > Examples > 01.Basics > Blink), verify it, and upload it
to the board (Sketch > Upload).
Step 4. Monitor Serial Output: If the sketch includes serial communication, the serial
output can be monitored by opening the Serial Monitor (Tools > Serial Monitor) after
uploading the sketch.
Practical 3

Aim: Write a program using Arduino for Blink LED


Hardware Required: Following components are required:
1. Arduino Uno
2. A/B Cable
3. LED
4. 220 ohms Resistor
5. Bread Board
6. Jumper wires
7. Battery
Theory:
We define a constant integer variable ledPin and assign it the value 13. This represents the pin
number where the LED is connected. In the setup() function We set the ledPin as an output
using the pinMode() function. This configuration is necessary to control the LED.
In the loop() function We turn the LED on by setting the ledPin to HIGH using the
digitalWrite() function. We then wait for 1000 milliseconds (1 second) using the delay()
function. After that, we turn the LED off by setting the ledPin to LOW. Again, we wait for
1000 milliseconds (1 second) before repeating the process.
This creates a blinking effect where the LED turns on for 1 second and then turns off for 1
second, continuously repeating the pattern.
Connection Diagram:

The circuit is the Arduino connection diagram with an external led.


The anode of the led connects to the resistor, and the resistor connects to pin 13 of the Arduino.
The cathode of the led is connected to the GND pin of the Arduino.
Code:
The program will use the pinMode function to declare pin 13 as an output pin. Next, use the
digitalWrite function to control the led on or off. The delay function is used to delay the
program for a specific time and then execute the next instructions.

void setup()
{
pinMode(13, OUTPUT);
}
void loop()
{
digitalWrite(13, HIGH);
delay(1000);
digitalWrite(13, LOW);
delay(1000);
}

Procedure:
1. Connect the LED to pin 13 of the Arduino board. Connect the cathode (shorter leg) of
the LED to pin 13 and the anode (longer leg) to a current-limiting resistor, and connect
the other end of the resistor to ground (GND) on the Arduino board.
2. Upload the sketch to the Arduino board using the Arduino IDE.
3. The LED will blink on and off at 1-second intervals.
Practical 4

Aim: Write a program using Arduino for monitoring Temperature using LM35
Hardware Required: Following components are required:
1. Arduino Uno
2. LM35 temperature sensor
3. Breadboard and jumper wires
Theory:
LM35 Temperature Sensor is an Analog Sensor that senses temperature and generates an
equivalent voltage signal. The LM35 sensor's output pin is connected to any analog pin on
the Arduino board (e.g., A0).
Connection Diagram:

Fig 1. Interfacing LM35 with Arduino

Code:
#define sensorPin A0
void setup(){
Serial.begin(9600);}
void loop() {
int reading = analogRead(sensorPin);
float voltage = reading * (5.0 / 1024.0);
float temperatureC = voltage * 100;
Serial.print("Temperature: ");
Serial.print(temperatureC);
Serial.print("\xC2\xB0"); // shows degree symbol
Serial.print("C | ");
float temperatureF = (temperatureC * 9.0 / 5.0) + 32.0;
Serial.print(temperatureF);
Serial.print("\xC2\xB0"); // shows degree symbol
Serial.println("F");
delay(1000); // wait a second between readings
}
Procedure:
1. Connect the Arduino to the computer and upload the sketch.
2. Open the Arduino IDE serial monitor (Ctrl + Shift + M) to view the temperature readings.
Make sure to have installed the DHT library for Arduino to compile and run the code
successfully.
Practical 5

Aim: Write a program using Arduino for monitoring Temperature using DHT11
Hardware Required: Following components are required:
1. Arduino Uno
2. DHT11 humidity and temperature sensor
3. Breadboard and jumper wires
Theory:
DHT11 is a Humidity and Temperature Sensor. It is a Digital sensor that is available as a 3
pin IC. DHT11 sensor's data pin is connected to any digital pin on the Arduino board (e.g.,
pin 2).
Connection Diagram:

Code:
#include <DHT.h>
#define DHTPIN 2
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);
dht.begin();}
void loop() {
delay(2000);
float humidity = dht.readHumidity();
float temperature = dht.readTemperature();
if (isnan(humidity) || isnan(temperature)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.print(" %\t");
Serial.print("Temperature: ");
}=87 Serial.print(temperature);
Serial.println(" *C");
}
Procedure:
1. Connect the Arduino to the computer and upload the sketch.
2. Open the Arduino IDE serial monitor (Ctrl + Shift + M) to view the temperature and
humidity readings.
Make sure to have installed the DHT library for Arduino to compile and run the code
successfully.
Practical 6
Aim: Write a program to show how to fade an LED on pin 9 using analogWrite function
Hardware Required: Following components are required:
1. Arduino Uno
2. LED
3. Breadboard & Jumper wire
Theory:
analogWrite() function in Arduino is used to fade an LED connected to a PWM (Pulse Width
Modulation) capable pin. Pin 9 on most Arduino boards supports PWM. The code gradually
increases the brightness of the LED from off to full brightness, then decreases the brightness
back to off, creating a fading effect. The delay() value may be adjusted to change the speed of
the fading effect.
Connection Diagram:

Code:
const int ledPin = 9;
void setup() {
// No setup required
}
void loop() {
for (int brightness = 0; brightness <= 255; brightness++) {
analogWrite(ledPin, brightness); // Set the brightness of the LED
delay(10);
}
for (int brightness = 255; brightness >= 0; brightness--) {
analogWrite(ledPin, brightness);
delay(10);
}
}
This code will gradually increase the brightness of the LED from off to full brightness, then
decrease the brightness back to off, creating a fading effect. Adjust the `delay()` value to
change the speed of the fading effect.
Procedure:
1. Connect the LED to pin 9 of the Arduino board. Make sure to use a current-limiting
resistor to protect the LED from too much current.
2. Write the Arduino code using the analogWrite() function to control the brightness of
the LED.
Practical 7
Aim: Write the steps to add blynk libraries for NodeMCU and account on IFTTT for
home automation.
Hardware Required: Following components are required:
1. Arduino Uno
2. ESP8266 Microcontroller
3. Breadboard & Jumper wire
Theory:
NodeMCU is an open-source development board based on the ESP8266 Wi-Fi module. It
features the ESP8266 microcontroller, which has inbuilt Wi-Fi capability, making it an
excellent choice for Internet of Things (IoT) projects.
Blynk is a platform that allows users to build IoT applications for controlling hardware
remotely. It provides a drag-and-drop interface to create customizable interfaces for
controlling and monitoring connected devices. Blynk offers a mobile app (available for both
iOS and Android) through which users can interact with their IoT projects.
Steps for Setting up Blynk for NodeMCU:
1. Install NodeMCU Board Package:
Open Arduino IDE. Go to File -> Preferences.
In the "Additional Board Manager URLs" field, add the NodeMCU board package URL:
`http://arduino.esp8266.com/stable/package_esp8266com_index.json
Click "OK" to close the preferences window.
Go to Tools -> Board -> Boards Manager.
Search for "esp8266" and install the package.
2. Install Blynk Library:
In Arduino IDE, go to Sketch -> Include Library -> Manage Libraries.
Search for "Blynk" and install the Blynk library.
3. Connect NodeMCU to Blynk:
Create a new project in the Blynk app (available on iOS and Android).
Obtain the authentication token provided by Blynk for your project.
In the Arduino sketch, include the Blynk library at the beginning.
Use your authentication token to connect your NodeMCU to the Blynk server.
Write your code to control the hardware connected to the NodeMCU based on Blynk app
inputs.
4. Upload Code:
Connect the NodeMCU board to your computer via USB.
Select the NodeMCU board from Tools -> Board menu.
Select the correct port from Tools -> Port menu.
Upload the code to the NodeMCU.

Integrating Blynk with IFTTT:


1. Create an IFTTT Account:
Sign up for an account on IFTTT (https://ifttt.com).
2. Connect Blynk to IFTTT:
Go to the IFTTT website or open the IFTTT app.
Search for the Blynk service and connect it to your IFTTT account.
You may need to authorize IFTTT to access your Blynk account by providing your Blynk
credentials.
3. Create Applets:
Once Blynk is connected, you can create applets to trigger actions based on Blynk events.
For example, you can create an applet that turns on a smart bulb connected to IFTTT
whenever a specific button is pressed in the Blynk app.
Follow the instructions on IFTTT to create your desired applets, specifying Blynk as the
trigger and defining the corresponding action.
4. Test and Deploy:
Test your applets to ensure they work as expected.
Once tested, deploy your home automation setup.
5. Adjust and Refine:
Fine-tune your applets and NodeMCU code as needed to optimize your home automation
system.
Monitor performance and make adjustments as necessary.
By following these steps, to set up Blynk with NodeMCU and integrate it with IFTTT home
automation system can de designed easily.
Practical 8
Aim: Write a program of Fade LED using Node MCU (ESP8266) and blynk app.
Hardware Required:
1. NodeMCU (ESP8266) development board
2. LED
3. Resistor (220 ohms)
4. Breadboard & Jumper wires.
Software Required:
1. Arduino IDE.
2. Blynk app (available on iOS and Android).
Connection Diagram:

1. Connect the cathode (shorter leg) of the LED to one of the GPIO pins on the NodeMCU
(e.g., D5).
2. Connect the anode (longer leg) of the LED to a resistor.
3. Connect the other end of the resistor to the GND pin on the NodeMCU.
4. Connect the NodeMCU to your computer via USB.
Blynk Setup:
1. Download and install the Blynk app from the App Store (iOS) or Google Play Store
(Android).
2. Create a new project in the Blynk app.
3. Add a Slider widget to the project. Set its properties:
- Pin: V0 (Virtual pin number).
- Range: 0 to 255.
4. Note down the Auth Token provided by Blynk for the project.
Code:
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
char ssid[] = "YourWiFiSSID";
char pass[] = "YourWiFiPassword";
char auth[] = "YourAuthToken";
#define PIN_SLIDER V0
#define LED_PIN D5
void setupBlynk() {
Blynk.begin(auth, ssid, pass);
}
BLYNK_WRITE(PIN_SLIDER) {
int brightness = param.asInt();
analogWrite(LED_PIN, brightness);
}
void setup() {
pinMode(LED_PIN, OUTPUT);
WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("WiFi connected");
Serial.begin(9600);
setupBlynk();
}
void loop() {
Blynk.run();
}
Procedure:
1. Open Arduino IDE.
2. Install the ESP8266 board package if you haven't already (refer to previous instructions).
3. Install the Blynk library (refer to previous instructions).
4. Copy and paste the Arduino sketch provided above into the Arduino IDE.
5. Replace `"YourWiFiSSID"`, `"YourWiFiPassword"`, and `"YourAuthToken"` with your
actual Wi-Fi credentials and the authentication token provided by Blynk.
6. Verify and upload the sketch to the NodeMCU board.
7. Open the Serial Monitor in Arduino IDE to view the connection status.
8. Open the Blynk app on your smartphone.
9. Start the project created earlier.
10. Adjust the Slider widget to control the brightness of the LED. As you slide the widget, the
LED connected to the NodeMCU will fade in and out accordingly.
Practical 9
Aim: Write a Program for Arduino by using Ultrasonic Sensors & Servo Motors (HC-
SR04) and make a Smart Dustbin
Hardware Required:
1. Arduino board (e.g., Arduino Uno).
2. HC-SR04 Ultrasonic Sensor (x 2).
3. Servo motor (SG90).
4. Jumper wires.
5. Breadboard.
6. A small container or box to act as the dustbin.
Theory:
A smart car wiper system refers to an advanced automotive system that enhances the
functionality of traditional windshield wipers by incorporating various sensors and technologies
to improve performance and efficiency
Connection Diagram:

1. Connect the VCC pin of the ultrasonic sensors to the 5V pin on the Arduino.
2. Connect the GND pin of the ultrasonic sensors to the GND pin on the Arduino.
3. Connect the TRIG pin of each ultrasonic sensor to digital pins on the Arduino (e.g., D2 and
D3).
4. Connect the ECHO pin of each ultrasonic sensor to other digital pins on the Arduino (e.g.,
D4 and D5).
5. Connect the signal wire of the servo motor to a digital pin on the Arduino (e.g., D9).
6. Connect the VCC and GND pins of the servo motor to the 5V and GND pins on the Arduino,
respectively.
Code:
#include <Servo.h>
const int trigPin1 = 2;
const int echoPin1 = 4;
const int trigPin2 = 3;
const int echoPin2 = 5;
const int servoPin = 9;
const int openDistance = 10; // in centimeters
const int closeDistance = 20; // in centimeters
Servo servo;
void setup() {
Serial.begin(9600);
pinMode(trigPin1, OUTPUT);
pinMode(echoPin1, INPUT);
pinMode(trigPin2, OUTPUT);
pinMode(echoPin2, INPUT);
servo.attach(servoPin);
servo.write(0); // Close the lid initially
}
void loop() {
int distance1 = getDistance(trigPin1, echoPin1);
int distance2 = getDistance(trigPin2, echoPin2);
if (distance1 < openDistance || distance2 < openDistance) {
openLid();
} else if (distance1 > closeDistance && distance2 > closeDistance) {
closeLid();
}
}
int getDistance(int trigPin, int echoPin) {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
long duration = pulseIn(echoPin, HIGH);
int distance = duration * 0.034 / 2;
return distance;
}
void openLid() {
servo.write(90); // Open the lid
delay(500); // Allow time for the lid to fully open
}
void closeLid() {
servo.write(0); // Close the lid
}
Procedure:
1. Set up the circuit according to the circuit setup described above.
2. Open the Arduino IDE on your computer.
3. Copy and paste the Arduino sketch provided above into the Arduino IDE.
4. Verify and upload the sketch to the Arduino board.
5. Once uploaded, you can power the Arduino board using a USB cable or an external power
source.
6. As objects are brought closer to the ultrasonic sensors, the lid of the dustbin should open
automatically. When no object is detected nearby, the lid will close.
Practical 10
Aim: Write a Program for controlling RGB LED using Blynk App.
Hardware Required:
1. Arduino board (e.g., Arduino Uno).
2. ESP8266
3. RGB LED
4. Jumper wires.
5. Breadboard
Theory:
RGB LED, is a special type of LED that contains three separate LEDs within a single package -
one each for the red, green, and blue colors. By independently controlling the intensity of each
color component, RGB LEDs can produce a wide range of colors, including white light when
all three colors are fully illuminated.To control an RGB LED using the Blynk app, we need an
ESP2866 an RGB LED, and a Blynk account.
Connection Diagram:

Code:
#define BLYNK_PRINT Serial
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
char auth[] = "YourAuthToken";
char ssid[] = "YourNetworkName";
char pass[] = "YourPassword";
void setup() {
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
}
void loop() {
Blynk.run();
}
BLYNK_WRITE(V1) {
int redValue = param.asInt();
analogWrite(9, redValue);
}
BLYNK_WRITE(V2) {
int greenValue = param.asInt();
analogWrite(10, greenValue);
BLYNK_WRITE(V3) { // Virtual Pin V3 for Blue color slider
int blueValue = param.asInt();
analogWrite(11, blueValue); // Assuming blue LED is connected to pin 11
}
Procedure:
1. Make the connections using the connection diagram
2. Upload the code in the microcontroller
3. Use Blynk app to control the LED
Practical 11
Aim: Design an Arduino based Smart Car Wiper System using Rain Sensor and Servo
Motors.
Hardware Required:
1. Arduino Uno
2. Rain sensor module
3. DC motors (for wiper control)
4. Motor driver module (to control the motors)
5. Wiper blades and arms
6. Jumper wires
7. Power source
Theory:
A smart car wiper system refers to an advanced automotive system that enhances the
functionality of traditional windshield wipers by incorporating various sensors and technologies
to improve performance and efficiency. By connecting Rain sensor module to Arduino Board
intensity of rain may be sensed. The signal can then be used to start a motor.
Connection Diagram:

Code:
#define RAIN_SENSOR_PIN A0
#define MOTOR_PIN 9
#define RAIN_THRESHOLD 500
#define WIPER_DELAY 500
void setup() {
pinMode(RAIN_SENSOR_PIN, INPUT);
pinMode(MOTOR_PIN, OUTPUT);
Serial.begin(9600);
}
void loop( ) {
int rainValue = analogRead(RAIN_SENSOR_PIN);
if (rainValue > RAIN_THRESHOLD) {
digitalWrite(MOTOR_PIN, HIGH);
delay(WIPER_DELAY);
digitalWrite(MOTOR_PIN, LOW);
}
else {
digitalWrite(MOTOR_PIN, LOW);
}
Serial.println(rainValue);
delay(100);
}
Procedure:
1. Connect the rain sensor module to the Arduino board using jumper wires. Typically, the rain
sensor has analog output, so connect it to one of the analog input pins of the Arduino.
2. Connect the motor driver module to the Arduino. The motor driver will control the DC
motors. Connect the input pins of the motor driver to digital output pins of the Arduino.
3. Connect the DC motors to the motor driver output pins.
Practical 12
Aim: Design an Arduino based Smart Agriculture system using Soil Sensor and LED.
Hardware Required:
1. Arduino Uno
2. Soil sensor module
3. LED
4. Breadboard & Jumper wires
Theory:
Soil Quality sensor can be used to sense the moisture of soil. Using Arduino board soil sensor
can be used to start a water sprinkler.
Connection Diagram:

Code:
#define SOIL_SENSOR_PIN A0 // Analog pin for soil moisture sensor
#define MOTOR_PIN 9 // Digital pin for controlling irrigation motor
#define SOIL_DRY_THRESHOLD 700 // Adjust this threshold based on sensor calibration
#define IRRIGATION_DURATION 5000 // Duration of irrigation in milliseconds
void setup() {
pinMode(SOIL_SENSOR_PIN, INPUT);
pinMode(MOTOR_PIN, OUTPUT);
Serial.begin(9600);
}
void loop() {
int soilMoisture =
analogRead(SOIL_SENSOR_PIN); if (soilMoisture
> SOIL_DRY_THRESHOLD) {
digitalWrite(MOTOR_PIN, HIGH);
delay(IRRIGATION_DURATION);
digitalWrite(MOTOR_PIN, LOW);
}
Serial.println(soilMoisture);
delay(1000); // Delay between soil moisture readings
}
Procedure:
1. Connect the soil sensor module to the Arduino board using jumper wires. Typically, the
soil sensor has analog output, so connect it to one of the analog input pins of the Arduino.
2. Connect the LED to the Arduino.
3. The circuit senses the moisture o the soil. LED glows when moisture increases above
a threshold value

You might also like