Advertisement
GoldySlime

DHT11_LCD

Dec 15th, 2019
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //This code is to use with DHT11 Temperature/humidity sensor with LCD i2c screen
  2. //We measure the values of the temperature and humidity then print them on the screen every second
  3. //Refer to Surtrtech channel on youtube or blogger for more information or how to use the LCD i2c
  4.  
  5. #include <dht.h> //DHT and LCD libraries
  6. #include <LiquidCrystal_I2C.h>
  7.  
  8. #define I2C_ADDR 0x27
  9. #define BACKLIGHT_PIN 3
  10. #define En_pin 2
  11. #define Rw_pin 1
  12. #define Rs_pin 0
  13. #define D4_pin 4
  14. #define D5_pin 5
  15. #define D6_pin 6
  16. #define D7_pin 7
  17.  
  18. LiquidCrystal_I2C lcd(0x27, 16, 2);
  19.  
  20. dht DHT; //Declaring the DHT as a dht type to use it later
  21.  
  22. #define DHT11_PIN 7 //Declaring where the DHT signal pin is wired
  23.  
  24. void setup(){
  25.   Serial.begin(9600);
  26.   lcd.begin();
  27.   lcd.backlight();
  28. }
  29.  
  30. void loop()
  31. {
  32.   lcd.clear();
  33.   lcd.setCursor(0,0);
  34.   int chk = DHT.read11(DHT11_PIN); //Reading data from the module
  35.   lcd.print("Temp: ");
  36.   lcd.print(DHT.temperature); //Showing temperature value (before that you can do some math to get the temperature in Farnheit)
  37.   lcd.print(" C");
  38.   lcd.setCursor(0,1);
  39.   lcd.print("Humidity: ");
  40.   lcd.println(DHT.humidity); //Showing humidity percentage
  41.   lcd.print(" %");
  42.   delay(3000); //Refreshing every 1s
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement