Home environmental monitoring system

  • admin
  • admin's Avatar Topic Author
  • Offline
  • Administrator
  • Administrator
More
1 month 1 week ago - 1 month 1 week ago #80 by admin
Home environmental monitoring system






/***********************************************************************

 * Interfacing Arduino with ST7789 TFT display (240x240 pixel)

 *   and DHT11 digital humidity & temperature sensor.

  * https://sites.google.com/view/electrodevelo/home-page

 ***********************************************************************/

#include <Adafruit_GFX.h>     // Adafruit core graphics library

#include <Adafruit_ST7789.h>  // Adafruit hardware-specific library for ST7789

#include <DHT.h>              // Adafruit DHT library code

int LED = 2;

int buttonA = 4; //GASnatural

int buttonB = 5; //GAS

int buttonC = 6; //FIER

int buttonD = 7; //SMOKE

int BUTTONstate1 = 0;

int BUTTONstate2 = 0;

int BUTTONstate3 = 0;

int BUTTONstate4 = 0;

 // ST7789 TFT module connections

#define TFT_CS    10  // define chip select pin

#define TFT_DC     8  // define data/command pin

#define TFT_RST    9  // define reset pin, or set to -1 and connect to Arduino RESET pin

// initialize Adafruit ST7789 TFT library with hardware SPI module

// MOSI(SDA) ---> Arduino digital pin 11

// SCK (SCL) ---> Arduino digital pin 13

Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST);

 

#define DHTPIN  A2           // DHT11 data pin is connected to Arduino analog pin 2

#define DHTTYPE DHT11        // DHT11 sensor is used

DHT dht11(DHTPIN, DHTTYPE);  // initialize DHT library

 

void setup(void) {

  pinMode(LED, OUTPUT);

  pinMode(buttonA, INPUT);

  pinMode(buttonB, INPUT);

  pinMode(buttonC, INPUT);

  pinMode(buttonD, INPUT);

  

  // initialize the ST7789 display (240x240 pixel)

  // if the display has CS pin try with SPI_MODE0

  tft.init(240, 240, SPI_MODE2);

  // if the screen is flipped, remove this command

  tft.setRotation(1);

  // fill the screen with black color

  tft.fillScreen(ST77XX_BLACK);

  tft.setTextWrap(false);       // turn off text wrap option

  tft.setTextColor(ST77XX_GREEN, ST77XX_BLACK);  // set text color to green and black background

  tft.setTextSize(3);           // text size 

  tft.setCursor(15, 20);        // move cursor to position  pixel

  tft.print("TEMPERATURE:");

  tft.setTextColor(ST77XX_YELLOW, ST77XX_BLACK);  // set text color to yellow and black background

  tft.setCursor(43, 140);       // move cursor to position  pixel

  tft.print("HUMIDITY:");

  tft.setTextSize(5);           // text size 

 

  // initialize DHT11 sensor

  dht11.begin();

  }

  char _buffer[7];

  // main loop

  

  void loop() {

  delay(1000);    // wait a second

 

  digitalWrite(LED,LOW);// power on the led on pin 2

  digitalWrite(buttonA,HIGH);

  digitalWrite(buttonB,HIGH);

  digitalWrite(buttonC,HIGH);

  digitalWrite(buttonD,HIGH);

  

  // read humidity in rH%

  int Humi = dht11.readHumidity() * 10;

  // read temperature in degrees Celsius

  int Temp = dht11.readTemperature() * 10;

  // print temperature (in °C)

  tft.setTextColor(ST77XX_CYAN, ST77XX_BLACK);  // set text color to red with black background

  if(Temp < 0)    // if temperature < 0

  sprintf(_buffer, "-%02u.%02u", (abs(Temp)/10)%100, abs(Temp) % 10);

  else            // temperature >= 0

  sprintf(_buffer, "%02u.%02u", (Temp/10)%100, Temp % 10);

  tft.setCursor(20, 71);

  tft.print(_buffer);

  tft.drawCircle(181, 77, 4, ST77XX_CYAN);  // print degree symbol ( ° )

  tft.setCursor(190,71);

  tft.print("C");

  // print humidity (in %)

  tft.setTextColor(ST77XX_CYAN, ST77XX_BLACK);  // set text color to cyan and black background

  sprintf(_buffer, "%02u.%02u%%", (Humi/10)%100, Humi % 100);

  tft.setCursor(30, 181);

  tft.print(_buffer);

 

  BUTTONstate1 = digitalRead(buttonA);

  if (BUTTONstate1 == LOW){ 

  tft.fillScreen(ST77XX_RED); 

  tft.setTextColor(ST77XX_WHITE, ST77XX_RED);  // set text color to green and black background

  tft.setTextSize(7);           // text size   

  tft.setCursor(20, 61);        // move cursor to position  pixel  

  tft.print("N-GAS");

  tft.setCursor(20, 140);       // move cursor to position  pixel

  tft.print("ALARM"); 

  digitalWrite(LED,HIGH);

  delay(500);

  tft.invertDisplay(false);

  digitalWrite(LED,LOW); 

  delay(500);

  tft.invertDisplay(true);

  digitalWrite(LED,HIGH);

  delay(500);

  tft.invertDisplay(false);

  digitalWrite(LED,LOW);

  delay(500);

  tft.invertDisplay(true);

  digitalWrite(LED,HIGH);

  delay(500);

  tft.invertDisplay(false);

  digitalWrite(LED,LOW);

  delay(500);

  tft.invertDisplay(true);

  digitalWrite(LED,HIGH);  

  delay(500);

  tft.invertDisplay(false);

  digitalWrite(LED,LOW); 

  delay(500);

  tft.invertDisplay(true);

  digitalWrite(LED,HIGH);

  delay(500);

  tft.invertDisplay(false);

  digitalWrite(LED,LOW); 

  asm volatile ("  jmp 10");

  }

  else

  {

  BUTTONstate2 = digitalRead(buttonB);

  if (BUTTONstate2 == LOW){ 

  tft.fillScreen(ST77XX_RED); 

  tft.setTextColor(ST77XX_WHITE, ST77XX_RED);  // set text color to green and black background

  tft.setTextSize(7);           // text size   

  tft.setCursor(20, 61);        // move cursor to position  pixel  

  tft.print(" GAS");

  tft.setCursor(20, 140);       // move cursor to position  pixel

  tft.print("ALARM"); 

  digitalWrite(LED,HIGH);

  delay(500);

  tft.invertDisplay(false);

  digitalWrite(LED,LOW); 

  delay(500);

  tft.invertDisplay(true);

  digitalWrite(LED,HIGH);

  delay(500);

  tft.invertDisplay(false);

  digitalWrite(LED,LOW);

  delay(500);

  tft.invertDisplay(true);

  digitalWrite(LED,HIGH);

  delay(500);

  tft.invertDisplay(false);

  digitalWrite(LED,LOW);

  delay(500);

  tft.invertDisplay(true);

  digitalWrite(LED,HIGH);  

  delay(500);

  tft.invertDisplay(false);

  digitalWrite(LED,LOW); 

  delay(500);

  tft.invertDisplay(true);

  digitalWrite(LED,HIGH);

  delay(500);

  tft.invertDisplay(false);

  digitalWrite(LED,LOW); 

  asm volatile ("  jmp 10");

  }

  else

  {

  BUTTONstate3 = digitalRead(buttonC);

  if (BUTTONstate3 == LOW){ 

  tft.fillScreen(ST77XX_RED); 

  tft.setTextColor(ST77XX_WHITE, ST77XX_RED);  // set text color to green and black background

  tft.setTextSize(7);           // text size   

  tft.setCursor(20, 61);        // move cursor to position  pixel  

  tft.print("FIER");

  tft.setCursor(20, 140);       // move cursor to position  pixel

  tft.print("ALARM");

  digitalWrite(LED,HIGH);

  delay(500);

  tft.invertDisplay(false);

  digitalWrite(LED,LOW); 

  delay(500);

  tft.invertDisplay(true);

  digitalWrite(LED,HIGH);

  delay(500);

  tft.invertDisplay(false);

  digitalWrite(LED,LOW);

  delay(500);

  tft.invertDisplay(true);

  digitalWrite(LED,HIGH);

  delay(500);

  tft.invertDisplay(false);

  digitalWrite(LED,LOW);

  delay(500);

  tft.invertDisplay(true);

  digitalWrite(LED,HIGH);  

  delay(500);

  tft.invertDisplay(false);

  digitalWrite(LED,LOW); 

  delay(500);

  tft.invertDisplay(true);

  digitalWrite(LED,HIGH);

  delay(500);

  tft.invertDisplay(false);

  digitalWrite(LED,LOW);

  asm volatile ("  jmp 10");

  }

  else

  {

  BUTTONstate4 = digitalRead(buttonD);

  if (BUTTONstate4 == LOW){ 

  tft.fillScreen(ST77XX_RED); 

  tft.setTextColor(ST77XX_WHITE, ST77XX_RED);  // set text color to green and black background

  tft.setTextSize(7);           // text size   

  tft.setCursor(20, 61);        // move cursor to position  pixel  

  tft.print("SMOKE");

  tft.setCursor(20, 140);       // move cursor to position  pixel

  tft.print("ALARM");

  digitalWrite(LED,HIGH);

  delay(500);

  tft.invertDisplay(false);

  digitalWrite(LED,LOW); 

  delay(500);

  tft.invertDisplay(true);

  digitalWrite(LED,HIGH);

  delay(500);

  tft.invertDisplay(false);

  digitalWrite(LED,LOW);

  delay(500);

  tft.invertDisplay(true);

  digitalWrite(LED,HIGH);

  delay(500);

  tft.invertDisplay(false);

  digitalWrite(LED,LOW);

  delay(500);

  tft.invertDisplay(true);

  digitalWrite(LED,HIGH);  

  delay(500);

  tft.invertDisplay(false);

  digitalWrite(LED,LOW); 

  delay(500);

  tft.invertDisplay(true);

  digitalWrite(LED,HIGH);

  delay(500);

  tft.invertDisplay(false);

  digitalWrite(LED,LOW); 

  asm volatile ("  jmp 10");

  }

  }

  }

  }

  }

Source: Home environmental monitoring system
Attachments:
Last edit: 1 month 1 week ago by admin.

Please Log in or Create an account to join the conversation.

Time to create page: 0.095 seconds
Powered by Kunena Forum