//By Wésley Lima
#include <DHT.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define DHTPIN 26 // what digital pin the DHT sensor is connected to
#define DHTTYPE DHT22 // there are multiple kinds of DHT sensors
DHT dht(DHTPIN, DHTTYPE);
bool menu = 0;
int pushbutton = 5;
String estado = "";
const int pinLDR = 15;
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
// 'thermo', 55x55px
const unsigned char thermo [] PROGMEM = {
0x00, 0x00, 0x00, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00,
0x07, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x07, 0x83, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x01,
0xe0, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0xe0, 0x00,
0x00, 0x00, 0x00, 0x0e, 0x00, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x1f, 0xe0, 0x00, 0x00, 0x00,
0x00, 0x0c, 0x1f, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x1f, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x0c,
0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x1f, 0xe0,
0x00, 0x00, 0x00, 0x00, 0x0c, 0x1f, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x1f, 0xe0, 0x00, 0x00,
0x00, 0x00, 0x0c, 0x00, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00,
0x0c, 0x1f, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x1f, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x1f,
0xe0, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x38, 0x60, 0x00,
0x00, 0x00, 0x00, 0x0c, 0x7c, 0x60, 0x00, 0x00, 0x00, 0x00, 0x0c, 0xfe, 0x60, 0x00, 0x00, 0x00,
0x00, 0x0c, 0xfe, 0x60, 0x00, 0x00, 0x00, 0x00, 0x0c, 0xfe, 0x60, 0x00, 0x00, 0x00, 0x00, 0x0c,
0xfe, 0x60, 0x00, 0x00, 0x00, 0x00, 0x0c, 0xfe, 0x60, 0x00, 0x00, 0x00, 0x00, 0x0c, 0xfe, 0x60,
0x00, 0x00, 0x00, 0x00, 0x0c, 0xfe, 0x60, 0x00, 0x00, 0x00, 0x00, 0x0c, 0xfe, 0x60, 0x00, 0x00,
0x00, 0x00, 0x0c, 0xfe, 0x60, 0x00, 0x00, 0x00, 0x00, 0x1c, 0xfe, 0x70, 0x00, 0x00, 0x00, 0x00,
0x3c, 0xfe, 0x78, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xfe, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x7f, 0xff,
0xbc, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0xf7, 0xff, 0xde, 0x00,
0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xef, 0xff, 0xef, 0x00, 0x00, 0x00,
0x00, 0xef, 0xff, 0xef, 0x00, 0x00, 0x00, 0x00, 0xef, 0xff, 0xef, 0x00, 0x00, 0x00, 0x00, 0xef,
0xff, 0xef, 0x00, 0x00, 0x00, 0x00, 0xef, 0xff, 0xef, 0x00, 0x00, 0x00, 0x00, 0xef, 0xff, 0xef,
0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xf7, 0xff, 0xde, 0x00, 0x00,
0x00, 0x00, 0xfb, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x7d, 0xff, 0x3c, 0x00, 0x00, 0x00, 0x00,
0x7e, 0xfe, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x01, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xff,
0xf0, 0x00, 0x00, 0x00, 0x00, 0x07, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x01, 0xff, 0x00, 0x00,
0x00
};
// 'Moon', 55x55px
const unsigned char Moon [] PROGMEM = {
0x00, 0x00, 0x00, 0x1f, 0x80, 0x00, 0x00, 0x00, 0x00, 0x01, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00,
0x07, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0xf8,
0x00, 0x00, 0x00, 0x00, 0x01, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x03, 0xff, 0xe0, 0x00, 0x00,
0x00, 0x00, 0x07, 0xff, 0xe0, 0x18, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xc0, 0x3c, 0x00, 0x00, 0x00,
0x1f, 0xff, 0x80, 0x3c, 0x00, 0x00, 0x00, 0x3f, 0xff, 0x80, 0xff, 0x00, 0x00, 0x00, 0x3f, 0xff,
0x07, 0xff, 0xe0, 0x00, 0x00, 0x7f, 0xff, 0x07, 0xff, 0xe0, 0x00, 0x00, 0xff, 0xfe, 0x03, 0xff,
0xc0, 0x00, 0x00, 0xff, 0xfe, 0x01, 0xff, 0x80, 0x00, 0x01, 0xff, 0xfe, 0x00, 0xff, 0x80, 0x00,
0x01, 0xff, 0xfc, 0x00, 0xff, 0x80, 0x00, 0x03, 0xff, 0xfc, 0x00, 0xff, 0x80, 0x00, 0x03, 0xff,
0xfc, 0x00, 0xff, 0x80, 0x00, 0x03, 0xff, 0xfc, 0x00, 0xc3, 0x80, 0x00, 0x07, 0xff, 0xfc, 0x00,
0x00, 0x00, 0x00, 0x07, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x07, 0xff, 0xfc, 0x00, 0x00, 0x02,
0x00, 0x07, 0xff, 0xfc, 0x00, 0x00, 0x07, 0x00, 0x07, 0xff, 0xfc, 0x00, 0x00, 0x1f, 0xc0, 0x0f,
0xff, 0xfc, 0x00, 0x00, 0x1f, 0xe0, 0x0f, 0xff, 0xfc, 0x00, 0x00, 0x1f, 0xc0, 0x0f, 0xff, 0xfc,
0x00, 0x00, 0x0f, 0x80, 0x0f, 0xff, 0xfc, 0x00, 0x00, 0x0f, 0x80, 0x0f, 0xff, 0xfe, 0x00, 0x20,
0x00, 0x80, 0x07, 0xff, 0xfe, 0x00, 0x30, 0x00, 0x00, 0x07, 0xff, 0xfe, 0x00, 0x78, 0x00, 0x00,
0x07, 0xff, 0xff, 0x01, 0xfe, 0x00, 0x00, 0x07, 0xff, 0xff, 0x01, 0xfe, 0x00, 0x00, 0x07, 0xff,
0xff, 0x81, 0xfe, 0x00, 0x00, 0x03, 0xff, 0xff, 0x80, 0xfc, 0x00, 0x00, 0x03, 0xff, 0xff, 0xc0,
0xfc, 0x00, 0x00, 0x03, 0xff, 0xff, 0xe0, 0xfc, 0x00, 0x00, 0x01, 0xff, 0xff, 0xe0, 0x00, 0x00,
0x00, 0x01, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x00,
0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x7f, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xff,
0xff, 0x80, 0x00, 0x00, 0x00, 0x3f, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x1f, 0xff, 0xff, 0xf0,
0x00, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x07, 0xff, 0xff, 0xff, 0xc0, 0x00,
0x00, 0x03, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x01, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00,
0x7f, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x3f, 0xff, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x0f, 0xff,
0xff, 0xe0, 0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xf8, 0x00,
0x00
};
// 'Sun', 55x55px
const unsigned char Sun [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,
0x00, 0x00, 0x40, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00,
0x70, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x30, 0xfe, 0x18, 0x00, 0x00, 0x00, 0x00, 0x03, 0xff,
0x80, 0x00, 0x00, 0x00, 0x00, 0x07, 0x83, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0xe0, 0x00,
0x00, 0x00, 0x00, 0x0c, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x30, 0x00, 0x00, 0x00,
0x00, 0x18, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x30, 0x00, 0x00, 0x00, 0x0f, 0x18,
0x00, 0x31, 0xe0, 0x00, 0x00, 0x00, 0x18, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x30,
0x00, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x60, 0x00, 0x00,
0x00, 0x00, 0x0e, 0x00, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x07, 0x01, 0xc0, 0x00, 0x00, 0x00, 0x00,
0x03, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x30, 0xfe, 0x18, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00,
0x1c, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x04, 0x00,
0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00
};
void setup()
{
Serial.begin(9600);
dht.begin();
pinMode(pinLDR, INPUT);
pinMode(pushbutton, INPUT_PULLUP);
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
Serial.println(F("SSD1306 Falhou"));
for(;;);
}
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(40, 10);
display.println("Estacao");
display.setCursor(25, 20);
display.println("Meteorologica");
display.setCursor(35, 40);
display.println("Desafio 2");
display.setCursor(20, 55);
display.println("By: Wesley Lima");
display.display();
delay(2000);
}
void loop()
{
float h = dht.readHumidity();
float t = dht.readTemperature();
Serial.print("Humidade: ");
Serial.print(h);
Serial.print(" %\t");
Serial.print("Temperatura: ");
Serial.print(t);
Serial.println(" *C ");
if(digitalRead(pinLDR) == HIGH){ //SE LEITURA DO PINO FOR IGUAL A 1 (HIGH), FAZ
Serial.println("Noite");
estado = "Noite";
}
else{ //SENÃO, FAZ
Serial.println("Dia");
estado = "Dia";
}
if (digitalRead(pushbutton) == LOW)
{
while (digitalRead(pushbutton) == LOW);
menu = !menu;
}
if (menu == 0)
{
if(estado == "Noite")
{
display.clearDisplay();
display.drawBitmap(0, 5, Moon, 55, 55, WHITE);
display.setCursor(65, 25);
display.print(estado);
display.display();
}else if(estado == "Dia"){
display.clearDisplay();
display.drawBitmap(0, 5, Sun, 55, 55, WHITE);
display.setCursor(65, 25);
display.print(estado);
display.display();
}
}else if (menu == 1) {
display.clearDisplay();
display.drawBitmap(0, 5, thermo, 55, 55, WHITE);
display.setCursor(50, 20);
display.print("Temp: " + String(h) + " C");
display.setCursor(50, 35);
display.print("Hum: " + String(t) + " %");
display.display();
}
}