squatchmc
Published

Arduino Nano DHT22 LCD 16x2 I2C temp and humidity display

Desktop temp and humid sensor

IntermediateShowcase (no instructions)9,063
Arduino Nano DHT22 LCD 16x2 I2C temp and humidity display

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
DHT22 Temperature Sensor
DHT22 Temperature Sensor
×1
lcd 16x2 I2c module
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Breadboard, 830 Tie Points
Breadboard, 830 Tie Points
Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Schematics

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 -

Code

Code

C/C++
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
/* How to use the DHT-22 sensor with Arduino uno
   Temperature and humidity sensor
   More info: http://www.ardumotive.com/how-to-use-dht-22-sensor-en.html
   Dev: Michalis Vasilakis // Date: 1/7/2015 // www.ardumotive.com 
*/

//Libraries
#include <DHT.h>
#include <Wire.h> 
//#include <lcd.h>
#include <LiquidCrystal_I2C.h>

//Constants
#define DHTPIN 4 // what pin the DHT22 Data is connected to
#define DHTTYPE DHT22   // DHT 22  (AM2302)
DHT dht(DHTPIN, DHTTYPE); //// Initialize DHT sensor for normal 16mhz Arduino


LiquidCrystal_I2C lcd(0x27, 16, 2); // I2C address 0x27, 16 column and 2 rows

//Variables
int chk;
float hum;  //Stores humidity value
float temp; //Stores temperature value
float tempF;
void setup()
{
  lcd.init(); // initialize the lcd
  lcd.backlight();

  lcd.setCursor(0, 0);         // move cursor to   (0, 0)
  lcd.print("Arduino");        // print message at (0, 0)
  lcd.setCursor(2, 1);         // move cursor to   (2, 1)
  lcd.print("Booting Up"); // print message at (2, 1)
  Serial.begin(9600);
  dht.begin();
  lcd.begin(16,2);
  lcd.init(); // initialize the lcd
  lcd.backlight();
}

void loop()
{
  
  delay(2000);
  //Read data and store it to variables hum and temp
  hum = dht.readHumidity();
  temp = dht.readTemperature();
  tempF = ((temp * 1.8) + 32);
  //Print temp and humidity values to serial monitor
  Serial.print("Humidity: ");
  Serial.print(hum);
  Serial.print(" %, Temp: ");
  Serial.print(temp);
  Serial.println(" Celsius");
  //Print temp and humidity values to LCD
  lcd.setCursor(0,0);
  lcd.print("Humidity: ");
  lcd.print(hum);
  lcd.print("%");
  lcd.setCursor(0,1);
  lcd.print("Temp: "); 
  lcd.print(tempF);
  lcd.println("Fahrenheit");
  delay(2000); //Delay 2 sec between temperature/humidity check


}

Credits

squatchmc

squatchmc

0 projects • 0 followers

Comments