Skip to content

Instantly share code, notes, and snippets.

@tyrelsouza
Created June 21, 2018 01:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tyrelsouza/b83b11bd171693a62481ebe25f344e96 to your computer and use it in GitHub Desktop.
Save tyrelsouza/b83b11bd171693a62481ebe25f344e96 to your computer and use it in GitHub Desktop.
// include the library code:
#include <dht.h>
#define dht_apin A0
#include <LiquidCrystal.h>
dht DHT;
// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2, temp = dht_apin;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
Serial.begin(9600);
delay(500);
Serial.println("DHT11 Humidity & temperature sensor\n\n");
delay(1000);
Serial.print(DHT.temperature);
Serial.print("C ");
}
void loop() {
/* Only update every 1 second */
int timer = (millis() % 1000);
if (timer != 0) {
// if timer is not 0, then return and skip the rest of the function
return;
}
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 0);
lcd.print("Temperature is");
int throwaway = DHT.read11(dht_apin);
float celsius = DHT.temperature; // Read temp from sensor
Serial.print(celsius);
lcd.print(celsius);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment