Go Down

Topic: yet another DHT11 Class for Arduino (Read 26322 times) previous topic - next topic

robtillaart

@jkestr,

thanks for using the library, I'll update the playground article with the link you posted.
Is very informative.
If there are any problems, please let me know.
Rob Tillaart

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

5rEyErEm

#46
Dec 25, 2013, 10:16 pm Last Edit: Feb 08, 2014, 02:45 pm by robtillaart Reason: 1
I would like to thank you for the code for the DHT11. I made some changes to incorporate a second DHT11 and a serial LCD (LCM1602).I would like to make this available to others that need the help, like myself.

Thank you again.
Code: [Select]

/* YourDuino.com Example Software Sketch
  DHT11 Humidity and Temperature Sensor test
  Credits: Rob Tillaart */

/*-----( Import needed libraries )-----*/
#include <dht11.h>
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>

/*-----( Declare objects )-----*/
dht11 DHT11;
dht11 DHT11_2;

/*-----( Declare Constants, Pin Numbers )-----*/
#define DHT11PIN 2       //DHT11 Indoor
#define DHT11_2PIN 4     //DHT11 Outdoor

#define I2C_ADDR    0x27  // Define I2C Address where the PCF8574A is
#define BACKLIGHT_PIN     3  //This pin is internal. Do not edit.
#define En_pin  2            //This pin is internal. Do not edit.
#define Rw_pin  1            //This pin is internal. Do not edit.
#define Rs_pin  0            //This pin is internal. Do not edit.
#define D4_pin  4            //This pin is internal. Do not edit.
#define D5_pin  5            //This pin is internal. Do not edit.
#define D6_pin  6            //This pin is internal. Do not edit.
#define D7_pin  7            //This pin is internal. Do not edit.
LiquidCrystal_I2C       lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);

void setup()   /*----( SETUP: RUNS ONCE )----*/
{
 lcd.begin (20,4,LCD_5x8DOTS);
 lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE); // init the backlight
 lcd.setBacklight(HIGH);
 //Indoor rH setup
 lcd.setCursor (0,0);
 lcd.print("rH Inside:   %" );

 //degree symbol setup
 lcd.setCursor (11,1);
 lcd.print((char)223);
 lcd.print("C");
 lcd.setCursor (16,1);
 lcd.print((char)223);
 lcd.print("F");

 //Indoor temp setup
 lcd.setCursor (0,1);
 lcd.print("Temp In:");

   //Outside rH setup
 lcd.setCursor (0,2);
 lcd.print("rH Outside:   %" );

 //degree symbol setup
 lcd.setCursor (12,3);
 lcd.print((char)223);
 lcd.print("C");
 lcd.setCursor (17,3);
 lcd.print((char)223);
 lcd.print("F");

 //Outside temp setup
 lcd.setCursor (0,3);
 lcd.print("Temp Out:");

}/*--(end setup )---*/

void loop()   /*----( LOOP: RUNS CONSTANTLY )----*/
{
 int chk = DHT11.read(DHT11PIN);
 int chk_2 = DHT11_2.read(DHT11_2PIN);

 //LCD printing
 // DHT11 number 1 - Indoor
 lcd.setCursor (11,0); //set the cursor for hunidity
 lcd.print((float)DHT11.humidity, 0);
 lcd.setCursor (9,1); // set the cursor for temp
 lcd.print((float)DHT11.temperature, 0);
 lcd.setCursor (14,1); // set the cursor for F temp
 lcd.print(Fahrenheit(DHT11.temperature), 0);

 //DHT11 number 2 - Outdoor
 lcd.setCursor (12,2); //set the cursor for hunidity
 lcd.print((float)DHT11_2.humidity, 0);
 lcd.setCursor (10,3); // set the cursor for temp
 lcd.print((float)DHT11_2.temperature, 0);
 lcd.setCursor (15,3); // set the cursor for F temp
 lcd.print(Fahrenheit(DHT11_2.temperature), 0);

 delay(2000);
}/* --(end main loop )-- */

/*-----( Declare User-written Functions )-----*/
//
//Celsius to Fahrenheit conversion
double Fahrenheit(double celsius)
{
  return 1.8 * celsius + 32;
}

//Celsius to Kelvin conversion
double Kelvin(double celsius)
{
  return celsius + 273.15;
}

// dewPoint function NOAA
// reference: http://wahiduddin.net/calc/density_algorithms.htm
double dewPoint(double celsius, double humidity)
{
  double A0= 373.15/(273.15 + celsius);
  double SUM = -7.90298 * (A0-1);
  SUM += 5.02808 * log10(A0);
  SUM += -1.3816e-7 * (pow(10, (11.344*(1-1/A0)))-1) ;
  SUM += 8.1328e-3 * (pow(10,(-3.49149*(A0-1)))-1) ;
  SUM += log10(1013.246);
  double VP = pow(10, SUM-3) * humidity;
  double T = log(VP/0.61078);   // temp var
  return (241.88 * T) / (17.558-T);
}

// delta max = 0.6544 wrt dewPoint()
// 5x faster than dewPoint()
// reference: http://en.wikipedia.org/wiki/Dew_point
double dewPointFast(double celsius, double humidity)
{
  double a = 17.271;
  double b = 237.7;
  double temp = (a * celsius) / (b + celsius) + log(humidity/100);
  double Td = (b * temp) / (a - temp);
  return Td;
}

/* ( THE END ) */

Update moderator: added code tags

robtillaart

please modify your post and put code tags around it..
selct yout code and press the # button above the smileys and then press save.
Rob Tillaart

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

brooksdr

Just got one of these devices and am using it on an Arduinio Pro. Note that Serial.begin() must be set to Serial.begin(9600) and (perhaps this is obvious, but not to a newbie like me) the pin to access the dht11 is a digital pin (2), not an analog pin.

axe673

Hello,

Newbie here. I seem to be having trouble with this library. I copy and pasted the .cpp and the .h files exactly as they were presented in to the compiler. Upon compiling, I get the error message saying:

"core/core.a(main.cpp.o): In function `main':
/Users/axe673/Library/Arduino15/packages/arduino/hardware/avr/1.6.11/cores/arduino/main.cpp:43: undefined reference to `setup'
/Users/axe673/Library/Arduino15/packages/arduino/hardware/avr/1.6.11/cores/arduino/main.cpp:46: undefined reference to `loop'
collect2: error: ld returned 1 exit status"


I cannot seem to figure out how to remedy this problem. Any help is greatly appreciated.

Thank you

PaulS

Quote
I cannot seem to figure out how to remedy this problem.
Define a setup() and loop() function. Not exactly rocket science.

Ajioz_

Hi Rob,

I tried the code on Arduino  Uno Rev3, and the result is discouraging.  Below is the output, I am  the sensor couldn't just start.


DHT11 TEST PROGRAM
LIBRARY VERSION: 0.1.14



Read sensor: Time out error
Humidity (%): -999.00
Temperature (°C): -999.00
Temperature (°F): -1766.20
Temperature (°K): -725.85
Dew Point (°C): nan
Dew PointFast (°C): nan
*/


As seen from the printout, I used the most recent library for the DHT 11.

Ajioz_

Hi Rob,

I tried the DHTlib library for my Arduino Uno Rev3,  but the output shows that the sensor couldn't pick up, below is the result :


DHT11 TEST PROGRAM
LIBRARY VERSION: 0.1.14


Read sensor: Time out error
Humidity (%): -999.00
Temperature (°C): -999.00
Temperature (°F): -1766.20
Temperature (°K): -725.85
Dew Point (°C): nan
Dew PointFast (°C): nan

Above shows I'm using the most recent library.

How do I fix this problem?

Regards
Ajioz


Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy