// Project : Arduino with DHT11 sensor and ST7735 TFT display
// By : DIY Channel / ABDELLATIF MIMOUNE
// My Youtube Channel : https://www.youtube.com/c/DIYChannel2019
#include <Adafruit_GFX.h>
#include <Adafruit_ST7735.h>
#include <DHT.h>
#define TFT_RST 8
#define TFT_CS 9
#define TFT_DC 10
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
#define DHTPIN A0
#define DHTTYPE DHT11
DHT dht11(DHTPIN, DHTTYPE);
void setup(void)
{
tft.initR(INITR_BLACKTAB);
tft.fillScreen(ST7735_BLACK);
tft.drawFastHLine(0, 50, tft.width(), ST7735_BLUE);
tft.drawFastHLine(0, 102, tft.width(), ST7735_BLUE);
tft.setTextColor(ST7735_CYAN, ST7735_CYAN);
tft.setTextSize(1);
tft.setCursor(6, 16);
tft.print(" ST7735 TFT + DHT11");
tft.setCursor(19, 33);
tft.print("BY : DIY CHANNEL");
tft.setTextColor(ST7735_GREEN, ST7735_GREEN);
tft.setCursor(25, 61);
tft.print("TEMPERATURE =");
tft.setTextColor(ST7735_YELLOW, ST7735_YELLOW);
tft.setCursor(34, 113);
tft.print("HUMIDITY =");
tft.setTextSize(2);
dht11.begin();
}
char _buffer[7];
void loop()
{
byte humi = dht11.readHumidity();
// read temperature
byte temp = dht11.readTemperature();
sprintf(_buffer, "%02u.0", temp);
tft.setTextColor(ST7735_RED, ST7735_BLACK);
tft.setCursor(29, 78);
tft.print(_buffer);
tft.drawCircle(83, 80, 2, ST7735_GREEN);
tft.setCursor(89, 78);
tft.print("C");
sprintf(_buffer, "%02u.0 %%", humi);
tft.setTextColor(ST7735_CYAN, ST7735_BLACK);
tft.setCursor(29, 130);
tft.print(_buffer);
delay(1000);
}
No comments:
Post a Comment