DHT 11 error

Hi I'm trying to get the DHT 11 sensor to work and wrote my own code but it failed so ive searched the internet and found a code sample so I can learn from it. When I go to compile the code I keep getting this error message Arduino: 1.8.6 (Windows 10), Board: "Arduino/Genuino Uno"

In file included from C:\Users\Rodney\AppData\Local\Temp\arduino_modified_sketch_859970\sketch_sep16a.ino:1:0:

C:\Users\Rodney\Documents\Arduino\libraries\Grove_Temperature_And_Humidity_Sensor/DHT.h:34:15: error: expected initializer before numeric constant

#define DHT11 11

^

C:\Users\Rodney\AppData\Local\Temp\arduino_modified_sketch_859970\sketch_sep16a.ino:3:13: note: in expansion of macro 'DHT11'

int DHTTYPE DHT11

^

C:\Users\Rodney\AppData\Local\Temp\arduino_modified_sketch_859970\sketch_sep16a.ino: In function 'void loop()':

sketch_sep16a:16:4: error: expected unqualified-id before '.' token

DHT.readHumidity = hum ;

^

sketch_sep16a:17:9: error: expected primary-expression before '.' token

temp=DHT.readTemperature()

^

exit status 1
expected unqualified-id before '.' token

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

as you can see I have tried writing it differently and added semi colons and removed semi colons but it still gives the same error .

here is the full code which since posting I have managed to get rid of original error message but now refuses to compile for uno

#include <DHT.h>
int DHTPIN = 8;
int DHTTYPE DHT11
DHT dht(DHTPIN,DHTTYPE); 
float hum;
float temp;

void setup() {
  Serial.begin (9600);
int DHT,begin;
  // put your setup code here, to run once:

}

void loop() {
  int readHumidity = hum ;
  int readTemperature = temp;
Serial.print ("humidity:");
Serial.print (hum);
Serial.print ("%,temp:");
Serial.print (temp);
delay (1000);
  // put your main code here, to run repeatedly:

}

Arduino: 1.8.6 (Windows 10), Board: "Arduino/Genuino Uno"

In file included from C:\Users\Rodney\AppData\Local\Temp\arduino_modified_sketch_515785\sketch_sep16a.ino:1:0:

C:\Users\Rodney\Documents\Arduino\libraries\Grove_Temperature_And_Humidity_Sensor/DHT.h:34:15: error: expected initializer before numeric constant

#define DHT11 11

^

C:\Users\Rodney\AppData\Local\Temp\arduino_modified_sketch_515785\sketch_sep16a.ino:3:13: note: in expansion of macro 'DHT11'

int DHTTYPE DHT11

^

exit status 1
Error compiling for board Arduino/Genuino Uno.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Please, have a look in this post for the setup : MEGA + dht11 + DHT-sensor-library-master.zip

When I include dht.begin in my code I keep getting an error code. I delete it and it will compile but gives readings of zero for temp and humidity.

int DHTTYPE DHT11Somethings missing here.

@OP

AWOL:
int DHTTYPE DHT11Somethings missing here.

What is missing in this statement: int DHTTYPE DHT11?

There are two 'language elements' that are missing here. If you think that DHTTYPE is an identifier (variable), you should use a ______ operator to assign the value DHT11 to it and then terminate the statement using a ___.

Ok I’m lost. The code is copied and I’ve never coded before and never been shown or had a education. So what is missing.

Post#5 has detected your mistakes, and Post#6 has given you hints for correcting these mistakes. You are not lost; the Forum is here to bring you up, proceed, and progress.

If you are asked to write a single line C-code to assign a value (say, 0x2345) into a 16-bit variable named x, what line would you write? Please, show it in reply.

Hints: The variable x must be preceded by a keyword called 'data type' which is byte if the variable is to hold 8-bit data (range: 0x00 - 0xFF) or int if the variable is to hold 16-bit data (range: 0x0000 - 0xFFFF). Here, 0x has been used to mean that the data that follows it has the hexadecimal (16) base. The intended value is stored in the variable (x) using = operator (called assignment operator). The C-line is always ended (terminated) by a ; (semicolon). The items: byte int = 0x234 ; are called language elements/tokens/constructs.

Ripcrow:
Ok I’m lost. The code is copied and I’ve never coded before and never been shown or had a education. So what is missing.

Copy / Paste programming is likely to make you very frustrated and get you nowhere. You may need to take a step back from your project and spend some time learning basic coding techniques and the C / C++ language. The Arduino IDE contains dozens of example programs to learn from -- starting from very simple concepts and moving forward.

Look at the differences in the two lines below. Notice the two things the first has that the second doesn't.

int DHTPIN = 8;
int DHTTYPE DHT11

made some adjustments but now refuses to compile . I understand copy and paste programming is not the best way but usually if I can see how its written I can understand how to write my own and understand how it works. Googling these error codes does not really give a decent answer either . Here is the updated code

[code]
#include <DHT.h>
int DHTPIN = 8 ;
int (DHTTYPE DHT11);
DHT dht(DHTPIN,DHT11); 
float hum ;
float temp;

void setup() {
  Serial.begin (9600);
byte  DHT, read ; 
  // put your setup code here, to run once:

}

void loop() {
int  readHumidity = hum;
  int readTemperature = temp;
  int hum (0);
Serial.print ("humidity:");
Serial.print (hum);
Serial.print ("%,temp:");
Serial.print (temp);
delay (2000);
  // put your main code here, to run repeatedly:

}

[/code]

Hi Ripcrow

GolamMostafa pointed you to this post, which explains how to set up the device.

Scroll down to the bottom of the page he pointed you to. (just open this link in a new window)
There is a code box.
His code works.
Compare the first four lines of your code, to the first four lines of his code.

Those first four lines are what have been causing the majority of your problems.

I haArduino: 1.8.6 (Windows 10), Board: "Arduino/Genuino Uno"

C:\Program Files (x86)\Arduino\arduino-builder -dump-prefs -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries C:\Users\Rodney\Documents\Arduino\libraries -fqbn=arduino:avr:uno -vid-pid=0X2341_0X0043 -ide-version=10806 -build-path C:\Users\Rodney\AppData\Local\Temp\arduino_build_377930 -warnings=none -build-cache C:\Users\Rodney\AppData\Local\Temp\arduino_cache_310246 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.arduinoOTA.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avrdude.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avr-gcc.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -verbose C:\Users\Rodney\AppData\Local\Temp\arduino_modified_sketch_821257\DHT_11.ino
C:\Program Files (x86)\Arduino\arduino-builder -compile -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries C:\Users\Rodney\Documents\Arduino\libraries -fqbn=arduino:avr:uno -vid-pid=0X2341_0X0043 -ide-version=10806 -build-path C:\Users\Rodney\AppData\Local\Temp\arduino_build_377930 -warnings=none -build-cache C:\Users\Rodney\AppData\Local\Temp\arduino_cache_310246 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.arduinoOTA.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avrdude.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avr-gcc.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -verbose C:\Users\Rodney\AppData\Local\Temp\arduino_modified_sketch_821257\DHT_11.ino
Using board 'uno' from platform in folder: C:\Program Files (x86)\Arduino\hardware\arduino\avr
Using core 'arduino' from platform in folder: C:\Program Files (x86)\Arduino\hardware\arduino\avr
Detecting libraries used...
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10806 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "C:\Users\Rodney\AppData\Local\Temp\arduino_build_377930\sketch\DHT_11.ino.cpp" -o nul
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10806 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "-IC:\Users\Rodney\Documents\Arduino\libraries\Adafruit_Unified_Sensor-1.0.2" "C:\Users\Rodney\AppData\Local\Temp\arduino_build_377930\sketch\DHT_11.ino.cpp" -o nul
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10806 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "-IC:\Users\Rodney\Documents\Arduino\libraries\Adafruit_Unified_Sensor-1.0.2" "-IC:\Users\Rodney\Documents\Arduino\libraries\Grove_Temperature_And_Humidity_Sensor" "C:\Users\Rodney\AppData\Local\Temp\arduino_build_377930\sketch\DHT_11.ino.cpp" -o nul
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10806 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "-IC:\Users\Rodney\Documents\Arduino\libraries\Adafruit_Unified_Sensor-1.0.2" "-IC:\Users\Rodney\Documents\Arduino\libraries\Grove_Temperature_And_Humidity_Sensor" "C:\Users\Rodney\Documents\Arduino\libraries\Grove_Temperature_And_Humidity_Sensor\DHT.cpp" -o nul
Generating function prototypes...
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10806 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "-IC:\Users\Rodney\Documents\Arduino\libraries\Adafruit_Unified_Sensor-1.0.2" "-IC:\Users\Rodney\Documents\Arduino\libraries\Grove_Temperature_And_Humidity_Sensor" "C:\Users\Rodney\AppData\Local\Temp\arduino_build_377930\sketch\DHT_11.ino.cpp" -o "C:\Users\Rodney\AppData\Local\Temp\arduino_build_377930\preproc\ctags_target_for_gcc_minus_e.cpp"
"C:\Program Files (x86)\Arduino\tools-builder\ctags\5.8-arduino11/ctags" -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives "C:\Users\Rodney\AppData\Local\Temp\arduino_build_377930\preproc\ctags_target_for_gcc_minus_e.cpp"
Compiling sketch...
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -flto -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10806 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "-IC:\Users\Rodney\Documents\Arduino\libraries\Adafruit_Unified_Sensor-1.0.2" "-IC:\Users\Rodney\Documents\Arduino\libraries\Grove_Temperature_And_Humidity_Sensor" "C:\Users\Rodney\AppData\Local\Temp\arduino_build_377930\sketch\DHT_11.ino.cpp" -o "C:\Users\Rodney\AppData\Local\Temp\arduino_build_377930\sketch\DHT_11.ino.cpp.o"
C:\Users\Rodney\AppData\Local\Temp\arduino_modified_sketch_821257\DHT_11.ino: In function 'void setup()':

DHT_11:12:6: error: expected primary-expression before '.' token

dht.begin();

^

C:\Users\Rodney\AppData\Local\Temp\arduino_modified_sketch_821257\DHT_11.ino: In function 'void loop()':

DHT_11:21:16: error: expected primary-expression before '.' token

int chk = DHT.read11(DHT11_PIN);

^

DHT_11:21:24: error: 'DHT11_PIN' was not declared in this scope

int chk = DHT.read11(DHT11_PIN);

^

DHT_11:23:21: error: expected primary-expression before '.' token

Serial.println(DHT.temperature);

^

DHT_11:25:22: error: expected primary-expression before '.' token

Serial.println (DHT.humidity);

^

Using library Adafruit_Unified_Sensor-1.0.2 at version 1.0.2 in folder: C:\Users\Rodney\Documents\Arduino\libraries\Adafruit_Unified_Sensor-1.0.2
Using library Grove_Temperature_And_Humidity_Sensor at version 1.0.0 in folder: C:\Users\Rodney\Documents\Arduino\libraries\Grove_Temperature_And_Humidity_Sensor
exit status 1
expected primary-expression before '.' tokenve tried a new code for the DHT 11 sensor. now I keep getting an expected primary expression error for a serial.println bit of code.

Wow! Lots of errors. Any code to relate them to?

I stole that code and it still says there are errors in that code. Error I get is stray \240 in code. beginning to think I got dodgy sensors or computer. Compiler says one line of code is wrong and yet its the same as previous lines and no code works,

[code]

#include <DHT.h>
#define DHTTYPE DHT11
#define dht DHT;
#define DHT11-PIN 9


void setup() {
  Serial.begin(9600);
  dht.begin();
 
  
  
  // put your setup code here, to run once:

}

void loop() {
  int chk = DHT.read11(DHT11_PIN);
  Serial.print("temperature =");
  Serial.println(DHT.temperature);
  Serial.print("HUMIDITY =");
  Serial.println(DHT.humidity);
  delay (1000);
  // put your main code here, to run repeatedly:

}

[/code]

Ripcrow:
I stole that code and it still says there are errors in that code. Error I get is stray \240 in code. beginning to think I got dodgy sensors or computer. Compiler says one line of code is wrong and yet its the same as previous lines and no code works,

Hey Ripcrow.

Don't double post.

While dodgy sensors or computer might be a (slim) possibility, more like it's malevolent forces at work and an evil spirit has infected your computer.

or...

You've made changes to your code, but there are still errors.

Post your new code, and have a cuppa.

#define DHT11-PIN 9 should probably be #define DHT11_PIN 9, you may find the rest of the errors disappear.

Also, why #define dht DHT when all you do is dht.begin()? Why not DHT.begin() as all you other references are to DHT?

It might also be useful to attach the library.

Now I see you've double posted. Totally un-cool.