Ir ao conteúdo
  • Cadastre-se

Arduino Sensor DHT11 E Termistor NTC


Posts recomendados

  • Membro VIP

Olá.

Fiz um código para verificar temperatura ambiente. Para deixar a leitura mais precisa utilizei um DHT11 e um termistor NTC e com as leituras tirei a média de temperatura. Queria saber se eu tirando a média de temperatura ( Soma dos valores e divide por 2[nº de sensores] a a leitura fica realmente mais precisa ou se a leitura está completamente errada.Segue o código:

Nota: Utilizei como microcontrolador o Arduino UNO.

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

// REQUIRES the following Arduino libraries:
// - DHT Sensor Library: https://github.com/adafruit/DHT-sensor-library
// - Adafruit Unified Sensor Lib: https://github.com/adafruit/Adafruit_Sensor

#include "DHT.h"

#define Vin 4.88 // define constante igual a 5.0
#define T0 298.15 // define constante igual a 298.15 Kelvin
#define Rt 10000 // Resistor do divisor de tensão
#define R0 10000 // Valor da resistencia inicial do NTC
#define T1 273.15 // [K] in datasheet 0º C
#define T2 373.15 // [K] in datasheet 100° C
#define RT1 35563 // [ohms] resistencia in T1
#define RT2 549 // [ohms] resistencia in T2
float beta = 0.0; // parametros iniciais [K]
float Rinf = 0.0; // parametros iniciais [ohm]
float TempKelvin = 0.0; // variable output
float TempCelsius = 0.0; // variable output
float Vout = 0.0; // Vout in A0
float Rout = 0.0; // Rout in A0

#define DHTPIN A1     // Digital pin connected to the DHT sensor
// Feather HUZZAH ESP8266 note: use pins 3, 4, 5, 12, 13 or 14 --
// Pin 15 can work but DHT must be disconnected during program upload.

// 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(F("Testando DHT11"));
beta = (log(RT1 / RT2)) / ((1 / T1) - (1 / T2)); // calculo de beta
Rinf = R0 * exp(-beta / T0); // calculo de Rinf
  dht.begin();
  Serial.println("--------------");
  Serial.println(" ");
}

void loop() {
  // Wait a few seconds between measurements.
  delay(2000);
Vout = Vin * ((float)(analogRead(0)) / 1024.0); // calculo de V0 e leitura de A0
Rout = (Rt * Vout / (Vin - Vout)); // calculo de Rout
TempKelvin = (beta / log(Rout / Rinf)); // calculo da temp. em Kelvins
TempCelsius = TempKelvin - 273.15; // calculo da temp. em Celsius

  // 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) ) {
    Serial.println(F("Falha na leitura do sensor de temperatura DHT11"));
    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);
float mediaT = ((t+TempCelsius)/2);
  Serial.print(F("Humidity: "));
  Serial.println(h);
  Serial.print(F("Temperatura_DHT: "));
  Serial.println(t);
  Serial.print("Temperatura_NTC:"); // imprime no monitor serial
  Serial.println(TempCelsius); // imprime temperatura Celsius
  Serial.println("--------------");
  Serial.print("Média_Temperatura");
  Serial.println(mediaT);
  Serial.println("--------------");
  Serial.println(" ");
}

 

Link para o comentário
Compartilhar em outros sites

Crie uma conta ou entre para comentar

Você precisa ser um usuário para fazer um comentário

Criar uma conta

Crie uma nova conta em nossa comunidade. É fácil!

Crie uma nova conta

Entrar

Já tem uma conta? Faça o login.

Entrar agora

Sobre o Clube do Hardware

No ar desde 1996, o Clube do Hardware é uma das maiores, mais antigas e mais respeitadas comunidades sobre tecnologia do Brasil. Leia mais

Direitos autorais

Não permitimos a cópia ou reprodução do conteúdo do nosso site, fórum, newsletters e redes sociais, mesmo citando-se a fonte. Leia mais

×
×
  • Criar novo...