SOLVED: DHT11 sensor and web server help

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
gwilson09
 
Posts: 3
Joined: Wed Aug 15, 2012 1:58 pm

SOLVED: DHT11 sensor and web server help

Post by gwilson09 »

Hello,

I'm new to the Arduino and am trying to put a small web-based weather station together. My setup currently consists of a UNO, DHT11 sensor, and an ENC28J60 thernet module. I have independently tested each component and they all work correctly: I get good temp/humidity readings from the DHT11 and the rbbbServer sketch will serve the test web page correctly. My initial effort is a combination of the DHTtester and rbbbServer sketches. The web page loads, but the sensor data that is returned isn't right. Humidity shows '0' and temperature shows something like '17012'. The humidity doesn't change, but the 5 digit temperature value does fluctuate, if I blow on it or fan it. Can anyone provide some insight into this for me? All replies greatly appreciated.

Glenn
temp.jpg
temp.jpg (36.08 KiB) Viewed 2401 times

Code: Select all

#include <EtherCard.h>
#include <DHT.h>

// ethernet interface mac address, must be unique on the LAN
static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };
static byte myip[] = { 10, 58, 30, 122 };

byte Ethernet::buffer[500];
BufferFiller bfill;

#define DHTPIN 8     // what pin we're connected to
#define DHTTYPE DHT11   // DHT 11

float   rh, rt;      // make global

DHT dht(DHTPIN, DHTTYPE);

void setup ()
{
  if (ether.begin(sizeof Ethernet::buffer, mymac) == 0)
    Serial.println( "Failed to access Ethernet controller");
  ether.staticSetup(myip);
  
  Serial.begin(9600);
  dht.begin();
}

static word homePage()
{
  bfill = ether.tcpOffset();
  bfill.emit_p(PSTR(
    "HTTP/1.0 200 OK\r\n"
    "Content-Type: text/html\r\n"
    "Pragma: no-cache\r\n"
    "\r\n"
    "<meta http-equiv='refresh' content='1'/>"
    "<title>RBBB server</title>"
    "<h1>Tiny Weather Server</h1>"
    "<br>"
    "<h2>Humidity: $D</h2>"
    "<h2>Temperature: $D</h2>"),
    rh, rt);
    
  return bfill.position();
}

void loop ()
{    
  rh = dht.readHumidity();
  rt = dht.readTemperature();
    
  word len = ether.packetReceive();
  word pos = ether.packetLoop(len);
  
  if (isnan(rt) || isnan(rh)) {
    Serial.println("Failed to read from DHT");
  } else {
    Serial.print("Humidity: "); 
    Serial.print(rh);
    Serial.print(" %\t");
    Serial.print("Temperature: "); 
    Serial.print(rt);
    Serial.println(" *C");
  }

  
  if (pos)  // check if valid tcp data is received
    ether.httpServerReply(homePage()); // send web page data
}
Last edited by gwilson09 on Wed Aug 15, 2012 4:54 pm, edited 1 time in total.

User avatar
adafruit_support_bill
 
Posts: 88089
Joined: Sat Feb 07, 2009 10:11 am

Re: DHT11 sensor and web server help

Post by adafruit_support_bill »

I don't know which ENC28J60 module you are using, but that chip has an SPI interface, so it is probably using the hardware SPI pins: 10-13. That would interfere with your sensor on pin 11. Try moving the DHT11 to pin 9.

gwilson09
 
Posts: 3
Joined: Wed Aug 15, 2012 1:58 pm

Re: DHT11 sensor and web server help

Post by gwilson09 »

It's just a generic ethernet module that I got for $5 off Ebay. I have tried several different pins: 2,3,4,8, and 9. All with the same result. The serial monitor shows that the sensor is working correctly, but there's got to be something I'm missing.

User avatar
adafruit_support_bill
 
Posts: 88089
Joined: Sat Feb 07, 2009 10:11 am

Re: DHT11 sensor and web server help

Post by adafruit_support_bill »

Code: Select all

"<h2>Humidity: $D</h2>"
    "<h2>Temperature: $D</h2>"),
    rh, rt);
I believe that $D expects a WORD type parameter. rh and dh are defined as floats in your code.

gwilson09
 
Posts: 3
Joined: Wed Aug 15, 2012 1:58 pm

Re: DHT11 sensor and web server help

Post by gwilson09 »

Thanks for the insight. I thought about that before, but hadn't looked into it too far. Getting the sensor data as a float value and then converting it to a word has solved the problem. Again, thank you.

Glenn

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”