Skip to content

Instantly share code, notes, and snippets.

@greggjaskiewicz
Created September 5, 2020 21:03
Show Gist options
  • Save greggjaskiewicz/5e2f6eb641149e16d43f44509634a229 to your computer and use it in GitHub Desktop.
Save greggjaskiewicz/5e2f6eb641149e16d43f44509634a229 to your computer and use it in GitHub Desktop.
nodeMCU DH11 and display
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
#include <DHT.h>
#include <DHT_U.h>
int D0 = 16;
int D1 = 5;
int D2 = 4;
int D3 = 0;
int D4 = 2;
int D5 = 14;
int D6 = 12;
int D7 = 13;
int D8 = 15;
int RX = 3;
LiquidCrystal_I2C lcd(0x27,16,2);
#define DHTPIN D0 // Pin which is connected to the DHT sensor.
#define DHTTYPE DHT11 // DHT 11
//#define DHTTYPE DHT22 // DHT 22 (AM2302)
//#define DHTTYPE DHT21 // DHT 21 (AM2301)
DHT_Unified dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(115200);
Wire.begin(D2, D1);
dht.begin();
lcd.begin(16, 2);
lcd.home();
// Print a message to the LCD.
lcd.print("hello, world!");
lcd.backlight();
}
// the loop function runs over and over again forever
void loop() {
delay(1000);
lcd.setCursor(0, 1);
sensors_event_t event;
dht.temperature().getEvent(&event);
String tempString = String(event.temperature, 2);
String d = String(tempString + " *C");
lcd.print(d);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment