Skip to content

Instantly share code, notes, and snippets.

@p1nesap
Last active September 28, 2018 18:32
Show Gist options
  • Save p1nesap/cbd8cade62ffc067ea3f to your computer and use it in GitHub Desktop.
Save p1nesap/cbd8cade62ffc067ea3f to your computer and use it in GitHub Desktop.
DHT 11 temperature/humidity sensor, 16-character 2-line LCD screen with message relating to weather conditions, processed by Uno R3 microcontroller.
/* DHT 11 temperature/humidity sensor, 16-character 2-line LCD screen with message relating to weather conditions,
processed by Uno R3 microcontroller.
Watch related video on my YouTube channel, and post comment. Thanks!
http://youtube.com/user/p1nesap
Sensor out to pin 2. SCL to A5, SDA to A4.
1st i2c_scan, put address # in LiquidCrystal_I2C below.
*/
#include <Wire.h> // communicate with sensors
// Get the LCD I2C Library and move other LCD libraries
// https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads
#include <LiquidCrystal_I2C.h>
#include "DHT.h"
#define DHTPIN 2 // digital pin 2
#define DHTTYPE DHT11 // DHT 11
DHT dht(DHTPIN, DHTTYPE);
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Set the LCD I2C address
void setup() {
Serial.begin(9600);
// set up the LCD's number of columns and rows:
lcd.begin(16,2);
dht.begin();
}
void loop() {
int h = dht.readHumidity();
int t = dht.readTemperature();
//convert t to Fahrenheit
int f = (t * 9.0)/ 5.0 + 32.0;
// set cursor to (0,0):
lcd.setCursor(0, 0);
// ADDING TEXT
lcd.print("P1nesap IoT");
lcd.setCursor(0,1);
lcd.print("Weather Monitor");
delay(5000);
lcd.clear();
//END TEXT
lcd.print("Temp: ");
lcd.print(f);
lcd.print("F ");
lcd.print(t);
lcd.print("C");
// set cursor to (16,1):
lcd.setCursor(0,1);
lcd.print("Humidity: ");
lcd.print(h);
lcd.print("%");
delay(5000);
//ADDING
lcd.clear();
lcd.setCursor(0,0);
if ((f) >= 85 && (h) >= 51) {
lcd.print("Hot and humid...");
lcd.setCursor(0,1);
lcd.print("Drink water.");
}
else if ((f) <= 85 && (f) >= 64 && (h) <= 51) {
lcd.print("Perfect!");
lcd.setCursor(0,1);
lcd.print("Warm and dry.");
}
else if ((f) <= 85 && (f) >= 64 && (h) >= 51) {
lcd.print("Warm and moist,");
lcd.setCursor(0,1);
lcd.print("Sounds yummy.");
}
else if ((f) >= 50 && (f) <= 64 && (h) >= 51) {
lcd.print("Cool and damp...");
lcd.setCursor(0,1);
lcd.print("Raincoat?");
}
else if ((f) >= 50 && (f) <= 64 && (h) <= 51) {
lcd.print("Cool and dry.");
lcd.setCursor(0,1);
lcd.print("Wear a sweater.");
}
else if ((f) >= 33 && (f) <= 50 && (h) <= 51) {
lcd.print("Cool and dry,");
lcd.setCursor(0,1);
lcd.print("On the brisk side.");
}
else if ((f) >= 33 && (f) <= 50 && (h) >= 51) {
lcd.print("Raw weather...");
lcd.setCursor(0,1);
lcd.print("Read a book.");
}
else if ((f) >= 17 && (f) <= 33 && (h) <= 51) {
lcd.print("Ah, winter cold");
lcd.setCursor(0,1);
lcd.print("Dress in layers.");
}
else if ((f) < 17 ) {
lcd.print("OK, now it's");
lcd.setCursor(0,1);
lcd.print("REALLY cold!");
}
else {
lcd.print("Alert: alien");
lcd.setCursor(0,1);
lcd.print("atmosphere!");
}
delay(5000);
lcd.clear();
}
@maqueta49
Copy link

No funciona el Codigo me da error al compilar en tarjeta arduino uno

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment