Question

I am building a weather station using my friend's code. However, he an older verison of Arduino and I'm having trouble figuring out why. I am new to programming, so I don't know what "'dht' does not name a type" means? I'm using Arduino 1.04 and my friend coded his weather station on Arudino 0022. My question is, why isn't my verification able to compile? What am I doing incorrectly?

Here's my code:

#include <dht.h>
dht DHT;  
#define DHT22_PIN 2
#include <Wire.h>
#define BMP085_ADDRESS 0x77  // I2C address of BMP085

const unsigned char OSS = 3;  // Oversampling Setting

// Calibration values
int ac1;
int ac2; 
int ac3; 
unsigned int ac4;
unsigned int ac5;
unsigned int ac6;
int b1; 
int b2;
int mb;
int mc;
int md;

// b5 is calculated in bmp085GetTemperature(...), this variable is also used in      bmp085GetPressure(...)
// so ...Temperature(...) must be called before ...Pressure(...).
long b5; 
short temperature;
long pressure;

void setup()
{
  pinMode(2, INPUT); 
  Wire.begin();
  bmp085Calibration();
  Serial.begin(115200);
  analogReference(INTERNAL);
}

void loop() {
  // READ DATA
  float bat_read=analogRead(6);
  //bat_read = analogRead(BAT_voltage);
  float chk = DHT.read22(DHT22_PIN);

  // DISPLAY DATA
  Serial.print(bat_read, DEC);
  Serial.print(", "); 
  Serial.print(DHT.humidity, 2);
  Serial.print(", ");
  temperature = bmp085GetTemperature(bmp085ReadUT());
  pressure = bmp085GetPressure(bmp085ReadUP());
  Serial.print(temperature, DEC);
  Serial.print(", "); 
  Serial.println(pressure, DEC);
  delay(1000);
}

The errors are:

error: 'dht' does not name a type

sketch_jul05a.ino: In function 'void loop()': error: 'DHT' was not declared in this scope
Was it helpful?

Solution

About your specific bug you should

'dht' does not name a type

That means you have the word dht that is not at a place where the compiler could understand what you mean.

how do i change it to a type?

You do not want to change it into a type, you want to solve the compiling issue you're getting.

what does a type mean?

You should read the K&R on the subject. A type is a rule that constraints you into making code that is coherent.

You should copy in your question the full error you're getting, for us to better help you.

Let's assume the error is on the following line:

#include <dht.h>
dht DHT;  

The compiler does not know what is the dht, as it has never seen that being defined before. I assume, dht.h shall be a header to be included that needs should contain dht type definition. You should look if you have dht.h in your filesystem, and push it in your sketch's directory. And finally change the #include <dht.h> into #include "dht.h", so it looks up the dht.h in your local directory.

EDIT: I'm sorry I don't think I can't help you here more than what I just said. The problem is that you don't understand what I'm telling you to solve your problem, and explaining it to you would be giving you a C programming lesson. So you should first begin to read the K&R, go to some C/C++/Arduino programing courses (maybe in your local hackerspace?), and/or ask your friend to help you out and explaining to you what is happening.

OTHER TIPS

I had this exact same issue yesterday while updating a sketch using the DHT22 sensor that was written in Arduino 0022. I was trying to edit it in the Arduino 1.0.5 IDE. Multiple compile errors, particularly with the function millis(). I think it might have worked if I'd just opened the 0022 IDE, but I thought it was time to bring the sketch into this decade ;)

I downloaded the Adafruit DHT22 library from Github and re-wrote the sketch slightly to use the library's methods. It was pretty much drop-in. There is an example sketch included with the library that you can derive to make everything fit.

In my sketch, I got things going with:

#include "DHT.h"
#define DHTPIN 7 // what pin we're connected to on the Arduino UNO

#define DHTTYPE DHT22 // DHT 22 (AM2302)

DHT dht(DHTPIN, DHTTYPE);

void setup() {
Serial.begin(9600);
Serial.println("DHTxx test!");
dht.begin();
}

A difference between the old version and the updated version was the 'dht.begin();' statement in the setup block.

The Adafruit library isn't quite as robust as the previous library I'd been using, particularly with error handling, but it just worked after maybe 45 minutes of fiddling.

May doG help me if the XBee library stops working in a future Arduino IDE release!

A 'type' describes what your variable is. Like an integer (5), a string("Hello world"), a character("a"), a boolean (true or false), or a float (3.1415).

It looks like 'dht' is supposed to be a type but the arduino IDE does not recognize it since it isnt a normal type. This should be solved by importing a library that creates that type. Then the arduino can recognize it.

This is where your "#include " comes in. I would recommend changing it to "#include "dht.h".

Also, double check to make sure that dht.h is indeed a file that the arduino can access.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top