Pages: [1]   Go Down
Author Topic: I am having trouble with a DHT22 temperature sensor to work on Arduino Mini Pro  (Read 2621 times)
0 Members and 1 Guest are viewing this topic.
New York
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
« Last Edit: May 30, 2012, 04:56:37 pm by neimato1 » Logged

Fail Forward

Switzerland
Offline Offline
Faraday Member
**
Karma: 108
Posts: 5144
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 212
Posts: 13531
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


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

furthermore you must do this test
Code:
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.


Logged

Rob Tillaart

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

New York
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 smiley 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
« Last Edit: May 26, 2012, 08:47:22 pm by neimato1 » Logged

Fail Forward

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 212
Posts: 13531
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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


Logged

Rob Tillaart

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

0
Offline Offline
Shannon Member
****
Karma: 201
Posts: 11744
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Which Mini Pro?  5V?  3V3?  16MHz? 8MHz?
Logged

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

New York
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

5V 16mhz and I tried to set the pin10 to input but it didn't help
« Last Edit: May 27, 2012, 09:23:20 am by neimato1 » Logged

Fail Forward

New York
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 smiley-sad I don't understand why it doesn't work and I am really frustrated
« Last Edit: May 30, 2012, 04:55:35 pm by neimato1 » Logged

Fail Forward

Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Thanks
Steve
Logged

Australia
Offline Offline
Sr. Member
****
Karma: 11
Posts: 473
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Pages: [1]   Go Up
Jump to: