Prérequis :
Matériel :
1 x Carte Arduino Nano
1 x TFT TZT GMT130 ST7789
1 x DHT11
1 x Module 1 Relais 5V
1 x Ventilateur 12V
1 x Alimentation 12v
Fils de connexion
1 x Breadboard
Version IDE :
Bibliothèque :
DHT.h
Adafruit_GFX.h
Adafruit_ST7789.h
Vidéo de démonstration :
VIDEO
Schéma de câblage :
Code :
#include "DHT.h" #define DHTPIN 2 //Définit le pin du DHT11 #define DHTTYPE DHT11 // DHT 11 DHT dht(DHTPIN, DHTTYPE); #include <Adafruit_GFX.h> // Core graphics library #include <Adafruit_ST7789.h> // Hardware-specific library for ST7789 #include <SPI.h> // Arduino SPI library // ST7789 TFT module connections #define TFT_CS 10 #define TFT_DC 8 #define TFT_RST 9 // Initialize Adafruit ST7789 TFT library Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST); #define Relais 7 //Définit le pin du Relais int humON = 70; //Humidité allumage ventilateur int humOFF = 65; //Humidité extinction ventilateur int EtatRelais; void setup(void) { Serial.begin(9600); dht.begin(); pinMode(Relais, OUTPUT); tft.init(240, 240, SPI_MODE2); tft.setRotation(2); tft.setTextWrap(false); tft.fillScreen(ST77XX_WHITE); } void loop() { int h = dht.readHumidity(); float t = dht.readTemperature(); if (h >= humON && EtatRelais == 0) { EtatRelais = 1; } if (h <= humOFF && EtatRelais == 1) { EtatRelais = 0; } digitalWrite(Relais, EtatRelais); tft.setCursor(40, 10); tft.setTextColor(ST77XX_BLACK, ST77XX_WHITE); tft.setTextSize(4); tft.print(t); tft.drawCircle(171, 15, 4, ST77XX_BLACK); tft.drawCircle(171, 15, 5, ST77XX_BLACK); tft.setCursor(180, 10); tft.print("C"); tft.setCursor(100,60); tft.setTextColor(ST77XX_BLACK, ST77XX_WHITE); tft.setTextSize(3); tft.print(h); tft.print("%"); tft.setCursor(15, 120); tft.setTextColor(ST77XX_BLACK, ST77XX_WHITE); tft.setTextSize(3); tft.print("Relais :"); if (EtatRelais) { tft.setTextColor(ST77XX_GREEN, ST77XX_WHITE); tft.print(" ON "); } else { tft.setTextColor(ST77XX_RED, ST77XX_WHITE); tft.print(" OFF"); } tft.setCursor(10, 170); tft.setTextColor(ST77XX_GREEN, ST77XX_WHITE); tft.setTextSize(3); tft.print(" ON :"); tft.setTextColor(ST77XX_BLACK, ST77XX_WHITE); tft.print(humON); tft.print("%"); tft.setCursor(10, 200); tft.setTextColor(ST77XX_RED, ST77XX_WHITE); tft.setTextSize(3); tft.print("OFF :"); tft.setTextColor(ST77XX_BLACK, ST77XX_WHITE); tft.print(humOFF); tft.print("%"); }
Nombre de vues: 2 305
J’aime ça : J’aime chargement…