Permalink
Browse files

Update chapter-7/TempHumidDewpoint

  • Loading branch information...
1 parent c482a8a commit 3cc08c33e8ff6e9b6987ffc30793122b936d0c86 @ejgertz committed Oct 17, 2011
Showing with 15 additions and 49 deletions.
  1. +15 −49 chapter-7/TempHumidDewpoint
@@ -1,19 +1,14 @@
/* Temperature-Humidity-Dewpoint Monitor
This sketch gathers temperature and humidity data via a DHT22 sensor,
and also calculates dew point based on those measurements.
- */
+*/
#include <DHT22.h>
#include <SoftwareSerial.h>
#include <stdlib.h>
#define DHT22_ERROR_VALUE -99.5
-
-// Data wire is plugged into port 4 on the Arduino
-// Connect a 4.7K resistor between VCC and the data pin (strong pullup)
-
-
#define DHT22_PIN 4
@@ -25,7 +20,7 @@ DHT22 myDHT22(DHT22_PIN);
#define SerialOut 3
-#define wDelay 900
+#define 4Delay 900
byte thou=0;
@@ -37,12 +32,6 @@ byte ones=0;
SoftwareSerial mySerialPort(SerialIn, SerialOut);
-
-
-
-
-
-
void setup(void)
{
@@ -52,30 +41,21 @@ Serial.begin(9600);
Serial.println("DHT22 Library Demo");
-
-
-
-
pinMode(SerialOut, OUTPUT);
pinMode(SerialIn, INPUT);
-mySerialPort.begin(19200);
+mySerialPort.begin(9600);
mySerialPort.print("v");
-
-
-
-
-
mySerialPort.print("xxxx");
-delay(wDelay);
+delay(4Delay);
mySerialPort.print("----");
-delay(wDelay);
+delay(4Delay);
mySerialPort.print("8888");
-delay(wDelay);
+delay(4Delay);
mySerialPort.print("xxxx");
-delay(wDelay);
+delay(4Delay);
}
@@ -102,6 +82,7 @@ delay(2000);
errorCode = myDHT22.readData();
+
switch(errorCode)
{
case DHT_ERROR_NONE:
@@ -116,59 +97,42 @@ switch(errorCode)
tempF = (tempC*1.8)+32;
- delay(wDelay);
+ delay(4Delay);
dispData((int) tempF, 'F');
- delay(wDelay);
+ delay(4Delay);
humid = myDHT22.getHumidity();
Serial.print(humid);
Serial.println("%");
dispData((int)humid, 'h');
- delay(wDelay);
+ delay(4Delay);
dewPoint = calculateDewpoint(tempC, humid);
dispData((int) dewPoint, 'd');
Serial.print(dewPoint);
Serial.println("d");
- delay(wDelay);
+ delay(4Delay);
break;
case DHT_ERROR_CHECKSUM:
- Serial.print("check sum error ");
- Serial.print(myDHT22.getTemperatureC());
- Serial.print("C ");
- Serial.print(myDHT22.getHumidity());
- Serial.println("%");
break;
case DHT_BUS_HUNG:
- Serial.println("BUS Hung ");
- mySerialPort.print("bush");
break;
case DHT_ERROR_NOT_PRESENT:
- Serial.println("Not Present ");
- mySerialPort.print("uhoh");
break;
case DHT_ERROR_ACK_TOO_LONG:
- Serial.println("ACK time out ");
- mySerialPort.print("ACTO");
break;
case DHT_ERROR_SYNC_TIMEOUT:
- Serial.println("Sync Timeout ");
- mySerialPort.print("Snch");
break;
case DHT_ERROR_DATA_TIMEOUT:
- Serial.println("Data Timeout ");
- mySerialPort.print("Time");
break;
case DHT_ERROR_TOOQUICK:
- Serial.println("Polled to quick ");
- mySerialPort.print("Fast");
break;
}
@@ -362,4 +326,6 @@ if(ones>0)
Serial.print(c);
return;
}
-}
+}
+
+

0 comments on commit 3cc08c3

Please sign in to comment.