China Post – Arduino DHT Sensor Temperatur und Luftfeuchtigkeit messen

Der DHT11 als Billigsensor für Temperatur und Luftfeuchtigkeit

DHT11 Sensor Temperatur Relative Luftfeuchtigkeit
DHT11 Sensor Temperatur Relative Luftfeuchtigkeit

Der DHT11 ist ein preiswerter Sensor (Ebay 2€) für Temperatur und Luftfeuchtigkeit. Die Kommunikation läuft über 1-Wire Protokoll. Dafür das er nur 2€ kostet muss man bezüglich Genauigkeit einige Abstriche machen. Alternativ kann man den etwas besseren DHT22 einsetzen. Vom DKT11 sind 3 und 4-polige Versionen im Umlauf.

Eigenschaften

  • 3 bis 5V Spannungsversorgung und E/A
  • 2.5mA max. Stromaufnahme
  • Messbereich Luftfeuchtigkeit 20-80% ±5%
  • Messbereich Temperatur 0-50°C ±2°C
  • Messrate maximal 1 Hz

Beschaltung (3polige Version)

  • Pin1 Betriebsspannung
  • Pin2 Kommunikation
  • Pin3 Masse

Fazit

Einfach und günstig. In 5 Minuten eingerichtet.

Arduino Bibliothek
Von Adafruit die DHT library herunterladen oder direkt in der Arduino Bibliothek suchen und installieren. Einen Digital Pin zur Kommunikation festlegen “#define DHTPIN 2 ” und fertig. Ausgabe auf dem seriellen Monitor oder Plotter.

[code lang=”arduino”]
// Example testing sketch for various DHT humidity/temperature sensors
// Written by ladyada, public domain

#include "DHT.h"

#define DHTPIN 2 // what digital pin we’re connected to

// Uncomment whatever type you’re using!
#define DHTTYPE DHT11 // DHT 11
//#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
//#define DHTTYPE DHT21 // DHT 21 (AM2301)

// Connect pin 1 (on the left) of the sensor to +5V
// NOTE: If using a board with 3.3V logic like an Arduino Due connect pin 1
// to 3.3V instead of 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

// Initialize DHT sensor.
// Note that older versions of this library took an optional third parameter to
// tweak the timings for faster processors. This parameter is no longer needed
// as the current DHT reading algorithm adjusts itself to work on faster procs.
DHT dht(DHTPIN, DHTTYPE);

void setup() {
Serial.begin(9600);
Serial.println("DHTxx test!");

dht.begin();
}

void loop() {
// Wait a few seconds between measurements.
delay(2000);

// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds ‘old’ (its a very slow sensor)
float h = dht.readHumidity();
// Read temperature as Celsius (the default)
float t = dht.readTemperature();
// Read temperature as Fahrenheit (isFahrenheit = true)
float f = dht.readTemperature(true);

// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println("Failed to read from DHT sensor!");
return;
}

// Compute heat index in Fahrenheit (the default)
float hif = dht.computeHeatIndex(f, h);
// Compute heat index in Celsius (isFahreheit = false)
float hic = dht.computeHeatIndex(t, h, false);

Serial.print("Humidity: ");
Serial.print(h);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(t);
Serial.print(" *C ");
Serial.print(f);
Serial.print(" *F\t");
Serial.print("Heat index: ");
Serial.print(hic);
Serial.print(" *C ");
Serial.print(hif);
Serial.println(" *F");
}
[/code]

[asa produkt_medium]B00SWNZTVW[/asa]

Arduino – Luftdruck und Temperatur messen – BMP180

Mit einen Arduino und einem Sensor für 2€(ebay China) kann man schon eine einfache Wetterstation bauen.
Der hier verwendete Sensor von Bosch,ein BMP180 misst und berechnet Temperatur und Luftdruck. Die Daten werden per I2C Bus an den Arduino übertragen. Der BMP180 arbeitet mit 3,3 Volt die der Arduino bereitstellt. Neben Masse brauchen wird noch die Takt und Datenleitung für den I2C Bus. Diese sind 5Volt tolerant.
Die Verkabelung ist wie auf dem Bild zu sehen sehr simple.
Das Handling des Sensors nimmt uns die SFE_BMP180 library ab.
Hier in dem Beispiel werden Temperatur und Luftdruck an die serielle Schnittstelle ausgegeben.
In Zeile 30 sollten wir noch die Höhe unseres Ortes eintragen.

Barometric Pressure Sensor Breakout - BMP180

[code language=”Arduino” title=”SFE_BMP180 library example sketch”]

/* SFE_BMP180 library example sketch

This sketch shows how to use the SFE_BMP180 library to read the
Bosch BMP180 barometric pressure sensor.
https://www.sparkfun.com/products/11824
Hardware connections:

– (GND) to GND
+ (VDD) to 3.3V

(WARNING: do not connect + to 5V or the sensor will be damaged!)

You will also need to connect the I2C pins (SCL and SDA) to your
Arduino. The pins are different on different Arduinos:

Any Arduino pins labeled: SDA SCL
Uno, Redboard, Pro: A4 A5
Mega2560, Due: 20 21
Leonardo: 2 3
*/

#include <SFE_BMP180.h>
#include <Wire.h>

SFE_BMP180 pressure;

#define ALTITUDE 85.0 //Hoehe von Braunschweig

void setup()
{
Serial.begin(9600);
Serial.println("REBOOT");

// Initialize the sensor (it is important to get calibration values stored on the device).

if (pressure.begin())
Serial.println("BMP180 init success");
else
{
connections.

Serial.println("BMP180 init fail\n\n");
while(1); // Pause forever.
}
}

void loop()
{
char status;
double T,P,p0,a;

// Loop here getting pressure readings every 10 seconds.

// If you want sea-level-compensated pressure, as used in weather reports,
// you will need to know the altitude at which your measurements are taken.
// We’re using a constant called ALTITUDE in this sketch:

Serial.println();
Serial.print("provided altitude: ");
Serial.print(ALTITUDE,0);
Serial.print(" meters, ");

status = pressure.startTemperature();
if (status != 0)
{
// Wait for the measurement to complete:
delay(status);

// Retrieve the completed temperature measurement:
// Note that the measurement is stored in the variable T.
// Function returns 1 if successful, 0 if failure.

status = pressure.getTemperature(T);
if (status != 0)
{

Serial.print("temperature: ");
Serial.print(T,2);
Serial.print(" deg C, ");

// Start a pressure measurement:
// The parameter is the oversampling setting, from 0 to 3 (highest res, longest wait).
// If request is successful, the number of ms to wait is returned.
// If request is unsuccessful, 0 is returned.

status = pressure.startPressure(3);
if (status != 0)
{
// Wait for the measurement to complete:
delay(status);

// Retrieve the completed pressure measurement:
// Note that the measurement is stored in the variable P.
// Note also that the function requires the previous temperature measurement (T).
// (If temperature is stable, you can do one temperature measurement for a number of pressure measurements.)
// Function returns 1 if successful, 0 if failure.

status = pressure.getPressure(P,T);
if (status != 0)
{
// Print out the measurement:
Serial.print("absolute pressure: ");
Serial.print(P,2);
Serial.print(" mb, ");

// The pressure sensor returns abolute pressure, which varies with altitude.
// To remove the effects of altitude, use the sealevel function and your current altitude.
// This number is commonly used in weather reports.
// Parameters: P = absolute pressure in mb, ALTITUDE = current altitude in m.
// Result: p0 = sea-level compensated pressure in mb

p0 = pressure.sealevel(P,ALTITUDE);
Serial.print("relative (sea-level) pressure: ");
Serial.print(p0,2);
Serial.print(" mb, ");

// On the other hand, if you want to determine your altitude from the pressure reading,
// use the altitude function along with a baseline pressure (sea-level or other).
// Parameters: P = absolute pressure in mb, p0 = baseline pressure in mb.
// Result: a = altitude in m.

a = pressure.altitude(P,p0);
Serial.print("computed altitude: ");
Serial.print(a,0);
Serial.print(" meters, ");

}
else Serial.println("error retrieving pressure measurement\n");
}
else Serial.println("error starting pressure measurement\n");
}
else Serial.println("error retrieving temperature measurement\n");
}
else Serial.println("error starting temperature measurement\n");

delay(5000); // Pause for 5 seconds.
}

[/code]