Experiment 2.1: 2. Objectives

Download as pdf or txt
Download as pdf or txt
You are on page 1of 18

Experiment 2.

1
1. Aim:
Formulate distance of an object using an ultrasonic sensor.
2. Objectives:
1. Learn about IoT based simulations.
2. Testing and model in IoT based simulation platform.

3. Software Required: Tinkercad Simulation, Arduino IDE

4. Hardware Required:

 Arduino Uno R3 board


 Ultrasonic sensor (HC-SR04)
 16×2 LCD I2C Display
 Jumper Wires

5. Theory:
Arduino: It is an open-source electronics platform. It consists ATmega328 8-bit Micro controller. It
can be able to read inputs from different sensors & we can send instructions to the micro controller in
the Arduino. It provides Arduino IDE to write code & connect the hardware devices like Arduino
boards & sensors.
Ultrasonic Sensor: An ultrasonic Sensor is a device used to measure the distance between the sensor
and an object without physical contact. This device works based on time-to-distance conversion.
Working Principle of Ultrasonic Sensor: Ultrasonic sensors measure distance by sending and
receiving the ultrasonic wave. The ultrasonic sensor has a sender to emit the ultrasonic waves and a
receiver to receive the ultrasonic waves. The transmitted ultrasonic wave travels through the air and
is reflected by hitting the Object. Arduino calculates the time taken by the ultrasonic pulse wave to
reach the receiver from the sender. We know that the speed of sound in air is nearly 344 m/s. So, the
known parameters are time and speed (constant). Using these parameters, we can calculate the
distance travelled by the sound wave. Formula: Distance = Speed * Time. In the code, the “duration”
variable stores the time taken by the sound wave traveling from the emitter to the receiver. That is
double the time to reach the object, whereas the sensor returns the total time including sender to
object and object to receiver. Then, the time taken to reach the object is half of the time taken to
reach the receiver. So we can write the expression as, Distance = Speed of Sound in Air * (Time
Taken / 2).

Course Name: IoT Course Code: 21CSP-344


Lab Name: Darshit Sheth UID: 21BCS7782
6. Procedure:
Step 1. Connect the Echo pin of the sensor to the D2 pin of the Arduino.
Step 2. Connect the Trig pin of the sensor to the D3 pin of the Arduino.
Step 3. Navigate to Tools and select board and port.
Step 4. Verify and compile the code, then upload the code to the Arduino Uno R3 board.
Step 5. Monitor the output in the Serial monitor (Set the baud rate as 9600). To open Serial monitor
Tools>Serial Monitor or (Ctrl+Shift+M).

7. Code:
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x20, 16, 2); // Format -> (Address,Width,Height )
#define echoPin 2 // attach pin D2 Arduino to Echo pin of Sensor module
#define trigPin 3 // attach pin D3 Arduino to Trig pin of Sensor module
long duration; // Declare variable to store echo time duration
int distance; // Declare variable to store the result (distance)
void setup()
{
lcd.init(); // initialize the lcd
lcd.backlight(); // Turn on the Backlight
pinMode(trigPin,OUTPUT); // Sets the trigPin as an OUTPUT
pinMode(echoPin, INPUT); // Sets the echoPin as an INPUT
// Serial Communication is starting with 9600 of baudrate speed
Serial.begin(9600);
// The text to be printed in serial monitor
Serial.println("Distance measurement using Arduino Uno");
delay(500);
}
void loop()
{
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = duration * 0.0344 / 2;
Serial.print("Distance: ");
Serial.print(distance);
Serial.println(" cm");
lcd.clear(); // Clear the display buffer
lcd.setCursor(0, 0); // Set cursor for "Distance:" (Column, Row)
lcd.print("Distance:"); // print "Distance:" at (0, 0)
lcd.setCursor(0,1); // Set cursor for output value (0, 1)
lcd.print(distance); // print Output in cm at (0, 1)
Course Name: IoT Course Code: 21CSP-344
Lab Name: Darshit Sheth UID: 21BCS7782
lcd.setCursor(4, 1); // move cursor to (4, 1)
lcd.print("cm"); // print "cm" at (4, 1)
delay(1000);
delay(100);
}

8. Results:

Course Name: IoT Course Code: 21CSP-344


Lab Name: Darshit Sheth UID: 21BCS7782
9. Learning Outcomes:

a) Interfacing Ultrasonic Sensor.


b) Learnt about Arduino Uno board.
c) Implemented code on C++ language.

Course Name: IoT Course Code: 21CSP-344


Lab Name: Darshit Sheth UID: 21BCS7782
Course Name: IoT Lab Course Code: 21CSP-344
Name: Darshit Sheth UID: 21BCS7782
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

Experiment – 3.1

Aim: Interfacing Air Quality Sensor (MQ135) with Arduino.

Objectives:

1. Connections of Arduino board with MQ135 sensor.

2. How to interface MQ135 with Arduino.

Components Required:

Arduino Uno board, MQ135, Jumper wires, Arduino IDE


Output:
1. (a)Code in Arduino IDE

- int sensorValue; int

digitalValue; void setup()

Serial.begin(9600); pinMode(13,
OUTPUT);
}

void loop()

sensorValue = analogRead(A5); if
(sensorValue < 150 && sensorValue >64)

Serial.print("SENSOR VALUE = ");

Name- Darshit Sheth UID-21BCS7782


DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

Serial.print(sensorValue, DEC);
Serial.println(" (NORMAL)");
}

else

Serial.print("SENSOR VALUE = ");


Serial.print(sensorValue, DEC);
Serial.println(" (IMPURE AIR)");

delay(1000);

(b) Connections -

Name- Darshit Sheth UID-21BCS7782


DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

Result:

The air value was varying between 64 - 65.

Name- Darshit Sheth UID-21BCS7782


DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

Experiment – 2.2

Student Name: Darshit Sheth UID: 21BCS7782


Branch: BE- CSE Section/Group: 634-A
Semester: 5th Date of Performance: 3/10/2023
Subject Name: Internet of Things Lab Subject Code: 21CSP-344

1. Aim:
To investigate real-time relationship between humidity and temperature in IoT.

2. Objectives:
1. Learn about IoT based simulations.
2. Testing and model in IoT based simulation platform.

3. Components Required:
 Arduino Board
 Breadboard
 Jumper Wires
 DH11 Temperature and Humidity Sensor

4. Theory:
DH11 Sensor: DHT11 Module features a temperature & humidity sensor complex with a calibrated
digital signal output. The exclusive digital-signal-acquisition technique and temperature & humidity
sensing technology ensure high reliability and excellent long-term stability. This sensor includes an
NTC for temperature measurement and a resistive-type humidity measurement component for
humidity measurement. These are connected to a high-performance 8-bit microcontroller, offering
excellent quality, fast response, anti-interference ability, and cost-effectiveness.

5. Procedure:
A. Hardware Connections:
Connect the DHT22 sensor to the Arduino:
 VCC pin to 5V
 GND pin to GND
 DATA pin to digital pin 2
 Connect one leg of the first LED to digital pin 13 through a resistor.
 Connect one leg of the second LED to digital pin 12 through another resistor.
B. Upload Code:
 Open Arduino IDE.
 Copy and paste the provided code into a new sketch.
 Ensure that the "DHT" library is installed in the Arduino IDE.
 Select your Arduino board and COM port in the Tools menu.
 Upload the code to the Arduino.
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

C. Monitor Serial Output:


 Open the Serial Monitor in the Arduino IDE.
 Set the baud rate to 115200.
 Observe temperature and humidity data being printed in the Serial Monitor.

6. Script and Output:


#include "DHT.h"
#define DHTPIN 2
#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
int ledPin1 = 13;
int ledPin2 = 12;
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(115200);
Serial.println(F("DHT22 example!"));
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
dht.begin();
}
void loop() {
float temperature = dht.readTemperature();
float humidity = dht.readHumidity();
// Check if any reads failed and exit early (to try again).
if (isnan(temperature) || isnan(humidity)) {
Serial.println(F("Failed to read from DHT sensor!"));
return;
}
if(temperature<30)
{
digitalWrite(ledPin1, HIGH);
}
if(humidity>30)
{
digitalWrite(ledPin2, HIGH);
}
Serial.print(F("Humidity: "));
Serial.print(humidity);
Serial.print(F("% Temperature: "));
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

Serial.print(temperature);
Serial.println(F("°C "));
// Wait a few seconds between measurements.
delay(2000);
}
7. Output:
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

8. Learning Outcomes:
a) Interfacing DHT11 Sensor with Arduino.
b) Learnt about Arduino Uno board.
c) Learnt about Sensor Data Interpretation
d) Implemented code on C++ language.
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

Experiment – 2.3

Student Name: Darshit Sheth UID: 21BCS7782


Branch: BE- CSE Section/Group: 634-A
Semester: 5th Date of Performance: 10/10/2023
Subject Name: Internet of Things Lab Subject Code: 21CSP-344

1. Aim:
Assemble and Controlling of multiple actuators using Arduino Uno for any IoT Application

2. Objectives:
1. Learn about IoT based simulations.
2. Testing and model in IoT based simulation platform.

3. Components Required:
 1x Arduino
 1x LED
 1x Motor
 1x Buzzer

4. Theory:
Actuators
Servo Motors: Servomotors have three wires: power, ground, and signal. The power wire is typically
red, and should be connected to the 5V pin on the Arduino board. The ground wire is typically black
or brown and should be connected to a ground pin on the board. The signal pin is typically yellow or
orange and should be connected to PWM pin on the board. In these examples, it is pin number 9.

5. Procedure:
1. Connect the Hardware:
- Attach the servo motor's signal wire to a digital pin (e.g., pin 9), the power wire to 5V, and the
ground wire to GND on the Arduino.
2. Install Arduino IDE:
- Download and install the Arduino IDE on your computer if you haven't already.
3. Open the Sketch:
- Launch Arduino IDE and open the "Sweep" sketch.
4. Upload the Sketch:
- Connect your Arduino board to the computer via USB.
- Select the board and port in the "Tools" menu.
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

- Click "Upload" to load the sketch onto the Arduino.


5. Observe the Servo:
- Once uploaded, the servo should sweep between 0 and 180 degrees.

6. Script and Output:


#include <Servo.h>
int pos = 0;
Servo servo_9;
void setup()
{
servo_9.attach(9, 500, 2500);
}

void loop()
{
// sweep the servo from 0 to 180 degrees in steps
// of 1 degrees
for (pos = 0; pos <= 180; pos += 1) {
// tell servo to go to position in variable 'pos'
servo_9.write(pos);
// wait 15 ms for servo to reach the position
delay(15); // Wait for 15 millisecond(s)
}
for (pos = 180; pos >= 0; pos -= 1) {
// tell servo to go to position in variable 'pos'
servo_9.write(pos);
// wait 15 ms for servo to reach the position
delay(15); // Wait for 15 millisecond(s)
}
}
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

6. Output:

8. Learning Outcomes:
a) Interfacing Actuators with Arduino.
b) Learnt about Arduino Uno board.
c) Learnt about Servo motors.
d) Implemented code on C++ language.
Experiment No. – 3.2
AIM:
Case study of Agriculture 4.0 using IoT and to develop an IoT model for the agriculture sector.

COMPONENTS REQUIRED:
• 1 Arduino UNO
• 1 Resistor 1k ohm
• Jumper Wires
• Soil Moisture Sensor
• NPK Sensor
• Leaf Wetness Sensor
• Temperature and Humidity sensor

THEORY:
Introduction:
With India's population crossing 1.3 billion in 2016, a balance between the optimum population
growth and a healthy of nation is far to be achieved. The rising population, there is a need for
increased agricultural production. Irrigated agriculture has been an extremely important source
increased agricultural production. Now a days people wants to observe their work from anywhere
on their digital devices such as Smartphone and tablet or laptop. Several things were made easy
by using Internet of Thing (IoT).
Proposed System:
All the sensors i.e. moisture sensor, humidity sensor, temperature sensor, is connected to the
microcontroller 5volts of power is supplied to the micro controller. From that microcontroller a
relay gets the information about the percent of the moisture in the soil.

Name- Darshit Sheth UID-21BCS7782


Test Result:
The Smart Irrigation System is integrated into the mobile application system to enable the user to
easily monitor and control the irrigation of the farm field. On the mobile application system, there
is an interface to view data collected directly from the sensors via the help of the Firebase, which
is the cloud that creates a bridge between hardware and the cloud database. The main interface of
the mobile application is the main menu that displays the login page of the system. This is to
create a secured login for each user and to prevent others from knowing data owned by another
client. Once the user successfully login to the app, there is another menu display the options
control the irrigation system. The user has to select any of the options to go about the system. The
control option leads the user to control the water pump to either force "ON" or "OFF".

Future Scope:
Smart farming based on IoT technologies enables growers and farmers to reduce waste and
enhance productivity ranging from the quantity of fertiliser utilised to the number of journeys the
farm vehicles have made, and enabling efficient utilisation of resources such as water, electricity,
etc. IoT smart farming solutions is a system that is built for monitoring the crop field with the help
of sensors (light, humidity, temperature, soil moisture, crop health, etc.) and automating the
irrigation system.

Name- Darshit Sheth UID-21BCS7782


Conclusion

1) We conclude that this system is easy to implement and time, money and manpower saving
solution for irrigating fields.
2) A farmer should visualize his agricultural land’s moisture content from time to time and
water level of source is sufficient or not. IOT based smart irrigation system displays the values of
the sensors continuously in smart phone or on computer’s web page and farmer can operate them
anytime from and anywhere.

LEARNING OUTCOMES:
• Learnt about the iot in farming sector .

• Learnt how to connect equipment to iot to make smart device for agriculture.

Name- Darshit Sheth UID-21BCS7782

You might also like