Using
Libraries and
DHT11 Sensor
with Arduino
● Installing Arduino Libraries
Overview ● Importing and Using Libraries
● Introduction to DHT11 Sensor
● Project: Measuring Temperature
and Humidity with DHT11
Installing Arduino Libraries
Definition:
What are Arduino ● Libraries are collections of code that make it easy to connect to
a sensor, display, module, etc.
Libraries? Purpose:
● Simplify complex tasks by providing pre-written functions.
Steps:
How to Install ● Open the Arduino IDE.
Libraries ● Go to "Sketch" > "Include Library" >
"Manage Libraries...
Using Library Manager:
● Search for the desired library.
Library Manager ● Click "Install" to add the library to your IDE.
Example:
● Installing the DHT sensor library.
Importing and Using
Libraries
Syntax:
● #include <LibraryName.h>
Importing Libraries Example:
in Your Code ● #include <DHT.h>
Syntax:
● Create an instance of the library class.
Initializing Libraries Example:
● DHT dht(DHTPIN, DHTTYPE);
Example Functions:
● dht.begin();
Using Library ● float humidity = dht.readHumidity();
● float temperature = dht.readTemperature();
Functions
Introduction to DHT11
Sensor
Definition:
● The DHT11 is a basic, low-cost digital temperature and
humidity sensor.
Components:
● Sensor module with temperature and humidity sensors.
What is the DHT11
Sensor?
● Working Principle:
○ Uses a thermistor and a capacitive humidity
sensor.
● Output:
○ Digital signal with temperature and humidity
data.
How the DHT11
Sensor Works
Specifications:
● Temperature Range: 0-50°C
● Humidity Range: 20-90%
● Accuracy: ±2°C, ±5% humidity
DHT11 Sensor
Specifications
Project: Measuring
Temperature and Humidity with
DHT11
Objective:
● Measure and display temperature and humidity using the
Project Overview DHT11 sensor.
Components:
● Arduino, DHT11 sensor, Breadboard, Jumper wires.
● Connections:
○ VCC to 5V, GND to GND, Data to digital pin 2.
Building the Circuit
Writing the Code - Part
Setup:
Explanation of the ● Initialize the serial communication and
Code DHT sensor.
Loop:
● Read temperature and humidity
values.
● Check if readings are valid.
● Print values to the Serial Monitor.
No Readings:
Common Issues and ● Check connections and wiring.
Troubleshooting
Invalid Readings:
● Ensure correct sensor type is
defined (DHTTYPE DHT11).
Summary:
● Learned how to install and use Arduino libraries.
Key Takeaways ● Worked with the DHT11 sensor to measure temperature and
humidity.
Next Steps:
● Explore more sensors and libraries for your Arduino projects.