DHT11 Sensor: Specifications

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 31

DHT11 Sensor

The DHT11 is a digital temperature and humidity sensor. It consists of a humidity


sensor and a thermistor to measure the surrounding air temperature, heat index
and humidity, and sends out a digital signal on the data pin (no analog input pin).
It is easy and simple to use sensor but it needs to be operated carefully. The only
drawback of this sensor is that it gives a delay of 2 seconds to refresh and send
data again but on our level, it is a very negligible problem.

SPECIFICATIONS

ELECTRICAL CHARACTERISTICS

The DHT11 measures relative humidity. Relative humidity is the measurement of


the amount of water vapor in air vs the saturation point of water vapor in air. At
the saturation point, water vapor condensing and begin to accumulate on surface
in form of dew.

The saturation point changes with air temperature. Cold air can hold less water
vapor before it becomes saturated, and hot air can hold more water vapor before
it becomes saturated.
The formula to calculate relative humidity is:

WORKING
When MCU sends a start signal, DHT11 changes from the low-power-consumption
mode to the
running-mode, waiting for MCU to complete the start signal. Once it is completed,
DHT11 sends a
response signal of 40-bit data that include the relative humidity and temperature
information to
MCU. Users can opt to collect (read) and store some data. Without the start signal
from MCU, DHT11
will never give back the response signal to MCU. Once data is collected, DHT11
will change to the low power-consumption mode until it receives a start signal
from MCU again
When the cable connecting the MCU and DHT11 is shorter than 20 meters a 5K
pull-up resistor is recommended. One capacitor valued 100nF can be added
between VDD and GND for power filtering.

SKETCH
 #include "DHT.h"

 #define DHTPIN 2
 #define DHTTYPE DHT11

 DHT dht(DHTPIN, DHTTYPE);

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

 dht.begin();
 }

 void loop() {
 // Wait a few seconds between measurements.
 delay(2000);

 float h = dht.readHumidity();
 float t = dht.readTemperature();
 float f = dht.readTemperature(true);
 if (isnan(h) || isnan(t) || isnan(f)) {
 Serial.println("Failed to read from DHT sensor!");
 return;
 }

 float h if = dht.computeHeatIndex(f, h);

 Serial.print("Humidity: ");
 Serial.print(h);
 Serial.print("Temperature: ");
 Serial.print(t);
 Serial.print(f);
 Serial.print("Heat index: ");
 Serial.print(hif);
 }
HC-SR04 Sensor
Ultrasonic sensor HC - SR04 provides 2cm -
400cm range of measurement. The modules consist of ultrasonic transmitters,
receiver and control circuit. The basic principle of work is as follows;

(1) It uses IO trigger for at least 10us high level signal,


(2) The Module automatically sends eight 40 kHz signals and detects whether
there is a pulse signal back.
(3) If the signal comes back through high level, time of high output IO duration is
the time from sending ultrasonic to returning.

Test distance = (high level time velocity of sound (340M/S) / 2

It emits an ultrasonic wave at 40 000 Hz which travels through the air and if there
is an object or obstacle on its path, it will bounce back to the module. Considering
the travel time and the speed of the sound, we can measure the distance. The HC-
SR04 Ultrasonic Module has 4 pins, Ground, VCC, Trig and Echo. The Ground and
the VCC pins of the module needs to be connected to the Ground and the 5 volts
pins on the Arduino Board respectively and the trig and echo pins are connected
to any Digital I/O pin on the Arduino Board. For example, if the object is 10 cm
away from the sensor, and the speed of the sound is 340 m/s or 0.034 cm/µs the
sound wave will need to travel about 294 u seconds. But we will get the double of
the value of that number because the sound wave needs to travel forward and
return backward. So in order to get the distance in cm, we need to multiply the
received travel time value from the echo pin by 0.034 and divide it by 2.

SKETCH
. #define trigPin 16
#define echoPin 17
int Buzzer = 18;

void setup() {
pinMode(trigPin, OUTPUT);
pinMode(Buzzer, OUTPUT);
pinMode(echoPin, INPUT);

void loop() {
int distance, duration;
digitalWrite(trigPin, HIGH);
delayMicroseconds(2000);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin,HIGH);
distance = (duration/2) / 29.1;
if (distance >= 100 || distance <= 0){
digitalWrite(Buzzer, LOW);

}
else {
Serial.println("Motion detected");
tone(Buzzer, 400);
delay(100);
tone(Buzzer, 800);
delay(100);
tone(Buzzer, 400);
delay(100);
tone(Buzzer, 800);
delay(100);
tone(Buzzer, 400);
delay(100);
tone(Buzzer, 800);
delay(100);
}
delay(400);
}
4*4 Keypad Password Lock

Whenever the keys are pressed, they are matched with the keys already stored. If
the keys that are pressed match the initial password stored in the EEPROM which
is ‘1234’, then the lock will open up. If the password does not match, then it will
print “access denied” on the LCD.If the ‘#’ key will be pressed, it will ask you to
enter the current password and if it matches, then it will ask you to enter the new
password and the password will be changed.

First of all, we will include the libraries for the 4X4 keypad, LCD, and a library for
storing the password. The EEPROM library is used to store the password. The
default password stored in it is ‘1234’.The keys pressed are stored in the
‘password’ variable and these are shown on the LCD when the keys are pressed.
Then these keys will be matched with the initial password stored in the EEPROM.
If the keys that were pressed match the initial password, then the lock will get
open and “Pass accepted” will be printed on the LCD. If the password does not
match, then it will ask to enter the password again .If the ‘#’ key is pressed, then it
will call the ‘change()’ function. In the change function, it will ask you to enter the
current password. If the current password is correct, then it will ask you to enter
the new password. Upon entering the new password, the password will be
changed.
Sketch
#include <Keypad.h>

#include<LiquidCrystal.h>

#include<EEPROM.h>

#include "DHT.h"

#define DHTPIN 8

#define DHTTYPE DHT11

DHT dht(DHTPIN, DHTTYPE);

int distance, duration;

int trigPin=11;

int echoPin=12;

int Buzzer =13;

int dht_pin=8;
LiquidCrystal liquid_crystal_display(14,15,16,17,18,19,);

char password[4];

char saved_password[4];

int i=0;

int door_pin = 10;

char key_pressed=0;

const byte rows = 4;

const byte columns = 4;

char matrix[rows][columns] = {

{'1','2','3','A'},

{'4','5','6','B'},

{'7','8','9','C'},
{'*','0','#','D'}

};

byte row_pins[rows] = {0,1,2,3};

byte column_pins[columns] = {4,5,6,7};

Keypad keypad_key = Keypad( makeKeymap(matrix), row_pins, column_pins,


rows, columns);

void setup()

dht.begin();

pinMode(dht_pin, INPUT);

pinMode(trigPin, OUTPUT);
pinMode(Buzzer, OUTPUT);

pinMode(echoPin, INPUT);

pinMode(door_pin, OUTPUT);

liquid_crystal_display.begin(16,2);

liquid_crystal_display.print("WIFI BASED AUTOMATION with DATA LOGGING &


INTELLIGENT SECURITY");

liquid_crystal_display.setCursor(0,1);

delay(2000);

initialpassword();

}
void loop()

delay(1000)

digitalWrite(trigPin, HIGH);

delayMicroseconds(2000);

digitalWrite(trigPin, LOW);

duration = pulseIn(echoPin,HIGH);

distance = (duration/2) / 29.1;

if (distance >= 100 || distance <= 0){

digitalWrite(Buzzer, LOW);

else {

liquid_crystal_display.clear();

liquid_crystal_display.print("Motion detected");

tone(Buzzer, 400);

delay(100);

tone(Buzzer, 800);
delay(100);

tone(Buzzer, 400);

delay(100);

tone(Buzzer, 800);

delay(100);

tone(Buzzer, 400);

delay(100);

tone(Buzzer, 800);

delay(100);

delay(400);

temphumidity();

delay(100);

digitalWrite(door_pin,LOW);

liquid_crystal_display.clear();

liquid_crystal_display.print("Enter Password");

liquid_crystal_display.setCursor(0,1);

key_pressed = keypad_key.getKey();
if(key_pressed=='#')

change();

if (key_pressed)

password[i++]=key_pressed;

liquid_crystal_display.print(key_pressed);

if(i==4)

delay(200);

for(int j=0;j<4;j++)
saved_password[j]=EEPROM.read(j);

if(!(strncmp(password, saved_password,4)))

liquid_crystal_display.clear();

liquid_crystal_display.print("CORRECT");

digitalWrite(door_pin, HIGH);

delay(1000);

liquid_crystal_display.setCursor(0,1);

liquid_crystal_display.print("Pres # to change");

delay(1000);

liquid_crystal_display.clear();
liquid_crystal_display.print("Enter Password:");

liquid_crystal_display.setCursor(0,1);

i=0;

else

digitalWrite(door_pin, LOW);

liquid_crystal_display.clear();
liquid_crystal_display.print("Wrong Password");

liquid_crystal_display.setCursor(0,1);

liquid_crystal_display.print("Pres # to Change");

delay(2000);

liquid_crystal_display.clear();

liquid_crystal_display.print("Enter Password");

liquid_crystal_display.setCursor(0,1);

i=0;

}
}

void change()

int j=0;

liquid_crystal_display.clear();

liquid_crystal_display.print("Current Password");

liquid_crystal_display.setCursor(0,1);

while(j<4)

char key=keypad_key.getKey();

if(key)
{

password[j++]=key;

liquid_crystal_display.print(key);

key=0;

delay(500);

if((strncmp(password, initial_password, 4)))


{

liquid_crystal_display.clear();

liquid_crystal_display.print("Wrong Password");

delay(1000);

else

j=0;

liquid_crystal_display.clear();

liquid_crystal_display.print("Enter New Password:");

liquid_crystal_display.setCursor(0,1);
while(j<4)

char key=keypad_key.getKey();

if(key)

saved_password[j]=key;

liquid_crystal_display.print(key);

EEPROM.write(j,key);

j++;

}
}

liquid_crystal_display.print("Pass Changed");

delay(1000);

liquid_crystal_display.clear();

liquid_crystal_display.print("Enter Password");

liquid_crystal_display.setCursor(0,1);

key_pressed=0;

void temphumidity(){
delay(2000);

float h = dht.readHumidity();

float t = dht.readTemperature();

float f = dht.readTemperature(true);

if (isnan(h) || isnan(t) || isnan(f)) {

liquid_crystal_display.print("Failed to read from DHT sensor!");

return;

float hif = dht.computeHeatIndex(f, h);

liquid_crystal_display.clear();

liquid_crystal_display.print("Humidity,Temp= ");

liquid_crystal_display.print(h);

liquid_crystal_display.print(t);

liquid_crystal_display.setCursor(0,1);

delay(3000)

}
void initialpassword(){

for(int j=0;j<4;j++)

EEPROM.write(j, j+49);

for(int j=0;j<4;j++)

initial_password[j]=EEPROM.read(j);

2N2222
They are designed for high spee switching application at collector current up to
500mA, and feature useful current gain over a wide range of collector current,
low leakage currents and low saturation voltage.For the time being, arduino is the
Nano-technology with almost 40mA input or output current. This value of current
is enough to light a single LED but you may need to light several LEDs using a
single pin. For this purpose one may use a transistor as a switch while controlled
with arduino.Here the 2N2222 transistor is used which can endure upto 800mA
current and 40V voltage.

Here,it is being operate as “ON/OFF” type solid state switch by biasing the
transistors Base terminal v

1N4007
1N4007 is used as a “flywheel diode”, also known as a freewheeling diode, is
connected across the relay coil. This flywheel diode clamps the reverse voltage
across the coil to about 0.7V dissipating the stored energy and protecting the
switching transistor

1N5400 DIODE

TECHNICAL SPECIFICATIONS
Vr - Reverse Voltage: 50 V

If - Forward Current: 3A

Type: Standard Recovery Rectifiers

Configuration: Single

Vf - Forward Voltage: 1V

Reverse Current: 10 uA

Recovery Time: -

Minimum Operating Temperature: - 65 C

Maximum Operating Temperature: + 150 C

We are using 1N5400 diode in power supply’s bridge rectifier because we our
current requitement is max 1.5A and it can support efficiently upto 3A.

CALCULATIONS

2N2222 base resistor

 R(base)=(Vin-Vbe)/base current
 I(base)=Ic/B

(5V-0.7V)/4mA ≈1k resistor

Filtering Capacitor

You might also like