Indoor Environment Monitoring

Indoor Environment Monitoring

Experimental introduction

In this experiment we will use three modules to collect data such as light, temperature, humidity and atmospheric pressure. At the same time, the data is sent and displayed on the LCD12854 through the serial port.

Experimental Materials

1X  Adeept UNO Board

1X  DHT-11 Module

1X  Photoresistor Module

1X  Barometer Module

1X  LCD12864 Module

1X  Breadboard

Some jumpers

Experimental connection diagram

Experiment code

/***********************************************************
File name:   AdeeptLCD12864.ino
Website: www.adeept.com
E-mail: support@adeept.com
Author: Tom
Date: 2019/03/20 
***********************************************************/
#include <Adeept_LCD12864RSPI.h>
#include <Adeept_DHT11.h>
#include <Adeept_BMP180.h>
#define AR_SIZE( a ) sizeof( a ) / sizeof( a[0] )
Adeept_DHT11 Adeept_dht11;
Adeept_BMP180 Adeept_bmp180(0x77);//I2C address of BMP180
#define DHT11PIN 2  //Set the digital 2 to the S pin

int photoresistorPin = 0;          // photoresistor  connected to analog pin 0
unsigned char show0[]=" photoresistor";         //Test the code
unsigned char show1[]=" analog:       ";     
unsigned char show2[]=" www.adeept.com";  
unsigned char show3[]="DHT11 sensor";      
unsigned char show4[]="Humi:       %";    
unsigned char show5[]="Temp:       %";
unsigned char show6[]="   Pressure  ";       
unsigned char show7[] = "Pr:          Pa ";
unsigned char show8[] = "Atm:       ";
unsigned char show9[] = "Alti:        M  ";
   

int btnpin1 = 12;           //Set the digital 12 to button module interface 
int btnpin2 = 13;           //Set the digital 13 to button module interface      

int pageNumber = 1;
void setup()
{
    pinMode(photoresistorPin, INPUT);//Set analog 0 port mode, the INPUT for the input
    Serial.begin(9600);   //opens serial port, sets data rate to 9600 bps
    Adeept_bmp180.begin();
    pinMode(btnpin1,INPUT); //Set digital 12 port mode, the INPUT for the input
    pinMode(btnpin2,INPUT); //Set digital 13 port mode, the INPUT for the input
    Adeept_12864.Initialise(); // The screen is initialized
    delay(100);
}
void loop()
{
    double dataphotoresistor = 0;
    char strphotoresistor[5];
    double temphumidity = 0;
    double tempTemperature = 0;
    char strhumidity[5];
    char strTemperature[5];
    char strPressure[7];
    char strAtm[3];
    char strAltitude[5];
   
    dataphotoresistor = analogRead(photoresistorPin);
    Serial.print("photoresistor: "); //send data to the serial monitor
    Serial.println(dataphotoresistor); //send data to the serial monitor

    Adeept_dht11.read(DHT11PIN);
    temphumidity = Adeept_dht11.humidity;
    Serial.print("humidity: "); //send data to the serial monitor
    Serial.print(temphumidity); //send data to the serial monitor
    Serial.println("%"); //send data to the serial monitor

    tempTemperature = Adeept_dht11.temperature;
    Serial.print("temperature: "); //send data to the serial monitor
    Serial.print(tempTemperature); //send data to the serial monitor
    Serial.println("C"); //send data to the serial monitor

    double dataTemperature = Adeept_bmp180.GetTemperature(); //MUST be called first
    float dataPressure = Adeept_bmp180.GetPressure();
    float dataAtm = dataPressure / 101325; // "standard atmosphere"
    float dataAltitude = Adeept_bmp180.calcAltitude(dataPressure); //Uncompensated caculation - in Meters

    Serial.print("Temperature: "); //send data to the serial monitor
    Serial.print(dataTemperature); //send data to the serial monitor
    Serial.println("C"); //send data to the serial monitor

    Serial.print("Pressure: "); //send data to the serial monitor
    Serial.print(dataPressure); //send data to the serial monitor
    Serial.println("Pa"); //send data to the serial monitor

    Serial.print("Atm: "); //send data to the serial monitor
    Serial.println(dataAtm); //send data to the serial monitor

    Serial.print("Altitude: "); //send data to the serial monitor
    Serial.print(dataAltitude); //send data to the serial monitor 
    Serial.println("M"); //send data to the serial monitor 

//photoresistor->LCD12864
    if(pageNumber==1){
      dtostrf(dataphotoresistor,4,0,strphotoresistor);//Converts a floating-point number to a string
      Adeept_12864.DisplayString(0,0,show0,AR_SIZE(show0));//Display: photoresistor
      delay(50);
      Adeept_12864.DisplayString(1,0,show1,AR_SIZE(show1));//Display: analog: 
      delay(50);
      Adeept_12864.DisplayString(1,4,(unsigned char *)strphotoresistor,4);//Display photoresistor data
      delay(50);
      Adeept_12864.DisplayString(3,0,show2,AR_SIZE(show2));//Display: www.adeept.com
    }

//humidity&temperature->LCD12864
    if(pageNumber==2){
      dtostrf(temphumidity,5,2,strTemperature);//Converts a floating-point number to a string
      dtostrf(tempTemperature,5,2, strhumidity );//Converts a floating-point number to a string
      Adeept_12864.DisplayString(0,1,show3,AR_SIZE(show3));//Display: DHT11 sensor
      delay(50);
      Adeept_12864.DisplayString(1,1,show4,AR_SIZE(show4));//Display: Humi:     %
      delay(50);
      Adeept_12864.DisplayString(1,4,(unsigned char *)strTemperature,5);//Display humidity data  
      delay(50);
      Adeept_12864.DisplayString(2,1,show5,AR_SIZE(show5));//Display: Temp:     C
      delay(50);
      Adeept_12864.DisplayString(2,4,(unsigned char *)strhumidity,6);//Display temperature data
      delay(50);
      Adeept_12864.DisplayString(3,0,show2,AR_SIZE(show2));//Display: www.adeept.com
    }

//Pressure->LCD12864
    if(pageNumber==3){
      dtostrf(dataPressure, 6, 2, strPressure); //Converts a floating-point number to a string
      dtostrf(dataAtm, 2, 2, strAtm); //Converts a floating-point number to a string
      dtostrf(dataAltitude, 4, 2, strAltitude); //Converts a floating-point number to a string
      Adeept_12864.DisplayString(0, 0, show6, AR_SIZE(show6)); //Display: Temp:      C
      Adeept_12864.DisplayString(1, 0, show7, AR_SIZE(show7)); //Display: Pr:        Pa
      delay(10);
      Adeept_12864.DisplayString(1, 2, (unsigned char *)strPressure, 8); //Display temperature data
      delay(10);
      Adeept_12864.DisplayString(2, 0, show8, AR_SIZE(show8)); //Display: Atm:         Pa
      delay(10);
      Adeept_12864.DisplayString(2, 2, (unsigned char *)strAtm, 4); //Display temperature data
      delay(10);
      Adeept_12864.DisplayString(3, 0, show9, AR_SIZE(show9)); //Display: Altitude:     M
      delay(10);
      Adeept_12864.DisplayString(3, 3, (unsigned char *)strAltitude, 6); //Display temperature data  
    }
  if(digitalRead(btnpin1)==LOW)              //Detection button interface to low
  {   
      delay(10);                              //Delay 10ms for the elimination of key leading-edge jitter
      if(digitalRead(btnpin1)==LOW)           //Confirm button is pressed
      {        
        pageNumber++;
        if(pageNumber>=3){pageNumber=3;}
        Adeept_12864.CLEAR();//Clear screen
        delay(100);
      }
   }
  if(digitalRead(btnpin2)==LOW)              //Detection button interface to low
  {   
      delay(10);                              //Delay 10ms for the elimination of key leading-edge jitter
      if(digitalRead(btnpin2)==LOW)           //Confirm button is pressed
      {     
        pageNumber--;
        if(pageNumber<=1){pageNumber=1;}
        Adeept_12864.CLEAR();//Clear screen
        delay(100);
      }
   }  
    delay(100);//0.1S

}

Experimental phenomena

Press the two buttons to control the LCD12864 to display page turning, switch display information such as illumination, temperature and humidity.

One Reply to “Indoor Environment Monitoring”

Leave a Reply