Skip to content

Instantly share code, notes, and snippets.

@PiotrKrosniak
Last active January 1, 2017 16:54
Show Gist options
  • Save PiotrKrosniak/32d714b0c11b4c67e75dee0accb23361 to your computer and use it in GitHub Desktop.
Save PiotrKrosniak/32d714b0c11b4c67e75dee0accb23361 to your computer and use it in GitHub Desktop.
// This tutorial is based on Arduino UNO R3 // and DHT11 Sensor + LCD 16x2 with I2C Board // Enjoy and visit my blog piotrgisworks.blogspot.com
/*-----( WELCOME )-----*/
// This tutorial is based on Arduino UNO R3
// and DHT11 Sensor + LCD 16x2 with I2C Board
// Enjoy and visti my blog piotrgisworks.blogspot.com
/*-----( Import needed libraries )-----*/
#include <Wire.h> // Comes with Arduino IDE
#include <dht.h> // Download from https://github.com/adafruit/DHT-sensor-library
// Get the LCD I2C Library here:
// https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads
// Move any other LCD libraries to another folder or delete them
// See Library "Docs" folder for possible commands etc.
#include <LiquidCrystal_I2C.h>
dht DHT;
#define DHT11_PIN 7 //Declare sensor pin on Your Arduino UNO Board
/*-----( Declare Constants )-----*/
/*-----( Declare objects )-----*/
// set the LCD address to 0x27 for a 16 chars 2 line display
// A FEW use address 0x3F
// Set the pins on the I2C chip used for LCD connections:
// addr, en,rw,rs,d4,d5,d6,d7,bl,blpol
LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Set the LCD I2C address
/*-----( Declare Variables )-----*/
//NONE
void setup() /*----( SETUP: RUNS ONCE )----*/
{
lcd.begin(16,2); // initialize the lcd for 16 chars 2 lines, turn on backlight
// ------- Quick 3 blinks of backlight , just for fun -------------
for(int i = 0; i< 3; i++)
{
lcd.backlight();
delay(250);
lcd.noBacklight();
delay(250);
}
lcd.backlight(); // finish with backlight on
//-------- Write characters on the display ------------------
// NOTE: Cursor Position: (CHAR, LINE) start at 0
lcd.setCursor(0,0);
lcd.print("Hello, world!"); //Welcome Message
delay(1000);
lcd.setCursor(0,1);
lcd.print("Second Line");
delay(8000); // Delay betwen first screen and sensor data
}
void loop() /*----( LOOP: RUNS CONSTANTLY )----*/
// Display Temp and Humidity to LCD
{
lcd.clear();
lcd.setCursor(0,0); //Start at character 0 on line 0
int chk = DHT.read11(DHT11_PIN);
lcd.print("Temp: ");
lcd.print(DHT.temperature); //Read tempreature from DHT11 Sensor
lcd.print((char)223);
lcd.print("C");
lcd.setCursor(0,1);//Start at character 0 on line 1
lcd.print("Humidity: ");
lcd.print(DHT.humidity);//Read humidity from DHT11 Sensor
lcd.print("%");
delay(1000); //Set sensor data refresh time
}
/* ( THE END ) */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment