Hello,
I'm new to Arduino and i'm having problems with my project. I Know somethings wrong with reading the sensor, because the rest works when I leave that part out of the script. Does anyone has the solution for me?
#include <SPI.h>
#include <DHT11.h>
int pin=4;
DHT11 dht11(pin);
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0x3F, 0xF9, 0xED }; //physical mac address
IPAddress ip(192,168,2, 113);
EthernetServer server(80); //server port
String readString;
void setup(){
pinMode(5, OUTPUT); //pin selected to control
pinMode(6, OUTPUT); //pin selected to control
//start Ethernet
Ethernet.begin(mac);
server.begin();
//enable serial data print
Serial.begin(9600);
}
void loop(){
float temp, humi;
dht11.read(humi, temp);
{
// Create a client connection
EthernetClient client = server.available();
if (client) {
while (client.connected()) {
if (client.available()) {
char c = client.read();
//read char by char HTTP request
if (readString.length() < 100) {
//store characters to string
readString += c;
//Serial.print(c);
}
//if HTTP request has ended
if (c == '\n') {
///////////////
Serial.println(readString); //print to serial monitor for debuging
client.println("HTTP/1.1 200 OK"); //send new page
client.println("Content-Type: text/html");
client.println();
client.println("<HTML>");
client.println("<HEAD>");
client.println("<TITLE>Arduino Control page</TITLE>");
client.println("</HEAD>");
client.println("<BODY>");
client.println("<CENTER>");
client.println("<H1>Arduino Control</H1>");
// output 5
client.print("<input type=submit value=ON style=width:100px;height:45px onClick=location.href='/?on2;'>");
client.print("<input type=submit value=OFF style=width:100px;height:45px onClick=location.href='/?off3;'>
");
// output 6
client.print("<input type=submit value=ON style=width:100px;height:45px onClick=location.href='/?on4;'>");
client.print("<input type=submit value=OFF style=width:100px;height:45px onClick=location.href='/?off5;'>
");
client.print("Temperature : ");
client.print(temp);
client.print("<sup>0</sup>");
client.print("C");
client.println("
");
client.print("Humidity : ");
client.print(humi);
client.print("%");
client.println("</CENTER>");
client.println("</BODY>");
client.println("</HTML>");
delay(1);
//stopping client
client.stop();
}
}
}
}
}
}