Acasă / Atelier / Microcontroler / Arduino / Ministatie meteo cu senzorul DHT11 si Arduino

Ministatie meteo cu senzorul DHT11 si Arduino

Desi o statie meteo ofera mai multe date decat temperatura si umiditatea, am considerat ca si aceste date sunt „bune” pentru o „ministatie meteo”…

Totul se bazeaza pe un senzor dedicat DHT11, care nu are o precize uimitoare, dar pentru aplicatii casnice este acceptabil (domeniu de temperatura 0..50oC cu precizie de +2oC, respectiv umiditate 20..90%RH cu o precizie de +5%RH).

Prima proba s-a facut cu senzorul DHT11 avand pinul conectat la A2 (analog 2) de la Arduino, iar afisajul cu cristale lichide cu 16 coloane si 2 randuri LCD1602 conectat ca in exemplele de pe site-ul Arduino, sketck-ul fiind:

// LCD1602A
// * LCD RS pin to digital pin 12
// * LCD Enable pin to digital pin 11
// * LCD D4 pin to digital pin 5
// * LCD D5 pin to digital pin 4
// * LCD D6 pin to digital pin 3
// * LCD D7 pin to digital pin 2
// * LCD R/W pin to ground
// * 10K resistor:
// * ends to +5V and ground
// * wiper to LCD VO pin (pin 3)
//Celsius to Fahrenheit conversion
double Fahrenheit(double celsius)
{
return 1.8 * celsius + 32;
}

double Kelvin(double celsius)
{
return celsius + 273.15;
}

double dewPoint(double celsius, double humidity)
{
double RATIO = 373.15 / (273.15 + celsius); // RATIO was originally named A0, possibly confusing in Arduino context
double SUM = -7.90298 * (RATIO – 1);
SUM += 5.02808 * log10(RATIO);
SUM += -1.3816e-7 * (pow(10, (11.344 * (1 – 1/RATIO ))) – 1) ;
SUM += 8.1328e-3 * (pow(10, (-3.49149 * (RATIO – 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;
}

#include
dht11 DHT11;
#define DHT11PIN A2 // sensor pin is at A2
// include the library code:
#include
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup()
{
Serial.begin(9600);
Serial.println(„DHT11 TEST PROGRAM „);
Serial.print(„LIBRARY VERSION: „);
Serial.println(DHT11LIB_VERSION);
Serial.println();
// set up the LCD’s number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print(„ministatie meteo”);
}

void loop()
{
Serial.println(„n”);

int chk = DHT11.read(DHT11PIN);

Serial.print(„Read sensor: „);
switch (chk)
{
case DHTLIB_OK:
Serial.println(„OK”);
break;
case DHTLIB_ERROR_CHECKSUM:
Serial.println(„Checksum error”);
break;
case DHTLIB_ERROR_TIMEOUT:
Serial.println(„Time out error”);
break;
default:
Serial.println(„Unknown error”);
break;
}

Serial.print(„Humidity (%): „);
Serial.println((float)DHT11.humidity, 2);

Serial.print(„Temperature (oC): „);
Serial.println((float)DHT11.temperature, 2);

Serial.print(„Temperature (oF): „);
Serial.println(Fahrenheit(DHT11.temperature), 2);

Serial.print(„Temperature (K): „);
Serial.println(Kelvin(DHT11.temperature), 2);

Serial.print(„Dew Point (oC): „);
Serial.println(dewPoint(DHT11.temperature, DHT11.humidity));

Serial.print(„Dew PointFast (oC): „);
Serial.println(dewPointFast(DHT11.temperature, DHT11.humidity));

delay(2000);

// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(1, 1);
// print the number of seconds since reset:
lcd.print((float)DHT11.temperature, 1);
lcd.write(0b11011111);
lcd.print(„C H=”);

lcd.print((float)DHT11.humidity, 1);
lcd.print(„%”);
}

Am facut si un filmulet numit ministatie meteo cu DHT11, LCD1602 si Arduino (I):

Am conectat apoi afisajul LCD 1602A cu interfata i2c cu sketch-ul gasit la http://blog.gotencool.com/2012_03_01_archive.html modificand adresa de la 0x27 la 0x20

#include
#include <liquidcrystal_i2c .h>
LiquidCrystal_I2C lcd(0x20,16,2); // 0x27 es la direccion del LCD 16×2
void setup(){
lcd.init();
lcd.backlight(); //enciende la iluminacion
lcd.setCursor(0, 0);
lcd.print(„Probando i2c”);
}
void loop(){
delay(1000);
}
apoi am combinat cele 2 sketch-uri:
#include
#include <liquidcrystal_i2c .h>
LiquidCrystal_I2C lcd(0x20,16,2); // 0x27 es la direccion del LCD 16×2
//Celsius to Fahrenheit conversion
double Fahrenheit(double celsius)
{
return 1.8 * celsius + 32;
}
double Kelvin(double celsius)
{
return celsius + 273.15;
}
double dewPoint(double celsius, double humidity)
{
double RATIO = 373.15 / (273.15 + celsius); // RATIO was originally named A0, possibly confusing in Arduino context
double SUM = -7.90298 * (RATIO – 1);
SUM += 5.02808 * log10(RATIO);
SUM += -1.3816e-7 * (pow(10, (11.344 * (1 – 1/RATIO ))) – 1) ;
SUM += 8.1328e-3 * (pow(10, (-3.49149 * (RATIO – 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;
}
#include
dht11 DHT11;
#define DHT11PIN A2 // sensor pin is at A2
void setup()
{
Serial.begin(9600);
Serial.println(„DHT11 TEST PROGRAM „);
Serial.print(„LIBRARY VERSION: „);
Serial.println(DHT11LIB_VERSION);
}
void loop()
{
Serial.println(„n”);
int chk = DHT11.read(DHT11PIN);
Serial.print(„Read sensor: „);
switch (chk)
{
case DHTLIB_OK:
Serial.println(„OK”);
break;
case DHTLIB_ERROR_CHECKSUM:
Serial.println(„Checksum error”);
break;
case DHTLIB_ERROR_TIMEOUT:
Serial.println(„Time out error”);
break;
default:
Serial.println(„Unknown error”);
break;
}
Serial.print(„Humidity (%): „);
Serial.println((float)DHT11.humidity, 2);
Serial.print(„Temperature (oC): „);
Serial.println((float)DHT11.temperature, 2);
Serial.print(„Temperature (oF): „);
Serial.println(Fahrenheit(DHT11.temperature), 2);
Serial.print(„Temperature (K): „);
Serial.println(Kelvin(DHT11.temperature), 2);
Serial.print(„Dew Point (oC): „);
Serial.println(dewPoint(DHT11.temperature, DHT11.humidity));
Serial.print(„Dew PointFast (oC): „);
Serial.println(dewPointFast(DHT11.temperature, DHT11.humidity));
delay(2000);
//LCD16x2 with i2c control – see http://www.tehnic.go.ro
lcd.init();
lcd.backlight(); //voi aprinde si led-ul de fundal
// set up the LCD’s number of columns and rows:
//lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print(„ministatie meteo”);
lcd.setCursor(1, 1);
// print the number of seconds since reset:
lcd.print((float)DHT11.temperature, 1);
lcd.write(0b11011111);
lcd.print(„C H=”);
lcd.print((float)DHT11.humidity, 1);
lcd.print(„%”);
delay(2000);
}
Un filmulet, care prezinta modul de functionare, se numeste ministatie meteo cu DHT11, LCD1602 si Arduino (II)

Am schimbat un pic aranjamentul din sketch:

#include
#include <liquidcrystal_i2c .h>
LiquidCrystal_I2C lcd(0x20,16,2); // 0x27 es la direccion del LCD 16×2

//Celsius to Fahrenheit conversion
double Fahrenheit(double celsius)
{
return 1.8 * celsius + 32;
}

double Kelvin(double celsius)
{
return celsius + 273.15;
}

double dewPoint(double celsius, double humidity)
{
double RATIO = 373.15 / (273.15 + celsius); // RATIO was originally named A0, possibly confusing in Arduino context
double SUM = -7.90298 * (RATIO – 1);
SUM += 5.02808 * log10(RATIO);
SUM += -1.3816e-7 * (pow(10, (11.344 * (1 – 1/RATIO ))) – 1) ;
SUM += 8.1328e-3 * (pow(10, (-3.49149 * (RATIO – 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;
}

#include
dht11 DHT11;
#define DHT11PIN A2 // sensor pin is at A2

void setup()
{
Serial.begin(9600);
Serial.println(„DHT11 TEST PROGRAM „);
Serial.print(„LIBRARY VERSION: „);
Serial.println(DHT11LIB_VERSION);

lcd.init();
lcd.backlight(); //voi aprinde si led-ul de fundal
// set up the LCD’s number of columns and rows:
//lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print(„ministatie meteo”);
}
void loop()
{
Serial.println(„n”);
int chk = DHT11.read(DHT11PIN);
Serial.print(„Read sensor: „);
switch (chk)
{
case DHTLIB_OK:
Serial.println(„OK”);
break;
case DHTLIB_ERROR_CHECKSUM:
Serial.println(„Checksum error”);
break;
case DHTLIB_ERROR_TIMEOUT:
Serial.println(„Time out error”);
break;
default:
Serial.println(„Unknown error”);
break;
}

Serial.print(„Humidity (%): „);
Serial.println((float)DHT11.humidity, 2);

Serial.print(„Temperature (oC): „);
Serial.println((float)DHT11.temperature, 2);

Serial.print(„Temperature (oF): „);
Serial.println(Fahrenheit(DHT11.temperature), 2);

Serial.print(„Temperature (K): „);
Serial.println(Kelvin(DHT11.temperature), 2);

Serial.print(„Dew Point (oC): „);
Serial.println(dewPoint(DHT11.temperature, DHT11.humidity));

Serial.print(„Dew PointFast (oC): „);
Serial.println(dewPointFast(DHT11.temperature, DHT11.humidity));
delay(2000);

//LCD16x2 with i2c control – see http://www.tehnic.go.ro

lcd.setCursor(0, 1);
lcd.print(„t=”);
lcd.print((float)DHT11.temperature, 1);
lcd.write(0b11011111);
lcd.print(„C H=”);
lcd.print((float)DHT11.humidity, 1);
lcd.print(„%”);
delay(2000);
}

 

 

Am introdus si partea de „reclama”: „www.tehnic.go.ro creat de niq_ro”, apoi „ministatie meteo versiunea 1m1” pastrand si posibilitatea monitorizarii seriale pe ecranul monitorului.

#include

#include <liquidcrystal_i2c .h>
LiquidCrystal_I2C lcd(0x20,16,2); // 0x20 is adress my I2C adapter
#include
dht11 DHT11;
#define DHT11PIN A2 // sensor pin is at A2
void setup()
{
Serial.begin(9600);
Serial.println(„DHT11 TEST PROGRAM „);
Serial.print(„LIBRARY VERSION: „);
Serial.println(DHT11LIB_VERSION);
lcd.init();
lcd.backlight(); //voi aprinde si led-ul de fundal
// set up the LCD’s number of columns and rows:
lcd.begin(16, 2);
// Print a logo message to the LCD.
lcd.print(„www.tehnic.go.ro”);
lcd.setCursor(0, 1);
lcd.print(„creat de niq_ro”);
delay (2500);
lcd.clear();
// Print a permanent message to the LCD.
lcd.print(„ministatie meteo”);
lcd.setCursor(2, 1);
lcd.print(„versiunea 1m1”);
delay (2500);
}
void loop()
{
Serial.println(„n”);
int chk = DHT11.read(DHT11PIN);
Serial.print(„Read sensor: „);
switch (chk)
{
case DHTLIB_OK:
Serial.println(„OK”);
break;
case DHTLIB_ERROR_CHECKSUM:
Serial.println(„Checksum error”);
break;
case DHTLIB_ERROR_TIMEOUT:
Serial.println(„Time out error”);
break;
default:
Serial.println(„Unknown error”);
break;
}
Serial.print(„Humidity (%): „);
Serial.println((float)DHT11.humidity, 2);
Serial.print(„Temperature (oC): „);
Serial.println((float)DHT11.temperature, 2);
//LCD16x2 with i2c control – see http://www.tehnic.go.ro
lcd.setCursor(0, 1);
lcd.print(„t=”);
lcd.print((float)DHT11.temperature, 1);
lcd.write(0b11011111);
lcd.print(„C H=”);
lcd.print((float)DHT11.humidity, 1);
lcd.print(„%”);
delay(2000);
}
Filmuletul care prezinta cum se numeste ministatie meteo cu DHT11, LCD1602 si Arduino (III)

Sursă: Nicu FLORICA

Despre Nicu FLORICA

ELECTRONICA este prima pasiune a mea... am inceput pe la 7 ani cu un radio cu galena, in vacanta de vara, a fost o bucurie enorma sa aud in casti posturi de radio si in loc sa joc fotbal, ascultam la minunea facuta de mine.. Pasiunea asta mi-a fost insuflata de tata, dar mie nu mi-au placut niciodata televizoarele cu lampi, vazand ca se pot testa cu mana, dar nestiind exact unde am primic cateva socuri care m-au cam speriat... Am inceput sa studiez revistele Tehnium, incat pana in 1998 am colectia aproape completa, de multe ori ajungeam intr-un oras si primul loc vizitat era Anticariatul. Am si alte reviste, cat de cat complete: RET, Radio, Electronistul, etc Am construit destule montaje si scheme si marea mea placere e sa imbunatatesc performantele lor.... In revista Tehnium am publicat 2 articole, unul in 1/'95 numit LUMINA DINAMICA si altul in 1/'97 numit INDICATOR TRICOLOR CU LED... BICOLOR. mi-am facut un site numai cu multe scheme: http://www.tehnic.go.ro si activez pe http://www.elforum.ro, unde am ID-ul niq_ro (acest ID il folosesc in toate forumurile si site-urile).

4 Comentarii

  1. buna ziua, ma intereseaza daca pot cumpara de la dumneavoastra acest proiect. ma refer la partea hardware gata facuta + software . Multumesc

  2. Interesant. Asa ceva doresc.
    Dar eu nu am asemenea cunostinte si nici macar speranta ca as putea invata asa ceva .
    Eu doresc sa citesc pe ceva.. umiditatea .
    Temperatura o pot citi pe termometru . As dori sa stiu temperatura din exteriorul apartamentului .
    indicele termic probabil este o impartire intre temperatura exterioara si umiditatea exterioara .

  3. Buna seara, doresc sa contruiesc un timer electronic cu display led 7 segmente 4 digiti. va rog o mana de ajutor
    Multumesc

  4. Eu ți-am dat odată adresa mea,etc și totuxși nu ai șters datele mele așa cum scrie mai sus.Te rog un lucru și anume dacă mi e valabil acest sait ,DE CE NU SÎNTEȚI CORECȚI S-AU SÎNTEȚI ȘMECHERI?

Lasă un răspuns

Adresa ta de email nu va fi publicată. Câmpurile obligatorii sunt marcate cu *

*