Hello,
I'd like to have a setup involving three LEDs with my current weather station while still logging data. I was wondering if you all know if it would be possible for the DHT22 temperature reading to impact LEDs. I currently just have one just to stay on while the station is running. How could I go about having one LED turn on if the temperature is less than 65F with the other two being off, a different one turn on for temps of 65-85F with the other two off and a third one turn on with the other two being off for temps greater than 85F?
Here is my code for my current weather station. Thanks.
#include "BMP280.h"
#include "Wire.h"
#define P0 1013.25
BMP280 bmp;
#include "DHT.h"
#include <SPI.h>
#include <SD.h>
#include <stdlib.h>
#include "Sodaq_DS3231.h"
#define DHTPIN 7 // what digital pin we're connected to
const int chipSelect = 10;
// Uncomment whatever type you're using!
#define DHTTYPE DHT22 // DHT 22
DHT dht(DHTPIN, DHTTYPE);
void setup()
{
pinMode(5, OUTPUT);
Serial.begin(9600);
Wire.begin();
rtc.begin();
Serial.print("Initializing SD card...");
// see if the card is present and can be initialized:
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");
// don't do anything more:
return;
}
Serial.println("card initialized.");
Serial.println("BMP DHT22 Measurement");
bmp.begin();
dht.begin();
bmp.setOversampling(4);
}
void loop()
{
digitalWrite(5, HIGH);
delay(300000);
DateTime now = rtc.now();
float h = dht.readHumidity();
// Read temperature as Celsius (the default)
float t = dht.readTemperature();
// Read temperature as Fahrenheit (isFahrenheit = true)
float f = dht.readTemperature(true);
if (isnan(h) || isnan(t) || isnan(f))
{
Serial.println("Failed to read from DHT sensor!");
return;
}
// Compute heat index in Fahrenheit (the default)
float hif = dht.computeHeatIndex(f, h);
// Compute heat index in Celsius (isFahreheit = false)
float hic = dht.computeHeatIndex(t, h, false);
double T,P;
char result = bmp.startMeasurment();
if(result!=0)
{
delay(result);
result = bmp.getTemperatureAndPressure(T,P);
if(result!=0)
{
double A = bmp.altitude(P,P0);
bmp.getTemperatureAndPressure(T,P);
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.date(), DEC);
Serial.print('/');
Serial.print(now.year(), DEC);
Serial.print(",");
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.print(",");
Serial.print("P: ");
Serial.print(P,2);
Serial.print(" mBar, ");
Serial.print("Temperature: ");
Serial.print(t);
Serial.print(" *C, ");
Serial.print(f);
Serial.print(" *F, ");
Serial.print("Humidity: ");
Serial.print(h);
Serial.println(" %, ");
// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
File dataFile = SD.open("dhtbmptc.txt", FILE_WRITE);
// if the file is available, write to it:
if (dataFile)
{
dataFile.print(now.month(), DEC);
dataFile.print('/');
dataFile.print(now.date(), DEC);
dataFile.print('/');
dataFile.print(now.year(), DEC);
dataFile.print(",");
dataFile.print(now.hour(), DEC);
dataFile.print(':');
dataFile.print(now.minute(), DEC);
dataFile.print(':');
dataFile.print(now.second(), DEC);
dataFile.print(",");
dataFile.print(f);
dataFile.print(",");
dataFile.print(t);
dataFile.print(",");
dataFile.print(h); // send humidity to file with 2 decimal places
dataFile.print(",");
dataFile.println(P,2); // send press and cr/lf so next data goes to new line
}
dataFile.close();
}
else
{
Serial.println("Error.");
}
}
else
{
Serial.println("Error.");
}
}