I am trying to do a project on temperature control and found an example but cannot get the code to work. I have read forums and tried to fix the issue which is below the code.
Code:
#include<DHT.h> // Including library for dht
#include<LiquidCrystal.h>
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
#define dht11dpin 12
DHT11;
#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()
DHT11.read(DHT11pin);
int temp = DHT11.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);
}
else if (temp == 28)
{
analogWrite(pwm, 153);
lcd.print("Fan Speed: 60% ");
delay(100);
}
else if (temp == 29)
{
analogWrite(pwm, 204);
lcd.print("Fan Speed: 80% ");
delay(100);
}
else if (temp > 29)
{
analogWrite(pwm, 255);
lcd.print("Fan Speed: 100% ");
delay(100);
}
delay(3000);
}
Error:
In file included from C:\Users\neilb\Documents\Arduino\sketch_jan20b\sketch_jan20b.ino:2:0:
C:\Users\neilb\Documents\Arduino\libraries\DHT_sensor_library/DHT.h:32:15: error: expected unqualified-id before numeric constant
#define DHT11 11
^
C:\Users\neilb\Documents\Arduino\sketch_jan20b\sketch_jan20b.ino:6:1: note: in expansion of macro 'DHT11'
DHT11;
^
C:\Users\neilb\Documents\Arduino\libraries\DHT_sensor_library/DHT.h:32:15: error: expected initializer before numeric constant
#define DHT11 11
^
C:\Users\neilb\Documents\Arduino\sketch_jan20b\sketch_jan20b.ino:35:1: note: in expansion of macro 'DHT11'
DHT11.read(DHT11pin);
^
sketch_jan20b:36: error: request for member 'temperature' in '11', which is of non-class type 'int'
int temp=DHT11.temperature;
^
sketch_jan20b:37: error: 'lcd' does not name a type
lcd.setCursor(0,0);
^
sketch_jan20b:38: error: 'lcd' does not name a type
lcd.print("Temperature:");
^
sketch_jan20b:39: error: 'lcd' does not name a type
lcd.print(temp); // Printing temperature on LCD
^
sketch_jan20b:40: error: 'lcd' does not name a type
lcd.write(1);
^
sketch_jan20b:41: error: 'lcd' does not name a type
lcd.print("C");
^
sketch_jan20b:42: error: 'lcd' does not name a type
lcd.setCursor(0,1);
^
sketch_jan20b:43: error: expected unqualified-id before 'if'
if(temp <26 )
^
sketch_jan20b:50: error: expected unqualified-id before 'else'
else if(temp==26)
^
sketch_jan20b:57: error: expected unqualified-id before 'else'
else if(temp==27)
^
sketch_jan20b:64: error: expected unqualified-id before 'else'
else if(temp==28)
^
sketch_jan20b:71: error: expected unqualified-id before 'else'
else if(temp==29)
^
sketch_jan20b:77: error: expected unqualified-id before 'else'
else if(temp>29)
^
sketch_jan20b:83: error: expected constructor, destructor, or type conversion before '(' token
delay(3000);
^
sketch_jan20b:84: error: expected declaration before '}' token
}
^
exit status 1
request for member 'temperature' in '11', which is of non-class type
1 Answer 1
It's a bit hard to see, but
DHT11;
does not look like a correct statement, assuming DHT11 is a class (not a define like shown) it should be something like
DHT11 dht;
where dht is an instance and you can use that.
Than in
DHT11.read(DHT11pin);
you should replace it by
dht.read(DHT11pin);
-
so got past that bit but getting issue with the line lcd.createChar(1, degree); saying degree was not declared in sopeneil brody– neil brody2018年01月20日 11:33:42 +00:00Commented Jan 20, 2018 at 11:33
-
degree should be a variable, which you haven't declared (unless it's global and you didn't post it).Michel Keijzers– Michel Keijzers2018年01月20日 13:48:34 +00:00Commented Jan 20, 2018 at 13:48
-
1Several variable declarations and the setup definition are prefixed by #. Those will prevent the line from being processed correctly. degree is one of those with that error.jose can u c– jose can u c2018年01月20日 17:19:33 +00:00Commented Jan 20, 2018 at 17:19
-
It seems the code has been changed since my comment.Michel Keijzers– Michel Keijzers2018年01月20日 19:05:19 +00:00Commented Jan 20, 2018 at 19:05
Explore related questions
See similar questions with these tags.
#
in#byte degree[8]
and#void setup()
?