Tutorial on temp and humidity sensor.
As i searched on internet, there are so many different types of sensors which can provide us the temp and humidity values but we need the controllers to read the temp- humidity values in PC. As per my research , if you are searching the temp sensor with inbuilt controller then the cost will be high. So, i have used AtMega 328 cheaper and best to start up.
The DHT22 Temperature and Humidity Sensor can be operated with the help of DHT22 library. The RHT03 Temperature and humidity sensor is equivalent to DHT22 sensor and so can be operated with the same library i.e. DHT22.
The library can be downloaded from the following link:
DHT22 Library
The wiring of the Sensor with Arduino is shown below:
The pin configuration of the sensor is:
Pin1- +5V
Pin2- Data
Pin3- NULL
Pin4- GND
You need to add an extra resistor of 10K between the data pin and the positive supply pin.
After physically connecting the arduino with the Sensor, you need to add the DHT22 library in the Arduino Software.
Follow the steps to add a library in the ARDUINO Sketch:
1. Download the DHT22 library from the link given below:
DHT22 Library
2. Extract the files from the DHT22.zip
3. Copy the complete DHT22 folder and paste it to ..\Arduino\libraries\
4. Now in order to check whether the library has been added, open the arduino window. Then click on the Sketch Tab and then on the Import Library. The DHT22 library will be shown on the top. This confirm that the library has been added successfully to software
Now copy the following code to the editor:
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#include <DHT22.h>
// Data wire is plugged into port 2 on the Arduino
// Connect a 4.7K resistor between VCC and the data pin (strong pullup)
#define DHT22_PIN2
// Setup a DHT22 instance
DHT22 myDHT22(DHT22_PIN);
void setup(void)
{
// start serial port
Serial.begin(9600);
Serial.println("DHT22 Library Demo");
}
void loop(void)
{
DHT22_ERROR_t errorCode;
delay(2000);
Serial.print("Requesting data...");
errorCode = myDHT22.readData();
if(errorCode == DHT_ERROR_NONE)
{
Serial.print("Got Data ");
Serial.print(myDHT22.getTemperatureC());
Serial.print("C ");
Serial.print(myDHT22.getHumidity());
Serial.println("%");
}
else
{
Serial.print("Error Code ");
Serial.print(errorCode);
Serial.println(" readData Failed");
}
}
As i searched on internet, there are so many different types of sensors which can provide us the temp and humidity values but we need the controllers to read the temp- humidity values in PC. As per my research , if you are searching the temp sensor with inbuilt controller then the cost will be high. So, i have used AtMega 328 cheaper and best to start up.
The DHT22 Temperature and Humidity Sensor can be operated with the help of DHT22 library. The RHT03 Temperature and humidity sensor is equivalent to DHT22 sensor and so can be operated with the same library i.e. DHT22.
The library can be downloaded from the following link:
DHT22 Library
The wiring of the Sensor with Arduino is shown below:
The pin configuration of the sensor is:
Pin1- +5V
Pin2- Data
Pin3- NULL
Pin4- GND
You need to add an extra resistor of 10K between the data pin and the positive supply pin.
After physically connecting the arduino with the Sensor, you need to add the DHT22 library in the Arduino Software.
Follow the steps to add a library in the ARDUINO Sketch:
1. Download the DHT22 library from the link given below:
DHT22 Library
2. Extract the files from the DHT22.zip
3. Copy the complete DHT22 folder and paste it to ..\Arduino\libraries\
4. Now in order to check whether the library has been added, open the arduino window. Then click on the Sketch Tab and then on the Import Library. The DHT22 library will be shown on the top. This confirm that the library has been added successfully to software
Now copy the following code to the editor:
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#include <DHT22.h>
// Data wire is plugged into port 2 on the Arduino
// Connect a 4.7K resistor between VCC and the data pin (strong pullup)
#define DHT22_PIN2
// Setup a DHT22 instance
DHT22 myDHT22(DHT22_PIN);
void setup(void)
{
// start serial port
Serial.begin(9600);
Serial.println("DHT22 Library Demo");
}
void loop(void)
{
DHT22_ERROR_t errorCode;
delay(2000);
Serial.print("Requesting data...");
errorCode = myDHT22.readData();
if(errorCode == DHT_ERROR_NONE)
{
Serial.print("Got Data ");
Serial.print(myDHT22.getTemperatureC());
Serial.print("C ");
Serial.print(myDHT22.getHumidity());
Serial.println("%");
}
else
{
Serial.print("Error Code ");
Serial.print(errorCode);
Serial.println(" readData Failed");
}
}

No comments:
Post a Comment