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

Iot 5 6

The document outlines two experiments involving Arduino: interfacing DHT11/DHT22 sensors for measuring temperature and humidity, and interfacing the HC-SR04 ultrasonic sensor for distance measurement. It details the theory, working principles, hardware requirements, circuit diagrams, and Arduino code for each experiment. Additionally, it includes viva voce questions addressing key concepts related to the sensors.

Uploaded by

aakshargarg
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 views8 pages

Iot 5 6

The document outlines two experiments involving Arduino: interfacing DHT11/DHT22 sensors for measuring temperature and humidity, and interfacing the HC-SR04 ultrasonic sensor for distance measurement. It details the theory, working principles, hardware requirements, circuit diagrams, and Arduino code for each experiment. Additionally, it includes viva voce questions addressing key concepts related to the sensors.

Uploaded by

aakshargarg
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/ 8

EXPERIMENT-5

Aim:
To interface DHT11/DHT22 sensor with ARDUINO and write a program to measure the
temperature and humidity of the surroundings.

Theory:
1. Introduction
The DHT11 and DHT22 sensors are popular humidity and temperature sensors that provide
calibrated digital output. These sensors are commonly used in weather stations, environmental
monitoring, and home automation projects. The DHT11 is more affordable but less accurate
and has a slower response time compared to the DHT22, which provides more precise data.
In this practical, we will interface a DHT11/DHT22 sensor with an Arduino microcontroller to
measure the temperature and humidity of the surroundings.
2. Working Principle
The DHT11 and DHT22 sensors consist of two parts:
• A humidity sensor that senses relative humidity by measuring the resistance of a
material that varies with moisture.
• A thermistor that senses temperature by varying its resistance with changes in
temperature.
The sensor measures these quantities and converts them into a digital signal, which can be read
by microcontrollers like Arduino.
3. Differences Between DHT11 and DHT22

Specification DHT11 DHT22

Temperature Range 0-50°C -40-80°C

Humidity Range 20-80% RH 0-100% RH

Temperature Accuracy ±2°C ±0.5°C

Humidity Accuracy ±5% RH ±2-5% RH

Sampling Rate 1 Hz (1 second) 0.5 Hz (2 seconds)

Pin Configuration 3 or 4 pins 4 pins

4. Hardware Requirements
• Arduino (Uno, Mega, or any compatible board)
• DHT11 or DHT22 sensor
• 10kΩ pull-up resistor (for data pin)
• Jumper wires
• Breadboard
• Power supply (from Arduino)
5. Pin Configuration
The DHT11 and DHT22 sensors typically have three or four pins:
1. VCC: Power supply (3.3V or 5V).
2. GND: Ground.
3. DATA: Serial data output.
4. NC (Optional): Not connected (only in DHT22).
The DATA pin requires a pull-up resistor (typically 10kΩ) to ensure stable communication.
6. Circuit Diagram
1. VCC of the sensor connects to the 5V pin of the Arduino.
2. GND of the sensor connects to the GND of the Arduino.
3. DATA pin connects to any digital input pin of the Arduino (e.g., Pin 2), with a 10kΩ
pull-up resistor between VCC and DATA.
7. Software Requirements
• Arduino IDE installed on your PC.
• DHT sensor library (DHT.h) by Adafruit to facilitate reading data from the sensor.

Arduino Code:
const int analogIn = A0;
int humiditysensorOutput = 0;
int RawValue= 0;
double Voltage = 0;
double tempC = 0;
double tempF = 0;

void setup(){
Serial.begin(9600);
pinMode(A1, INPUT);
}

void loop(){

RawValue = analogRead(analogIn);
Voltage = (RawValue / 1023.0) * 5000;
tempC = (Voltage-500) * 0.1;
Serial.print("\t Temperature in C = ");
Serial.print(tempC,1);
humiditysensorOutput = analogRead(A1);
Serial.print("\t Humidity: ");
Serial.print(map(humiditysensorOutput, 0, 1023, 10, 70));
Serial.println("%");

delay(5000);

}
Viva Voce:
What is the difference between DHT11 and DHT22 sensors?
• DHT11 is less accurate, has a narrower measurement range, and a slower sampling rate
compared to DHT22, which is more accurate, has a wider range, and faster response.

Why do we use a pull-up resistor with the DHT sensor?


• The pull-up resistor is used on the DATA pin to ensure stable communication between
the sensor and Arduino by keeping the line in a defined state when idle.

How does the DHT sensor measure humidity?


• The DHT sensor uses a resistive humidity sensor, where the resistance changes
according to the amount of moisture in the air, which is then converted to a digital
signal.

What is the role of the dht.begin() function in the code?


• dht.begin() initializes the communication between the Arduino and the DHT sensor,
preparing it to start sending data.

What is the heat index, and why is it calculated?


• The heat index represents the "feels-like" temperature by considering both the air
temperature and humidity, giving a more accurate measure of how hot it feels to
humans.
EXPERIMENT-6

Aim:
To interface Ultrasonic sensor (HC-SR04) with ARDUINO and write a program to measure
and print distance readings.

Theory:
1. Introduction
The HC-SR04 ultrasonic sensor is widely used for measuring distance by emitting ultrasonic
waves and detecting the time taken for the echo to return. It is commonly used in robotics,
obstacle detection, and distance measurement projects. The sensor provides accurate readings
for distances ranging from 2 cm to 400 cm.
2. Working Principle
The HC-SR04 sensor works on the principle of echo-location:
• The sensor has two components: a transmitter (which emits ultrasonic waves) and a
receiver (which listens for the reflected waves or echo).
• The sensor sends out an ultrasonic pulse at a frequency of 40 kHz through the trigger
pin.
• When the pulse hits an object, it reflects back, and the sensor’s echo pin detects the
returning wave.
• The time interval between sending the pulse and receiving the echo is used to calculate
the distance of the object.
3. Ultrasonic Sensor Specifications
• Operating voltage: 5V DC
• Measuring range: 2 cm to 400 cm
• Accuracy: ±3 mm
• Operating frequency: 40 kHz
4. Pin Configuration
The HC-SR04 has four pins:
1. VCC: Power supply (5V).
2. GND: Ground.
3. TRIG: Trigger pin to send the ultrasonic pulse.
4. ECHO: Echo pin to receive the reflected signal.
5. Hardware Requirements
• Arduino board (e.g., Uno, Mega, or any compatible model)
• HC-SR04 ultrasonic sensor
• Jumper wires
• Breadboard
• Power supply (from Arduino)
6. Circuit Diagram
• VCC of the sensor connects to the 5V pin of the Arduino.
• GND of the sensor connects to the GND of the Arduino.
• TRIG pin connects to any digital output pin of the Arduino (e.g., Pin 9).
• ECHO pin connects to any digital input pin of the Arduino (e.g., Pin 10).

Arduino Code:
const int trigPin = 9;
const int echoPin = 10;
// defining variables
long duration;
int distance;
void setup() {
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input
Serial.begin(9600); // Starts the serial communication
}
void loop() {
// Clears the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);
// Calculating the distance
distance= duration*0.034/2;
// Prints the distance on the Serial Monitor
Serial.print("Distance: ");
Serial.println(distance);
}
Viva Voce:
What is the working principle of the HC-SR04 sensor?
• The HC-SR04 sensor emits ultrasonic waves and measures the time it takes for the echo
to return after hitting an object, calculating the distance based on this time.

Why do we divide the duration by 2 in the distance calculation?


• We divide by 2 because the ultrasonic wave travels to the object and back, so the total
time is for a round trip, but we need the distance in one direction.

What is the purpose of the pulseIn() function in the Arduino code?


• The pulseIn() function measures the time the ECHO pin stays HIGH, which
corresponds to the time taken for the ultrasonic pulse to hit an object and return.

What is the maximum and minimum range of the HC-SR04 sensor?


• The HC-SR04 sensor has a measuring range of 2 cm to 400 cm.

How does the speed of sound affect distance measurement?


• The sensor calculates distance based on the time taken by sound to travel. The speed of
sound is approximately 343 m/s, and this value is used to convert the time taken by the
echo into a distance.

You might also like