// Written by Robin Milward, public domain 27/02/15 //Code to calculate the temperatur and humidity of an outdoor envoronment and log it on a Micro SD card #include #include #include "DHT.h" #define DHTPIN 2 // what pin we're connected to #define DHTTYPE DHT22 // DHT 22 (AM2302) const int chipSelect = 4; //Pin for Datalogger (SD) int led=8; //Define LED DHT dht(DHTPIN, DHTTYPE); // Initialize DHT sensor for normal 16mhz Arduino void setup() { Serial.begin(9600); pinMode(led,OUTPUT); Serial.print("Initializing SD card..."); pinMode(10, OUTPUT); if (!SD.begin(chipSelect)) { Serial.println("Card failed, or not present"); // don't do anything more: return; } Serial.println("card initialized.\n"); Serial.println("Humitidy, temperature and dew point mesurements from DTH22 (mesurment frequency 500mHz):\n"); dht.begin(); } void loop() { delay(2000); // Wait a 2 seconds between measurements. float h = dht.readHumidity(); //in humidity in % // Written by Robin Milward, public domain 27/02/15 //Code to calculate the temperatur and humidity of an outdoor envoronment and log it on a Micro SD card #include #include #include "DHT.h" #define DHTPIN 2 // what pin we're connected to #define DHTTYPE DHT22 // DHT 22 (AM2302) const int chipSelect = 4; //Pin for Datalogger (SD) int led=8; //Define LED DHT dht(DHTPIN, DHTTYPE); // Initialize DHT sensor for normal 16mhz Arduino void setup() { Serial.begin(9600); pinMode(led,OUTPUT); Serial.print("Initializing SD card..."); pinMode(10, OUTPUT); if (!SD.begin(chipSelect)) { Serial.println("Card failed, or not present"); // don't do anything more: return; } Serial.println("card initialized.\n"); Serial.println("Humitidy, temperature and dew point mesurements from DTH22 (mesurment frequency 500mHz):\n"); dht.begin(); } void loop() { delay(60000); // Wait a 60 seconds between measurements. float h = dht.readHumidity(); //in humidity in % float t = dht.readTemperature(); //in temperature in degrees Celceus *C // Reading temperature or humidity takes about 250 milliseconds float dp; // Calculate dew point //Formula for Dew Point = (h/100)^(1/8)*(112+0.9t)+0.1t-112 // dp h100 power variable1 variable 2 float h100; float power; float variable1; float variable2; h100 = h/100; power = pow(h100, 0.125); variable1 = 112+0.9*t;\ variable2 = 0.1*t-112; dp = power*variable1+variable2; float ff=t/h; File dataFile = SD.open("datalog.csv", FILE_WRITE); //coma seperated values if (dataFile) { // if the file is available, write to it: dataFile.print(h); dataFile.print(","); dataFile.print(t); dataFile.print(","); dataFile.print(dp); dataFile.print("\n"); dataFile.close(); } else { // if the file isn't open, pop up an error: Serial.println("error opening datalog.csv\n"); } if (isnan(h) || isnan(t) || isnan(dp)) { // Check if any reads failed and exit early (to try again). Serial.println("Failed to read from DHT sensor!\n"); return; } if (ff>0){ //ratio of teperature over humidity, when this value ~ 2.5 it represents the conditions // of a forest fire digitalWrite(led,HIGH); } else{ digitalWrite(led, LOW); } //Print on as serial data, to open window press ctrl+shift+m and be used to test when board is plugged in Serial.print("Humidity: "); Serial.print(h); Serial.print(" %\t"); Serial.print("Temperature: "); Serial.print(t); Serial.print(" *C"); Serial.print("\t\t"); Serial.print("Dew point: "); Serial.print(dp); Serial.print(" *C\n"); }