// Connect pin 1 (on the left) of the sensor to +5V
// Connect pin 2 of the sensor to whatever your DHTPIN is
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor
void loop() {
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
float h = dht.readHumidity();
float t = dht.readTemperature();
// check if returns are valid, if they are NaN (not a number) then something went wrong!
if (isnan(t) || isnan(h)) {
Serial.println("Failed to read from DHT");
} else {
Serial.print("Humidity: ");
Serial.print(h);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(t);
Serial.println(" *C");
}
}
I'm not sure what's wrong. It says that DHT does not name a type. Im not sure what I'm doing wrong. if someone could tell me, or give me a code for the DHT11, I'd really appreciate it.
I think I did. I have a MacBook Air, but the instructions I usually see online are for PCs. I think I downloaded it to the right spot. I'm able to open the tester code in the menu bar of the Arduino program.
So, I tried changing the code to <DHT.h> & it didn't change. The error says:
DHTtester.cpp:4:17: error: DHT.h: No such file or directory
DHTtester.pde:-1: error: 'DHT' does not name a type
DHTtester.cpp: In function 'void setup()':
DHTtester.pde:-1: error: 'dht' was not declared in this scope
DHTtester.cpp: In function 'void loop()':
DHTtester.pde:-1: error: 'dht' was not declared in this scope
and in the orange bar it says:
'DHT' does not name a type.
I assumed this code would be legit since it came from ladyada.net
Incidentally the < > syntax is for refering to libraries, the " " syntax for local .h files (but most compilers then check library directories too if not found locally).
First, I would like to apologize in advance for bringing up a super old thread, but this was frustrating me to no end.
I just dealt with this same problem for the past few hours and finally figured out what the issue was. I was copying and pasting the library files off of a webpage, and then trying to save them from within a sketch, so every time I saved my ".h" and ".cpp" files, I was actually saving them as ".h.ino" and ".cpp.ino" files, which will of course not be recognized during compile. I rectified this by copying the library code into a text document, then "Save As..." and changing the file type to be "All Files" and they saved as the correct file types. Stick those two files into a named folder in your Arduino Library file, and you should be good to go. This took my far too long to figure out; I am somewhat ashamed.
Hope this isn't way too late and it helps somebody! All the best