Á¤¸» °¨»çÇÏ°Ú½À´Ï´Ù.
/* How to use the DHT-22 sensor with Arduino
Temperature and humidity sensor and
I2C LCD1602
SDA --> A4
SCL --> A5
Dev: Panagiotis Papadopoulos // Date: 7/6/2016 // */
//Libraries
#include <DHT.h>;
//I2C LCD:
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
#include "MutichannelGasSensor.h"
LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27 for a 16 chars and 2 line display
//Constants
#define DHTPIN D3 // what pin we're connected to
#define DHTTYPE DHT22 // DHT 22 (AM2302)
DHT dht(DHTPIN, DHTTYPE); //// Initialize DHT sensor for normal 16mhz Arduino
//Variables
//int chk;
float hum; //Stores humidity value
float temp; //Stores temperature value
void setup()
{
Serial.begin(9600);
Serial.println("ppdo's Temp and Humidity Sensor Test");
dht.begin();
gas.begin(0x04);//the default I2C address of the slave is 0x04
gas.powerOn();
lcd.init(); //initialize the lcd
lcd.backlight(); //open the backlight
}
void loop()
{
//Read data and store it to variables hum and temp
// Reading temperature or humidity takes about 250 milliseconds!
hum = dht.readHumidity();
temp= dht.readTemperature();
//Print temp and humidity values to serial monitor
Serial.print("Humidity: ");
Serial.print(hum,1); ////µÚ¿¡ ¼Ò¼öÁ¡
Serial.print(" %, Temp: ");
Serial.print(temp,1); ////µÚ¿¡ ¼Ò¼öÁ¡
Serial.println("Celsius");
float c;
c = gas.measure_NH3();
Serial.print("NH3: ");
if(c>=0) Serial.print(c);
else Serial.print("invalid");
Serial.println(" ppm");
c = gas.measure_CO();
Serial.print("CO: ");
if(c>=0) Serial.print(c);
else Serial.print("invalid");
Serial.println(" ppm");
c = gas.measure_NO2();
Serial.print("NO2: ");
if(c>=0) Serial.print(c);
else Serial.print("invalid");
Serial.println(" ppm");
// set the cursor to (0,0):
lcd.setCursor(0, 0);
// print from 0 to 9:
lcd.print("Temp: ");
lcd.print(temp,1); ////µÚ¿¡ ¼Ò¼öÁ¡
lcd.print("C");
lcd.setCursor(0, 1);
lcd.print("Humidity: ");
lcd.print(hum,1); //µÚ¿¡ ¼Ò¼öÁ¡
lcd.print("%");
delay(5000);//Delay 5 sec.
lcd.clear; ------------------------------------------------------- ÇöÀç À̺κп¡¼ ¿À·ù°¡ ¶å´Ï´Ù
lcd.setCursor(0, 0);
lcd.print("NH3:");
lcd.print(NH3,1); ////µÚ¿¡ ¼Ò¼öÁ¡
lcd.print("ppm");
lcd.setCursor(0, 1);
lcd.print("CO: ");
lcd.print(CO,1); //µÚ¿¡ ¼Ò¼öÁ¡
lcd.print("ppm");
delay(2000);//Delay 2 sec.
}