Devices & Components
Arduino Nano
lcd 16x2 I2c module
DHT22 Temperature Sensor
Hardware & Tools
Soldering iron (generic)
Breadboard, 830 Tie Points
Software & Tools
Arduino IDE
Project description
Code
Code
c_cpp
Most of the code is taken from https://create.arduino.cc/projecthub/adrakhmat/temperature-monitor-with-dht22-and-i2c-16x2-lcd-3ddd39 It needs the DHT, WIRE and I2C libraries This also display if F not C, replace line 63 with "temp" instead of "tempF" for C and change line 64
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 the DHT22 Data is connected to 15#define DHTTYPE DHT22 // DHT 22 (AM2302) 16DHT dht(DHTPIN, DHTTYPE); //// Initialize DHT sensor for normal 16mhz Arduino 17 18 19LiquidCrystal_I2C lcd(0x27, 16, 2); // I2C address 0x27, 16 column and 2 rows 20 21//Variables 22int chk; 23float hum; //Stores humidity value 24float temp; //Stores temperature value 25float tempF; 26void setup() 27{ 28 lcd.init(); // initialize the lcd 29 lcd.backlight(); 30 31 lcd.setCursor(0, 0); // move cursor to (0, 0) 32 lcd.print("Arduino"); // print message at (0, 0) 33 lcd.setCursor(2, 1); // move cursor to (2, 1) 34 lcd.print("Booting Up"); // print message at (2, 1) 35 Serial.begin(9600); 36 dht.begin(); 37 lcd.begin(16,2); 38 lcd.init(); // initialize the lcd 39 lcd.backlight(); 40} 41 42void loop() 43{ 44 45 delay(2000); 46 //Read data and store it to variables hum and temp 47 hum = dht.readHumidity(); 48 temp = dht.readTemperature(); 49 tempF = ((temp * 1.8) + 32); 50 //Print temp and humidity values to serial monitor 51 Serial.print("Humidity: "); 52 Serial.print(hum); 53 Serial.print(" %, Temp: "); 54 Serial.print(temp); 55 Serial.println(" Celsius"); 56 //Print temp and humidity values to LCD 57 lcd.setCursor(0,0); 58 lcd.print("Humidity: "); 59 lcd.print(hum); 60 lcd.print("%"); 61 lcd.setCursor(0,1); 62 lcd.print("Temp: "); 63 lcd.print(tempF); 64 lcd.println("Fahrenheit"); 65 delay(2000); //Delay 2 sec between temperature/humidity check 66 67 68}
Code
c_cpp
Most of the code is taken from https://create.arduino.cc/projecthub/adrakhmat/temperature-monitor-with-dht22-and-i2c-16x2-lcd-3ddd39 It needs the DHT, WIRE and I2C libraries This also display if F not C, replace line 63 with "temp" instead of "tempF" for C and change line 64
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 the DHT22 Data is connected to 15#define DHTTYPE DHT22 // DHT 22 (AM2302) 16DHT dht(DHTPIN, DHTTYPE); //// Initialize DHT sensor for normal 16mhz Arduino 17 18 19LiquidCrystal_I2C lcd(0x27, 16, 2); // I2C address 0x27, 16 column and 2 rows 20 21//Variables 22int chk; 23float hum; //Stores humidity value 24float temp; //Stores temperature value 25float tempF; 26void setup() 27{ 28 lcd.init(); // initialize the lcd 29 lcd.backlight(); 30 31 lcd.setCursor(0, 0); // move cursor to (0, 0) 32 lcd.print("Arduino"); // print message at (0, 0) 33 lcd.setCursor(2, 1); // move cursor to (2, 1) 34 lcd.print("Booting Up"); // print message at (2, 1) 35 Serial.begin(9600); 36 dht.begin(); 37 lcd.begin(16,2); 38 lcd.init(); // initialize the lcd 39 lcd.backlight(); 40} 41 42void loop() 43{ 44 45 delay(2000); 46 //Read data and store it to variables hum and temp 47 hum = dht.readHumidity(); 48 temp = dht.readTemperature(); 49 tempF = ((temp * 1.8) + 32); 50 //Print temp and humidity values to serial monitor 51 Serial.print("Humidity: "); 52 Serial.print(hum); 53 Serial.print(" %, Temp: "); 54 Serial.print(temp); 55 Serial.println(" Celsius"); 56 //Print temp and humidity values to LCD 57 lcd.setCursor(0,0); 58 lcd.print("Humidity: "); 59 lcd.print(hum); 60 lcd.print("%"); 61 lcd.setCursor(0,1); 62 lcd.print("Temp: "); 63 lcd.print(tempF); 64 lcd.println("Fahrenheit"); 65 delay(2000); //Delay 2 sec between temperature/humidity check 66 67 68}
Downloadable files
schematic
Arduino schematic Nano LCD I2c 5v VCC gnd gnd A4 SDA A5 SCL nano DHT22 3.3v + Data D4 (it says D2 in the schematic I couldnt change it) gnd -
schematic
Comments
Only logged in users can leave comments