Hi all,
I’m planning to write some code that will run a weather station - reporting temperature, pressure, humidity, wind speed, wind direction and rainfall via USB (serial data to labview).
Here’s the circuit diagram for reference:
So far, I have modified the example code from the BMP180 pressure sensor and the DHT22 temp/humidity sensor to join them into a single program:
#include "DHT.h"
#include "SFE_BMP180.h"
#include <Wire.h>
#define ALTITUDE 70.0
#define DHTPIN 2
#define DHTTYPE DHT22
SFE_BMP180 pressure; // create an SFE_BMP180 object called "pressure":
DHT dht(DHTPIN, DHTTYPE); // Initialize DHT sensor for normal 16mhz Arduino
void setup() {
Serial.begin(9600);
Serial.println("REBOOT");
if (pressure.begin())
Serial.println("BMP180 init success");
else
{
Serial.println("BMP180 init fail\n\n");
while(1); // Pause forever.
}
dht.begin();
}
void loop()
{
char status;
double T,P,p0,a;
status = pressure.startTemperature();
if (status != 0)
{
// Wait for the measurement to complete:
delay(status);
status = pressure.getTemperature(T); // Measure temp for pressure reading
if (status != 0)
{
status = pressure.startPressure(3); // Measure pressure (x3 accuracy)
if (status != 0)
{
delay(status); // Wait for the measurement to complete:
status = pressure.getPressure(P,T);
if (status != 0)
{
p0 = pressure.sealevel(P,ALTITUDE);
Serial.print("p");
Serial.println(p0,2);
}
else Serial.println("error retrieving pressure measurement\n");
}
else Serial.println("error starting pressure measurement\n");
}
else Serial.println("error retrieving temperature measurement\n");
}
else Serial.println("error starting temperature measurement\n");
// Start DHT22 readings (takes about 250 milliseconds each)
float h = dht.readHumidity(); // Humidity
float t = dht.readTemperature(); // Temperature
// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
// Print humidity and temp data
Serial.print("h");
Serial.println(h);
Serial.print("t");
Serial.println(t);
delay(2000); // Pause for 2 seconds.
}
This gives the following output:
This is good. However now I would like to add the readings for the wind speed sensor and the rainfall sensor. These are reed switches, which will simply give a high or low voltage, switching at each ‘tip’ of the tipping bucket rain sensor, and each rotation of the wind speed sensor. Thus the rainfall signal will be very slow (probably less than 1Hz even when raining) and the wind speed signal will be roughly 0-5Hz. Measuring the analogue output of the wind direction sensor should be trivial.
What would be the best way of adding in the rainfall and wind speed signals?
Thanks