This is my version for using 2xDHT22 and DHT11 sensors. Hope this could help you.
// * Ethernet shield attached to pins 10, 11, 12, 13
// * Analog inputs attached to pins A0 through A5 (optional)
#include <SPI.h>
#include <Ethernet.h>
#include "DHT.h"
#include <LiquidCrystal.h>
LiquidCrystal lcd(A0, A1, 5, 4, 3, 2);
#define DHTPIN A4
#define DHTPIN1 A3
#define DHTPIN2 A2
#define DHTTYPE DHT22 // DHT 22 (AM2302)
#define DHTTYPE1 DHT22 // DHT 22 (AM2302)
#define DHTTYPE2 DHT11 // DHT 11 (AM2301)
DHT dht(DHTPIN, DHTTYPE);
DHT dht1(DHTPIN1, DHTTYPE);
DHT dht2(DHTPIN2, DHTTYPE2);
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1,40);
byte gateway[] = {
192, 168, 1, 1 };
byte subnet[] = {
255, 255, 255, 0 };
EthernetServer server(80);
void setup() {
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip, gateway, subnet);
server.begin();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
dht.begin();
dht1.begin();
dht2.begin();
lcd.begin(20, 4);
}
void loop() {
float h = dht.readHumidity();
float t = dht.readTemperature();
float h1 = dht1.readHumidity();
float t1 = dht1.readTemperature();
float h2 = dht2.readHumidity();
float t2 = dht2.readTemperature();
// if (isnan(t) || isnan(h)) {
// Serial.println("Andur kadunud");
lcd.setCursor(0, 0);
lcd.print("Valjas:");
lcd.setCursor(0, 1);
lcd.print(" ");
lcd.print(t);
lcd.print(" *C ");
lcd.print(h);
lcd.print("%");
lcd.setCursor(0, 2);
lcd.print("Toas:");
lcd.setCursor(0, 3);
lcd.print(" ");
lcd.print(t1);
lcd.print(" *C ");
lcd.print(h1);
lcd.print("%");
// listen for incoming clients
EthernetClient client = server.available();
if (client) {
Serial.println("new client");
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
Serial.write(c);
// 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) {
// now output HTML data starting with standart header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close"); // the connection will be closed after completion of the response
client.println("Refresh: 10"); // refresh the page automatically every 5 sec
client.println();
//set background to yellow
client.print("<body style=background-color:yellow>");
//väljas
client.println("<font color='green' size='12'>Väljas");
client.println("<br />");
client.print(t);
client.println(" °C");
client.println(" ");
client.println(" ");
client.print(h);
client.print(" %\t");
client.println("<br />");
client.println("<hr />");
//toas
client.println("<font color='blue' size='12'>Toas: ");
client.println("<br />");
client.print(t1);
client.println(" °C");
client.println(" ");
client.println(" ");
client.print(h1);
client.print(" %\t");
client.println("<br />");
client.println("<hr />");
//
client.println("<font color='red' size='12'>X: ");
client.println("<br />");
client.print(t2);
client.println(" °C");
client.println(" ");
client.println(" ");
client.print(h2);
client.print(" %\t");
client.println("<br />");
client.println("<hr />");
client.println("</html>");
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();
Serial.println("client disonnected");
}
}