DHT11 Temperature sensor and the Ethernet Shield

Hello every one

I need to build a temperature and humidity sensor API so that i can use SMS api in php
https://arduino-info.wikispaces.com/ethernet-temp-humidity I have try this but not working.... if someone have this kind of code please help me

I have try this but not working

Smack it with a hammer and tell it to behave!

You loaded some code you expect us to track down. The code did something, but you couldn't be bothered to tell us what it did.

You wanted the code to do something, but you couldn't be bothered to tell us what that was, either.

And, yet, you want us to tell you what you did wrong. Lets see, did I miss anything?

PaulS:

I have try this but not working

Smack it with a hammer and tell it to behave!

You loaded some code you expect us to track down. The code did something, but you couldn’t be bothered to tell us what it did.

You wanted the code to do something, but you couldn’t be bothered to tell us what that was, either.

And, yet, you want us to tell you what you did wrong. Lets see, did I miss anything?

I very very sory to ask this kind of stupid question but i know a very little in programming i know php but can not under stand arduino code

currently i have 2 thinks to know i have code to show temperature in serial monitoring and its working XD

#include <dht.h>

#define dht_dpin A0 //no ; here. Set equal to channel sensor is on

dht DHT;

void setup(){
  Serial.begin(9600);
  delay(300);//Let system settle
  Serial.println("Humidity and temperature\n\n");
  delay(700);//Wait rest of 1000ms recommended delay before
  //accessing sensor
}//end "setup()"

void loop(){
  //This is the "heart" of the program.
  DHT.read11(dht_dpin);

    Serial.print("Current humidity = ");
    Serial.print(DHT.humidity);
    Serial.print("%  ");
    Serial.print("temperature = ");
    Serial.print(DHT.temperature); 
    Serial.println("C  ");
  delay(800);//Don't try to access too frequently... in theory
  //should be once per two seconds, fastest,
  //but seems to work after 0.8 second.
}// end loop()

and i have also a webserver code which is also working fine

/*
  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 9 Apr 2012
 by Tom Igoe
 
 */

#include <SPI.h>
#include <Ethernet.h>

// 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(103,16,100,20);

// Initialize the Ethernet server library
// with the IP address and port you want to use 
// (port 80 is default for HTTP):
EthernetServer server(80);

void setup() {
 // Open serial communications and wait for port to open:
  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);
  server.begin();
  Serial.print("server is at ");
  Serial.println(Ethernet.localIP());
}


void loop() {
  // 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) {
          // send a standard http response 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: 5");  // refresh the page automatically every 5 sec
          client.println();
          client.println("<!DOCTYPE HTML>");
          client.println("<html>");
          // output the value of each analog input pin
          for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
            int sensorReading = analogRead(analogChannel);
            client.print("analog input ");
            client.print(analogChannel);
            client.print(" is ");
            client.print(sensorReading);
            client.println("
");       
          }
          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");
  }
}

both are working… now my question how can i join both code and make a web server to show result in web pages

can you please help me

now my question how can i join both code and make a web server to show result in web pages

The web server example has one fundamental flaw, in my opinion. That is that is only gets the data to show when a client requests the data.

It should, in my opinion, be collecting data all the time, and only SHOWING the latest data when a client requests it.

This code, in the server code you posted:

          for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
            int sensorReading = analogRead(analogChannel);
            client.print("analog input ");
            client.print(analogChannel);
            client.print(" is ");
            client.print(sensorReading);
            client.println("
");       
          }

should be put in a function called showCurrentData(). The code that gets the data to show should be put in a function called getDataToShow().

The getDataToShow() function should be on every pass through loop(). The getDataToShow() function should use millis() and the last time the data was collected to determine if it is time to collect data again (rather than the horrid delay() function).

If those changes were made to the example server sketch, I’m sure that you could see how to replace what getDataToShow() is doing to get temperature and humidity information periodically.

You could also see, more easily, how to change the showCurrentData() function to show the last temperature and humidity information, instead of random analog pin readings.

Given this advice, can you see how you would change the server example to server temperature and humidity data, instead?

Hello

I have solve the problem… Now my project is working here is the code

/*
  Web Server

 A simple web server that shows the temperature & humidity from
 a DHT11 sensor using an Arduino Wiznet Ethernet shield. 

 Circuit:
 * Ethernet shield attached to pins 10, 11, 12, 13
 * Data from DHT11 is at A2 (analog input 2)

 */

#include <DHT.h>

#define DHTPIN A2     // what pin we're connected the DHT output
#define DHTTYPE DHT11   // DHT 11 
DHT dht(DHTPIN, DHTTYPE);

#include <Wire.h>
#include <SPI.h>
#include <Ethernet.h>



byte mac[] = { 
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,10, 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);

void setup() {
  dht.begin();  
  
 // Open serial communications and wait for port to open:
  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);
  server.begin();
  Serial.print("server is at ");
  Serial.println(Ethernet.localIP());
}


void loop() {
  int h = dht.readHumidity();
  int t = dht.readTemperature();
  
  // 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) {
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println("Connnection: close");
          client.println();
          client.println("<!DOCTYPE HTML>");
          client.println("<html>");
                    // add a meta refresh tag, so the browser pulls again every 5 seconds:
          client.println("<meta http-equiv=\"refresh\" content=\"5\">");
          client.println("<title>");
          client.print("Temperature and Humidity");
          client.println("</title>");
          
          // output the value of temperature and humuidity from DHT
          client.println("<center>");
          client.println("<h1>");
          client.print("Data Center");
          client.println("</h1>");
          client.println("<h2>");
          client.print("Server Room Temperature and Humidity");
          client.println("</h2>");
          client.println("<h4>");
          client.print("Temperature : ");
          client.print(t);
          client.print("<sup>0</sup>");
          client.print("C");
          client.println("
");
          client.print("Humidity : ");
          client.print(h);
          client.print("%");
          client.println("</h4>");
          client.println("</center>");
           
          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");
  }
}

Now i want to add more thing in this code… digital pin 7 will be blink if Temperature goes more then 30"C

can you please help me in this

Now i want to add more thing in this code.... digital pin 7 will be blink if Temperature goes more then 30"C

can you please help me in this

Pins don't blink. They are either on or off. You can make it appear as though an LED is flashing by turning the pin on and off at appropriate times.

So, what have you tried?

PaulS:

Pins don't blink. They are either on or off. You can make it appear as though an LED is flashing by turning the pin on and off at appropriate times.

So, what have you tried?

yes something liek this when Temperature goes more than 30"C some pin will be Power ON and a RED LED will pe power ON