/* How to use the DHT-22 sensor with Arduino uno
Temperature and humidity sensor
More info: http://www.ardumotive.com/how-to-use-dht-22-sensor-en.html
Dev: Michalis Vasilakis // Date: 1/7/2015 // www.ardumotive.com */
//Libraries
#include <DHT.h>;
#include <TM1637Display.h>
//Constants
#define DHTPIN 2 // what pin we're connected to
#define DHTTYPE DHT22 // DHT 22 (AM2302)
DHT dht(DHTPIN, DHTTYPE); //// Initialize DHT sensor for normal 16mhz Arduino
#define CLK 3
#define DIO 4
TM1637Display display(CLK, DIO);
//Variables
int chk;
float hum; //Stores humidity value
float temp; //Stores temperature value
// Create the °C Symbol
const uint8_t Celsius[] = {
SEG_A | SEG_B | SEG_F | SEG_G, // Circle
SEG_A | SEG_D | SEG_E | SEG_F // C
};
bool showTemp = true;
#define BUTTON 5
void setup()
{
Serial.begin(9600);
dht.begin();
display.setBrightness(5); // Set the display brightness (0-7)
pinMode(BUTTON, INPUT);
}
void loop()
{
int buttonState = digitalRead(BUTTON);
if(buttonState == HIGH){
showTemp = !showTemp;
}
//Read data and store it to variables hum and temp
hum = dht.readHumidity();
temp= dht.readTemperature();
//Print temp and humidity values to serial monitor
// Serial.print("Humidity: ");
// Serial.print(hum);
// Serial.print(" %, Temp: ");
// Serial.print(temp);
// Serial.println(" Celsius");
display.clear(); // Clear the display
//long numToShow = temp *100 + hum;
if(showTemp){
display.showNumberDec(temp, false, 2, 0);
display.setSegments(Celsius, 2, 2);
}
else{
display.showNumberDec(hum, false, 2, 0);
}
delay(500); //Delay 2 sec.
}