Used:
- Arduino Duemilanove
- Arduino Ethernet Shield
- DHT22 Sensor
- DHT-sensor-library
- DHT Example
Connect Sensor-Pin1 to +5V
Connect Sensor-Pin2 to Digital In 2
Connect Sensor-Pin4 to GND
Connect Sensor-Pin1 with a 10K resistor to Sensor-Pin2
Programm Used (Combination of WebServer and DHT Example):
/*
Web Server
A simple web server that shows the value of the analog input pins.
using an Arduino Wiznet Ethernet shield.
Circuit:
* Ethernet shield attached to pins 10, 11, 12, 13
* Analog inputs attached to pins A0 through A5 (optional)
created 18 Dec 2009
by David A. Mellis
modified 4 Sep 2010
by Tom Igoe
*/
#include
#include
// Example testing sketch for various DHT humidity/temperature sensors
// Written by ladyada, public domain
#include "DHT.h"
#define DHTPIN 2 // what pin we're connected to
// Uncomment whatever type you're using!
//#define DHTTYPE DHT11 // DHT 11
#define DHTTYPE DHT22 // DHT 22 (AM2302)
//#define DHTTYPE DHT21 // DHT 21 (AM2301)
// Connect pin 1 (on the left) of the sensor to +5V
// Connect pin 2 of the sensor to whatever your DHTPIN is
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor
DHT dht(DHTPIN, DHTTYPE);
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1, 177);
// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);
// Request
int Request; // any function will see this variable
void setup() {
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
server.begin();
// Serial.begin(9600);
// Serial.println("DHTxx test!");
// Request
Request = 0;
// DHT
dht.begin();
}
void WEBloop()
{
// listen for incoming clients
EthernetClient client = server.available();
if (client) {
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
// if you've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
if (c == '\n' && currentLineIsBlank) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
// output the value of each analog input pin
//for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
//client.print("analog input ");
//client.print(analogChannel);
//client.print(" is ");
//client.print(analogRead(analogChannel));
//client.println("
");
//}
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
float h = dht.readHumidity();
float t = dht.readTemperature();
// check if returns are valid, if they are NaN (not a number) then something went wrong!
if (isnan(t) || isnan(h)) {
// Serial.println("Failed to read from DHT");
//
client.print("Failed to read from DHT");
client.println("
");
} else {
// Serial.print("Humidity: ");
// Serial.print(h);
// Serial.print(" %\t");
// Serial.print("Temperature: ");
// Serial.print(t);
// Serial.println(" *C");
//
client.print("Request: ");
//client.println(random(1000));
Request = Request + 1;
client.println(Request);
//
client.print("Humidity: ");
client.print(h);
client.print(" %\t");
client.print("Temperature: ");
client.print(t);
client.println(" *C");
client.println("
");
}
break;
}
if (c == '\n') {
// you're starting a new line
currentLineIsBlank = true;
}
else if (c != '\r') {
// you've gotten a character on the current line
currentLineIsBlank = false;
}
}
}
// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();
}
}
void loop() {
//DHTloop();
WEBloop();
}
void DHTloop() {
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
float h = dht.readHumidity();
float t = dht.readTemperature();
// check if returns are valid, if they are NaN (not a number) then something went wrong!
if (isnan(t) || isnan(h)) {
Serial.println("Failed to read from DHT");
} else {
Serial.print("Humidity: ");
Serial.print(h);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(t);
Serial.println(" *C");
}
}
/*
Web Server
A simple web server that shows the value of the analog input pins.
using an Arduino Wiznet Ethernet shield.
Circuit:
* Ethernet shield attached to pins 10, 11, 12, 13
* Analog inputs attached to pins A0 through A5 (optional)
created 18 Dec 2009
by David A. Mellis
modified 4 Sep 2010
by Tom Igoe
modified 10 May 2013
by Brian Hellman
– Added ability for multiple sensors
– Changed C to F, see notes above in readTemperature
*/
#include
#include
// Example testing sketch for various DHT humidity/temperature sensors
// Written by ladyada, public domain
#include “DHT.h”
#define DHTPIN_1 1 // what pin we’re connected to
#define DHTPIN_2 2
// Uncomment whatever type you’re using!
//#define DHTTYPE DHT11 // DHT 11
#define DHTTYPE DHT22 // DHT 22 (AM2302)
//#define DHTTYPE DHT21 // DHT 21 (AM2301)
// Connect pin 1 (on the left) of the sensor to +5V
// Connect pin 2 of the sensor to whatever your DHTPIN is
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor
DHT dht_1(DHTPIN_1, DHTTYPE);
DHT dht_2(DHTPIN_2, DHTTYPE);
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
//IPAddress ip(192,168,1, 177);
IPAddress ip(192,168,10, 198);
// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);
// Request
int Request; // any function will see this variable
void setup() {
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
server.begin();
// Serial.begin(9600);
// Serial.println(“DHTxx test!”);
// Request
Request = 0;
// DHT
dht_1.begin();
dht_2.begin();
}
void WEBloop()
{
// listen for incoming clients
EthernetClient client = server.available();
if (client) {
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
// if you’ve gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
if (c == ‘\n’ && currentLineIsBlank) {
// send a standard http response header
client.println(“HTTP/1.1 200 OK”);
client.println(“Content-Type: text/html”);
client.println();
// output the value of each analog input pin
//for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
//client.print("analog input ");
//client.print(analogChannel);
//client.print(" is ");
//client.print(analogRead(analogChannel));
//client.println("”);
//}
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds ‘old’ (its a very slow sensor)
// For Celcius remove the “1” from all readTemerature()
float h1 = dht_1.readHumidity();
float t1 = dht_1.readTemperature(1);
float h2 = dht_2.readHumidity();
float t2 = dht_2.readTemperature(1);
// check if returns are valid, if they are NaN (not a number) then something went wrong!
if (isnan(t1) || isnan(t2)) {
// Serial.println(“Failed to read from DHT”);
//
client.print(“Failed to read from DHT”);
client.println(“”);
} else {
// Serial.print(“Humidity: “);
// Serial.print(h);
// Serial.print(” %\t”);
// Serial.print(“Temperature: “);
// Serial.print(t);
// Serial.println(” *C”);
//
client.print(“Request: “);
//client.println(random(1000));
Request = Request + 1;
client.println(Request);
client.println(“”);
//
client.print(“Humidity1: “);
client.print(h1);
client.print(” %\t”);
client.println(“”);
client.print(“Temperature1: “);
client.print(t1);
client.println(” *F”);
client.println(“”);
client.println(“”);
//
client.print(“Humidity2: “);
client.print(h2);
client.print(” %\t”);
client.println(“”);
client.print(“Temperature2: “);
client.print(t2);
client.println(” *F”);
client.println(“”);
}
break;
}
if (c == ‘\n’) {
// you’re starting a new line
currentLineIsBlank = true;
}
else if (c != ‘\r’) {
// you’ve gotten a character on the current line
currentLineIsBlank = false;
}
}
}
// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();
}
}
void loop() {
//DHTloop();
WEBloop();
}
void DHTloop() {
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds ‘old’ (its a very slow sensor)
// For Celcius remove the “1” from all readTemerature()
float h1 = dht_1.readHumidity();
float t1 = dht_1.readTemperature(1);
float h2 = dht_2.readHumidity();
float t2 = dht_2.readTemperature(1);
// check if returns are valid, if they are NaN (not a number) then something went wrong!
if (isnan(t1) || isnan(t2)) {
Serial.println(“Failed to read from DHT”);
} else {
Serial.print(“Humidity1: “);
Serial.print(h1);
Serial.print(” %\t”);
Serial.print(“Temperature1: “);
Serial.print(t1);
Serial.println(” *C”);
Serial.print(“Humidity2: “);
Serial.print(h2);
Serial.print(” %\t”);
Serial.print(“Temperature2: “);
Serial.print(t2);
Serial.println(” *F”);
}
}
Very nice!