Devices & Components
Arduino Uno Rev3
Male/Female Jumper Wires
9V battery (generic)
9V battery clip with 5.5mm/2.1mm plug
Male/Male Jumper Wires
DHT22 Temperature Sensor
White on Blue 16×2 LCD Module with I2C Backpack Module – 5V
Solderless Breadboard Full Size
USB-A to Mini-USB Cable
Project description
Code
hygroThermo.ino
c_cpp
1/* How to use the DHT-22 sensor with Arduino uno 2 Temperature and humidity sensor 3 More info: http://www.ardumotive.com/how-to-use-dht-22-sensor-en.html 4 Dev: Michalis Vasilakis // Date: 1/7/2015 // www.ardumotive.com 5*/ 6 7//Libraries 8#include <DHT.h> 9#include <Wire.h> 10#include <LCD.h> 11#include <LiquidCrystal_I2C.h> 12 13//Constants 14#define DHTPIN 4 // what pin we're connected to 15#define DHTTYPE DHT22 // DHT 22 (AM2302) 16DHT dht(DHTPIN, DHTTYPE); //// Initialize DHT sensor for normal 16mhz Arduino 17 18//ALWAYS USE THIS WITH LCD I2C and Addres 0x3F 19#define I2C_ADDR 0x3F 20#define BACKLIGHT_PIN 3 21#define En_pin 2 22#define Rw_pin 1 23#define Rs_pin 0 24#define D4_pin 4 25#define D5_pin 5 26#define D6_pin 6 27#define D7_pin 7 28LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin); 29 30//Variables 31int chk; 32float hum; //Stores humidity value 33float temp; //Stores temperature value 34 35void setup() 36{ 37 Serial.begin(9600); 38 dht.begin(); 39 lcd.begin(16,2); 40 lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE); 41 lcd.setBacklight(HIGH); 42} 43 44void loop() 45{ 46 47 delay(2000); 48 //Read data and store it to variables hum and temp 49 hum = dht.readHumidity(); 50 temp = dht.readTemperature(); 51 //Print temp and humidity values to serial monitor 52 Serial.print("Humidity: "); 53 Serial.print(hum); 54 Serial.print(" %, Temp: "); 55 Serial.print(temp); 56 Serial.println(" Celsius"); 57 58 lcd.clear(); 59 lcd.setCursor(0,0); 60 lcd.print("Temp: "); 61 lcd.print(temp); 62 lcd.print(" "); 63 lcd.print((char)223); 64 lcd.print("C"); 65 lcd.setCursor(0,1); 66 lcd.print("Hum: "); 67 lcd.print(hum); 68 lcd.print(" %"); 69 70 delay(2000); //Delay 2 sec. 71 72} 73
hygroThermo.ino
c_cpp
1/* How to use the DHT-22 sensor with Arduino uno 2 Temperature and humidity sensor 3 More info: http://www.ardumotive.com/how-to-use-dht-22-sensor-en.html 4 Dev: Michalis Vasilakis // Date: 1/7/2015 // www.ardumotive.com 5*/ 6 7//Libraries 8#include <DHT.h> 9#include <Wire.h> 10#include <LCD.h> 11#include <LiquidCrystal_I2C.h> 12 13//Constants 14#define DHTPIN 4 // what pin we're connected to 15#define DHTTYPE DHT22 // DHT 22 (AM2302) 16DHT dht(DHTPIN, DHTTYPE); //// Initialize DHT sensor for normal 16mhz Arduino 17 18//ALWAYS USE THIS WITH LCD I2C and Addres 0x3F 19#define I2C_ADDR 0x3F 20#define BACKLIGHT_PIN 3 21#define En_pin 2 22#define Rw_pin 1 23#define Rs_pin 0 24#define D4_pin 4 25#define D5_pin 5 26#define D6_pin 6 27#define D7_pin 7 28LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin); 29 30//Variables 31int chk; 32float hum; //Stores humidity value 33float temp; //Stores temperature value 34 35void setup() 36{ 37 Serial.begin(9600); 38 dht.begin(); 39 lcd.begin(16,2); 40 lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE); 41 lcd.setBacklight(HIGH); 42} 43 44void loop() 45{ 46 47 delay(2000); 48 //Read data and store it to variables hum and temp 49 hum = dht.readHumidity(); 50 temp = dht.readTemperature(); 51 //Print temp and humidity values to serial monitor 52 Serial.print("Humidity: "); 53 Serial.print(hum); 54 Serial.print(" %, Temp: "); 55 Serial.print(temp); 56 Serial.println(" Celsius"); 57 58 lcd.clear(); 59 lcd.setCursor(0,0); 60 lcd.print("Temp: "); 61 lcd.print(temp); 62 lcd.print(" "); 63 lcd.print((char)223); 64 lcd.print("C"); 65 lcd.setCursor(0,1); 66 lcd.print("Hum: "); 67 lcd.print(hum); 68 lcd.print(" %"); 69 70 delay(2000); //Delay 2 sec. 71 72} 73
Downloadable files
Schema
Schema

Fritzing Schema
Schema Fritzing
Fritzing Schema
Schema
Schema

Comments
Only logged in users can leave comments