DHT11 temperature and humidity sensor

Hi
I am very new to arduino and am trying to use the DHT11 sensor and library but i keep getting error messages that i cant find a solution for
#include <DHT.h>
#include <DHT_U.h>

#define dht_apin A0;

void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
delay(500);
Serial.print("DHT11 Humidity and Temperature sensor\n\n");
delay(1000);
}

void loop() {
// put your main code here, to run repeatedly:
DHT.read11(dht_apin);
Serial.print("Current Humidity");
Serial.print(DHT.humidity);
delay(1000);
Serial.print("Current Temperature");
Serial.print(DHT.temperature);
delay(5000);
}
here is my code, it is probably attached incorrectly but i dont know how to attach it. Everything is probably wrong but it would be great is i could get started learning with some help

And the errors you are seeing are . . ?

Please remember to use code tags when posting code

#define dht_apin A0;Lose the semicolon

Try this,

#include <DHT.h>
//#include <DHT_U.h>
#define dht_pin A0
#define DHTTYPE DHT11 

float Temperature;
float Humidity;

DHT dht(dht_pin, DHTTYPE);

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  delay(500);
  Serial.print("DHT11 Humidity and Temperature sensor\n\n");
  delay(1000);
}

void loop() {
  // put your main code here, to run repeatedly:
  Temperature = dht.readTemperature(true); //true = fahrenheit
  Humidity = dht.readHumidity();
  Serial.print("Current Humidity: ");
  Serial.println(Humidity);
  delay(1000);
  Serial.print("Current Temperature: ");
  Serial.println(Temperature);
  delay(5000);
}

Thanks
the code is much better than mine however in serial monitor it says temperature and humidity are nan

endermaker:
Thanks
the code is much better than mine however in serial monitor it says temperature and humidity are nan

Check your wires, make sure your using the pullup resistor

How do i use pullup resistor?

endermaker:
How do i use pullup resistor?

Have a look at this for reference

unnamed.png

unnamed.png

Still no luck

Sorry i made a mistake, i forgot a part in setup. try this,

#include <DHT.h>
//#include <DHT_U.h>
#define dht_pin A0
#define DHTTYPE DHT11

float Temperature;
float Humidity;

DHT dht(dht_pin, DHTTYPE);

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  delay(500);
  Serial.print("DHT11 Humidity and Temperature sensor\n\n");
  delay(1000);
  pinMode(dht_pin , INPUT);
  dht.begin();
}

void loop() {
  // put your main code here, to run repeatedly:
  Temperature = dht.readTemperature(true); //true = fahrenheit
  Humidity = dht.readHumidity();
  Serial.print("Current Humidity: ");
  Serial.println(Humidity);
  delay(1000);
  Serial.print("Current Temperature: ");
  Serial.println(Temperature);
  delay(5000);
}

Still not working

endermaker:
Still not working

Hmm im not sure. i use that code for dht22 i have never used a dht11 tho i think it should work. What value resistor are you using can you show your wiring?

10k resistor

Try changing A0 to 14? assuming your using an arduino.

The value of A0 is 14 on the Uno

it still doesnt work

What does nan stand for?

Not a Number

Changing the 2 float values to integers make them both read as 0

Usually NaN is problem with wires or sensor.. if you change the floats to int you will lose the decimal

What can I do about this?