1 /* YourDuino.com Example Software Sketch
2 DHT11 Humidity and Temperature Sensor test
4 http://arduino-direct.com/sunshop/index.php?l=product_detail&p=162
7 /*-----( Import needed libraries )-----*/
11 #include <WeatherSensorWH2.h>
13 /*-----( Declare objects )-----*/
17 /*-----( Declare Constants, Pin Numbers )-----*/
25 volatile byte got_interval = 0;
26 volatile byte interval = 0;
28 volatile unsigned long old = 0, packet_count = 0;
29 volatile unsigned long spacing, now, average_interval;
31 WeatherSensorWH2 weather;
33 ISR(TIMER1_COMPA_vect)
35 static byte count = 0;
36 static byte was_hi = 0;
38 if (digitalRead(RF_IN) == HIGH) {
51 void setup() /*----( SETUP: RUNS ONCE )----*/
54 Serial.println("STATUS:START");
58 pinMode(REDPIN,OUTPUT);
59 pinMode(GREENPIN,OUTPUT);
61 pinMode(RF_IN, INPUT);
69 }/*--(end setup )---*/
71 unsigned long previousMillis = 0;
72 unsigned long indoor_interval = 60000;
73 unsigned long outdoor_interval = 45000;
74 unsigned long previousIndoor = 0;
75 unsigned long previousOutdoor = 0;
77 void loop() /*----( LOOP: RUNS CONSTANTLY )----*/
84 weather.accept(interval);
85 if (weather.acquired()) {
90 average_interval = now / packet_count;
92 Serial.print("Spacing: ");
93 Serial.println(spacing, DEC);
94 Serial.print("Packet count: ");
95 Serial.println(packet_count, DEC);
97 Serial.print("Average spacing: ");
98 Serial.println(average_interval, DEC);
101 packet = weather.get_packet();
104 Serial.print(packet[i], HEX);
106 Serial.print(packet[i], DEC);
110 Serial.print("crc: ");
111 Serial.print(weather.calculate_crc(), HEX);
112 Serial.println((weather.valid() ? " OK" : " BAD"));
116 if (weather.valid()) {
118 Serial.print("SENSOR:TYPE=OUTDOOR,");
121 Serial.print(weather.get_sensor_id(), HEX);
123 Serial.print(",HUMIDITY=");
124 Serial.print(weather.get_humidity(), DEC);
126 Serial.print(",TEMPERATURE=");
127 Serial.println(weather.get_temperature_formatted());
129 previousOutdoor = millis();
130 digitalWrite(REDPIN,HIGH);
134 Serial.println("ERROR:OUTDOOR");
135 previousOutdoor = millis();
136 digitalWrite(REDPIN,LOW);
147 if ((unsigned long)(millis() - previousMillis) >= indoor_interval) {
149 previousMillis = millis();
151 int chk = DHT11.read(DHT11PIN);
155 Serial.print("SENSOR:TYPE=INDOOR,");
156 Serial.print("HUMIDITY=");
157 Serial.println((float)DHT11.humidity, 2);
159 // Serial.print(",TEMPERATURE=");
160 // Serial.println((float)DHT11.temperature, 2);
162 Serial.print("SENSOR:TYPE=BARO,");
163 Serial.print("PRESSURE=");
164 Serial.print(bmp.readPressure());
165 Serial.print(",TEMPERATURE=");
166 Serial.println(bmp.readTemperature());
168 previousIndoor = millis();
169 digitalWrite(GREENPIN,HIGH);
174 Serial.println("ERROR:INDOOR");
175 previousIndoor = millis();
176 digitalWrite(GREENPIN,LOW);
182 if ((unsigned long)(millis() - previousIndoor) >= indoor_interval*10) {
184 Serial.println("ERROR:INDOOR TIMEOUT");
185 previousIndoor = millis();
186 digitalWrite(GREENPIN,LOW);
190 if ((unsigned long)(millis() - previousOutdoor) >= outdoor_interval*10) {
192 Serial.println("ERROR:OUTDOOR TIMEOUT");
193 previousOutdoor = millis();
194 digitalWrite(REDPIN,LOW);
199 }/* --(end main loop )-- */