Error compiling DHT11

Hello
I'm a total n00b so please bear with me.

I'm trying to get the example code on Arduino Playground - DHT11Lib on to my mega board but I get a lot of errors:

sketch_apr13a:55: error: 'dht11' does not name a type
sketch_apr13a.ino: In function 'void setup()':
sketch_apr13a:64: error: 'DHT11LIB_VERSION' was not declared in this scope
sketch_apr13a.ino: In function 'void loop()':
sketch_apr13a:72: error: 'DHT11' was not declared in this scope
sketch_apr13a:77: error: 'DHTLIB_OK' was not declared in this scope
sketch_apr13a:80: error: 'DHTLIB_ERROR_CHECKSUM' was not declared in this scope
sketch_apr13a:83: error: 'DHTLIB_ERROR_TIMEOUT' was not declared in this scope

I think the problem is this:

Notes

To use the library, make a folder in your SKETCHBOOKPATH\libaries with the name DHT11 and put the .h and .cpp there. Optionally make a examples subdirectory to place the sample app. Be aware that the library will only be visible after restarting all instances of the Arduino IDE.

I don't exactly know what this means. I tried to copy the two codes:

dht11.h
dht11.cpp

copy paste them to Arduino 1.0.4 program and save them to my C:\Program Files\arduino-1.0.4\libraries\DHT11 folder as:

dht11.h
dht11.cpp

the files come up as "arduino source code" (dht11.h.ino)
I think here is the problem, but I don't know what to do!

and then I restart the program but that doesn't help.

This is probably a real stupid question, but I don't know how to solve it.

and save them to my C:\Program Files\arduino-1.0.4\libraries\DHT11 folder as:

User downloaded libraries do NOT go in the core library folder. Remove them from there.

http://www.arduino.cc/en/Hacking/Libraries

I don't exactly know what this means.

After reading the link above, if you still don't understand, ask. Don't just stuff files wherever.

The files are in the right directory if I understand correctly:
C:\Documents and Settings\XXX\My Documents\Arduino\libraries
I restart Arduino and c&p code from Arduino Playground - DHT11Lib to arduino.
I try to add the lib to the program from "Sketch | Import Library menu"
Try to compile and get the same error...

sketch_apr13a:56: error: 'dht11' does not name a type
sketch_apr13a.ino: In function 'void setup()':
sketch_apr13a:65: error: 'DHT11LIB_VERSION' was not declared in this scope
sketch_apr13a.ino: In function 'void loop()':
sketch_apr13a:73: error: 'DHT11' was not declared in this scope
sketch_apr13a:78: error: 'DHTLIB_OK' was not declared in this scope
sketch_apr13a:81: error: 'DHTLIB_ERROR_CHECKSUM' was not declared in this scope
sketch_apr13a:84: error: 'DHTLIB_ERROR_TIMEOUT' was not declared in this scope

The files
dht11.h
dht11.cpp
are still in dht11.h.ino format, is this right?

Did you check the file names? dht11 is not similar to DHT11.

Okey, so I got something working...

I Copy dht11.h code form Arduino Playground - DHT11Lib and paste to notepad, and save the file as dht11.h( before I pasted it to the Arduino IDE) in C:\Documents and Settings\XXX\My Documents\Arduino\libraries\DHT11 folder (before I used C:\Program Files\arduino-1.0.4\libraries\DHT11 folder, that was wrong your telling me)

I try to compile and NO PROBLEM, upload, all good, but the when I open serial monitor:

0?Náø?´P?j?Á]2?t%ÿþY?NÐqh¢À©yI
Ô

Whats up with this?

I think this is because of your serial port baud rate. Try changing it to 9600 and see what happens!

Thanks, that's where the problem was

Serial.begin(115200);

So I changed it to that and I'm getting readable result, but...

Read sensor: Time out error
Humidity (%): 0.00
Temperature (oC): 0.00

Oh, and I removed:

Serial.print("Temperature (oF): ");
Serial.println(Fahrenheit(DHT11.temperature), 2);

Serial.print("Temperature (K): ");
Serial.println(Kelvin(DHT11.temperature), 2);

Serial.print("Dew Point (oC): ");
Serial.println(dewPoint(DHT11.temperature, DHT11.humidity));

Serial.print("Dew PointFast (oC): ");
Serial.println(dewPointFast(DHT11.temperature, DHT11.humidity));

don't need them, could removing them be the problem?
I would think its :

Read sensor: Time out error

Sensor broken?

Sensor broken?

Most likely connected incorrectly. Post YOUR code (correctly! - read the sticky at the top of the forum) and a picture showing how the sensor is connected.

Removing them should not be a problem. Double check to where you are connecting your sensor and make sure that you have that defined in your sketch.

Its connected as in this picture:

without the LCD

This is the sensor I have:


I'm running cables
Mega 5v -> DHT11 +
Mega GND -> DHT11 -
Mega A0 -> DHT11 out

The Code:

#include <dht11.h>

// 
//   FILE:  dht11_test1.pde
// PURPOSE: DHT11 library test sketch for Arduino
//

//Celsius to Fahrenheit conversion
double Fahrenheit(double celsius)
{
        return 1.8 * celsius + 32;
}

// fast integer version with rounding
//int Celcius2Fahrenheit(int celcius)
//{
//  return (celsius * 18 + 5)/10 + 32;
//}


//Celsius to Kelvin conversion
double Kelvin(double celsius)
{
        return celsius + 273.15;
}

// dewPoint function NOAA
// reference: http://wahiduddin.net/calc/density_algorithms.htm 
double dewPoint(double celsius, double humidity)
{
        double A0= 373.15/(273.15 + celsius);
        double SUM = -7.90298 * (A0-1);
        SUM += 5.02808 * log10(A0);
        SUM += -1.3816e-7 * (pow(10, (11.344*(1-1/A0)))-1) ;
        SUM += 8.1328e-3 * (pow(10,(-3.49149*(A0-1)))-1) ;
        SUM += log10(1013.246);
        double VP = pow(10, SUM-3) * humidity;
        double T = log(VP/0.61078);   // temp var
        return (241.88 * T) / (17.558-T);
}

// delta max = 0.6544 wrt dewPoint()
// 5x faster than dewPoint()
// reference: http://en.wikipedia.org/wiki/Dew_point
double dewPointFast(double celsius, double humidity)
{
        double a = 17.271;
        double b = 237.7;
        double temp = (a * celsius) / (b + celsius) + log(humidity/100);
        double Td = (b * temp) / (a - temp);
        return Td;
}




dht11 DHT11;

#define DHT11PIN 2

void setup()
{
  Serial.begin(115200);
  Serial.println("DHT11 TEST PROGRAM ");
  Serial.print("LIBRARY VERSION: ");
  Serial.println(DHT11LIB_VERSION);
  Serial.println();
}

void loop()
{
  Serial.println("\n");

  int chk = DHT11.read(DHT11PIN);

  Serial.print("Read sensor: ");
  switch (chk)
  {
    case DHTLIB_OK: 
                Serial.println("OK"); 
                break;
    case DHTLIB_ERROR_CHECKSUM: 
                Serial.println("Checksum error"); 
                break;
    case DHTLIB_ERROR_TIMEOUT: 
                Serial.println("Time out error"); 
                break;
    default: 
                Serial.println("Unknown error"); 
                break;
  }

  Serial.print("Humidity (%): ");
  Serial.println((float)DHT11.humidity, 2);

  Serial.print("Temperature (oC): ");
  Serial.println((float)DHT11.temperature, 2);

  

  delay(2000);
}
//
// END OF FILE
//

Your code says that the sensor is connected to pin #2. Could you post an actual picture of your connection?

technics:
Your code says that the sensor is connected to pin #2. Could you post an actual picture of your connection?

WUHUUUUUUU!!!
Its working, I moved the cable from A0 -> 02 and I'm getting results now that seem to be correct:

Read sensor: OK
Humidity (%): 33.00
Temperature (oC): 25.00

Where did catch that pin error?

I was looking at :

double A0= 373.15/(273.15 + celsius);

but now that you pointed out my error I'm guessing what I should have been looking at is:

#define DHT11PIN 2

I have so much to learn to be able to make even the simplest of codes(I did blink the boards LED to say "hello world" in morse code, oh, the joy of it)

Its connected as in this picture:

Really? It's NOT connected in that picture. That explains your problem!

PaulS:

Its connected as in this picture:

Really? It's NOT connected in that picture. That explains your problem!

Yeah, I changed the
Mega A0-> DHT11 out
to:
Mega D02 -> DHT11 out

and now I'm getting readings.
So whats up with:
double A0= 373.15/(273.15 + celsius);
Is it just a double named A0, and if so, why would you name it like that as it so easily could be confused...
Did I get the:
#define DHT11PIN 2
right, is that where the pin is defined as D02?

Is it just a double named A0, and if so, why would you name it like that as it so easily could be confused...

My mistake,
I think I copied the name from the original fortran code, will fix it on the playground asap.