Go Down

Topic: I am having trouble with a DHT22 temperature sensor to work on Arduino Mini Pro (Read 2 times) previous topic - next topic

neimato1

I have tested the sensor on an Arduino Uno and it worked flawlessly, when I tried to get it working on an Arduino Mini Pro, the sensor wasn't even acknowledged by the board. I think it has to do with electricity going through the sensor but I am not entirely sure. I used a digital pin to supply power to the sensor, and I have another digital pin to read the sensor values, I'm not to sure if I need a seperate power source for the sensor or if there is something wrong with my code. My conclusion is I need an additional power source to run this sensor, but I would like to verify that before I look into it.

Quote
// Example testing sketch for various DHT humidity/temperature sensors
// Written by ladyada, public domain

#include "DHT.h"

#define DHTPIN 10     // what pin we're connected to

#define DHTTYPE DHT22   // DHT 22  (AM2302)


const int a = 12;          // the number of the LED pin
const int b = 6;
const int c = 13;
const int s = 2;


// Connect pin 1 (on the left) of the sensor to +5V
// Connect pin 2 of the sensor to whatever your DHTPIN is
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor

DHT dht(DHTPIN, DHTTYPE);

void setup() {
 Serial.begin(9600);
 Serial.println("DHT test!");
 pinMode(a, OUTPUT);  
 pinMode(b, OUTPUT);
 pinMode(c, OUTPUT);
 pinMode(s, OUTPUT);
 dht.begin();
 
}

void loop() {
 // Reading temperature or humidity takes about 250 milliseconds!
 // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
 digitalWrite(s, HIGH);
 float h = dht.readHumidity();
 float t = dht.readTemperature();
 // float f = t*9/5 + 32; //for Farenheit reading


if(t < 30.50)
{
  digitalWrite(a, HIGH);
}
else {
   digitalWrite(a, LOW);
   digitalWrite(b, HIGH);
}

if(t > 31.20)
{
  digitalWrite(c, HIGH);
  digitalWrite(a, LOW);
  digitalWrite(b, LOW);
}
if (isnan(t) || isnan(h)) {
   Serial.println("Failed to read from DHT");
   digitalWrite(c, HIGH);
   digitalWrite(a, HIGH);
 
 }else {
   Serial.print("Humidity: ");
   Serial.print(h);
   Serial.print(" %\t");
   Serial.print("Temperature: ");
   Serial.print(t);
   Serial.println("*C");
   
   //Serial.println(" *F");
 }
 
}
 
 


Here is the Circuit Schematics, the LED Grounds are all connected
Fail Forward

pylon

The DHT-22 needs a max of 2.1mA of current, so driving it from an Arduino output pin should be save.

Wait for a second or so after powering the sensor before you request readings. Maybe this solves your problems.

You haven't supplied a drawing or photo of your circuit nor a detailed description.

robtillaart


You should have 2 seconds between reads of the sensor , see the datasheet.

furthermore you must do this test
Code: [Select]

if (isnan(t) || isnan(h)) {
    Serial.println("Failed to read from DHT");


before processing the t and h variables

you just did the other way around.


Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

neimato1

I used the serial monitor to test it and it gave me garble. I tested the sensor with the serial monitor before and the readings are pretty fast its about once every second with the arduino uno . I am drawing a sketch of my circuit now for review :) and the location of the test shouldn't matter because if it can't read the sensor it would use the test I know it isn't working because the test also turns two of the LEDs on which is only happens if the sensor isn't being recognized
Fail Forward

robtillaart

Do you have a pull up resistor on the data line?  might help.

alternatively try my DHTlib & examples  - http://arduino.cc/playground/Main/DHTLib -


Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

MarkT

[ I won't respond to messages, use the forum please ]

neimato1

5V 16mhz and I tried to set the pin10 to input but it didn't help
Fail Forward

neimato1

I figured out the problem, so it turns out that the FTDI cable that I am using to test out the arduino had a current of 3.3V and DHT requires a minimum of 3.5V, so after freaking out I tried a 9V, I just connected 9V to RAW and it still doesn't work :( I don't understand why it doesn't work and I am really frustrated
Fail Forward

ste5eu

Hi
Did you ever solve this problem as I have the same issue?

Thanks
Steve

mauried

You need a pullup resistor of between around 3.3K and 10K on the sensor data line.
Without one , it might work , but will be very unreliable.

Go Up