Conexión de Arduino y AM2302
Materiales
- 1 Sensor AM2302.
- Arduino Uno, Arduino Nano.
Código
#include "DHT.h" // DHT & AM2302 library
// Data pin connected to AM2302
#define DHTPIN 2
#define DHTTYPE DHT22 // DHT 22 (AM2302)
DHT dht(DHTPIN, DHTTYPE); // LED pins
//////////////////////////////////////////////////////
//
// SETUP
//
void setup() {
// Setup serial monitor
Serial.begin(9600);
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)
float h = dht.readHumidity();
float t = dht.readTemperature();
// check if returns are valid, if they are NaN (not a number) then something went wrong!
if (isnan(t) || isnan(h)) {
Serial.println(F("Failed to read from DHT"));
}
else {
Serial.print(F("Humedad: "));
Serial.print(h);
Serial.print(F(" %\t"));
Serial.print(F("Temperatura: "));
Serial.print(t);
Serial.println(F(" C"));
}
// Wait 3 seconds
delay(3000);
}
Descargar Librería
Fuentes:http://arduinocostarica.blogspot.com/
0 comentarios:
Publicar un comentario