I have built my first Arduino project - the Temperature controlled fan from the code and schematic on this site.
https://circuitdigest.com/microcontroller-projects/automatic-temperatur…
After some time I got past the library include problem to now have this:
sketch_dec26a:6: error: 'dht' does not name a type
dht DHT;
^
C:\Users\wfene\OneDrive\Documents\Arduino\sketch_dec26a\sketch_dec26a.ino: In function 'void loop()':
sketch_dec26a:39: error: expected unqualified-id before '.' token
DHT.read11(dht_dpin);
^
sketch_dec26a:40: error: expected primary-expression before '.' token
int temp=DHT.temperature;
^
exit status 1
'dht' does not name a type
Any help to clear this hurdle would be appreciated so I can put this to work on my solar furnace !
Here is the code as copied directly from the sketch editor:
#include<dht.h> // Including library for dht
#include<LiquidCrystal.h>
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
#define dht_dpin 12
dht DHT;
#define pwm 9
byte degree[8] =
{
0b00011,
0b00011,
0b00000,
0b00000,
0b00000,
0b00000,
0b00000,
0b00000
};
void setup()
{
lcd.begin(16, 2);
lcd.createChar(1, degree);
lcd.clear();
lcd.print(" Fan Speed ");
lcd.setCursor(0,1);
lcd.print(" Controlling ");
delay(2000);
analogWrite(pwm, 255);
lcd.clear();
lcd.print("Circuit Digest ");
delay(2000);
}
void loop()
{
DHT.read11(dht_dpin);
int temp=DHT.temperature;
lcd.setCursor(0,0);
lcd.print("Temperature:");
lcd.print(temp); // Printing temperature on LCD
lcd.write(1);
lcd.print("C");
lcd.setCursor(0,1);
if(temp <26 )
{
analogWrite(9,0);
lcd.print("Fan OFF ");
delay(100);
}
else if(temp==26)
{
analogWrite(pwm, 51);
lcd.print("Fan Speed: 20% ");
delay(100);
}
else if(temp==27)
{
analogWrite(pwm, 102);
lcd.print("Fan Speed: 40% ");
delay(100);
}void setup() {
// put your setup code here, to run once:
}
Which results in the following error messages:
sketch_dec27a:6: error: 'dht' does not name a type
sketch_dec27a:6: error: 'dht' does not name a type
dht DHT;
^
C:\Users\wfene\OneDrive\Documents\Arduino\sketch_dec27a\sketch_dec27a.ino: In function 'void loop()':
sketch_dec27a:39: error: expected unqualified-id before '.' token
DHT.read11(dht_dpin);
^
sketch_dec27a:40: error: expected primary-expression before '.' token
int temp=DHT.temperature;
^
exit status 1
'dht' does not name a type
* If I could just get past the 'dht DHT; I'm sure the rest can be sorted out. I wonder if the 'copy > paste' I do causes the error but the code looks just like the listing on the project page. I have 5 of these DHT sensors and have ideas for all ! If I never get the code sorted for them they are useless !
Thanks in advance for your help.
After much surfing I concluded that the error was based on which 'dth lib ' one used ! One github repository actually bemoaned the fact that the syntax in the various dthlib s varied widely and because the sketch code [c++] is case sensitive beginners like me will chase errors because of this.
Bottom line I found one that had sample code syntax which I transposed to my project and got to compile !
Glad you got it working.. I compiled your program and it has no errors here. So no doubt the library was the culprit
Aswinth Raj
PermalinkDid you use the same program given in that link or did you make any modifications? I tried the same program from the link and it compiled properly for me.
Its always a good practice to paste your code in the forum rather than pointing it to a link. This way people can help you a bit more better
- Log in or register to post comments
Joined August 16, 2016 1000Tuesday at 12:29 AM