Cov txheej txheem:

DHT12 (i2c Pheej Yig Humidity thiab Kub Sensor), Kev Siv Yooj Yim Yooj Yim: 14 Cov Kauj Ruam
DHT12 (i2c Pheej Yig Humidity thiab Kub Sensor), Kev Siv Yooj Yim Yooj Yim: 14 Cov Kauj Ruam

Video: DHT12 (i2c Pheej Yig Humidity thiab Kub Sensor), Kev Siv Yooj Yim Yooj Yim: 14 Cov Kauj Ruam

Video: DHT12 (i2c Pheej Yig Humidity thiab Kub Sensor), Kev Siv Yooj Yim Yooj Yim: 14 Cov Kauj Ruam
Video: AM2320 Digital Temperature and Humidity Sensor with LCD1602 and I2C (code) 2024, Kaum ib hlis
Anonim
DHT12 (i2c Pheej Yig Vaum thiab Kub Sensor), Kev Yooj Yim Yooj Yim
DHT12 (i2c Pheej Yig Vaum thiab Kub Sensor), Kev Yooj Yim Yooj Yim

Koj tuaj yeem pom qhov hloov tshiab thiab lwm yam ntawm kuv qhov chaw

Kuv nyiam sensor uas tuaj yeem siv nrog 2 xaim (i2c raws tu qauv), tab sis kuv nyiam qhov pheej yig.

Nov yog Arduino thiab esp8266 lub tsev qiv ntawv rau DHT12 series ntawm tus nqi qis heev ntsuas kub/av noo (tsawg dua 1 $) uas ua haujlwm nrog i2c lossis ib txoj hlua txuas.

Siv tau zoo heev yog tias koj xav siv esp01 (yog tias koj siv cov lej koj tsuas muaj 2 tus lej) los nyeem cov av noo thiab qhov kub thiab tso tawm ntawm i2c LCD.

AI nyeem tias qee zaum zoo li xav tau kev ntsuas, tab sis kuv muaj tsob ntoo ntawm qhov no thiab tau txais tus nqi zoo ib yam li DHT22. Yog tias koj tau ntsuas qhov teeb meem no, qhib qhov teeb meem ntawm github thiab kuv ntxiv kev siv.

Kauj Ruam 1: Yuav Ua Li Cas I2c Ua Haujlwm

Yuav ua li cas I2c Ua Haujlwm
Yuav ua li cas I2c Ua Haujlwm

I2C ua haujlwm nrog nws ob lub xov hlau, SDA (kab ntawv cov ntaub ntawv) thiab SCL (kab kab ntawv).

Ob txoj kab no tau qhib-ntws, tab sis raug rub nrog cov neeg tawm tsam.

Feem ntau muaj ib tus tswv thiab ib lossis ntau tus qhev ntawm kab, txawm hais tias tuaj yeem muaj ntau tus tswv, tab sis peb yuav tham txog qhov ntawd tom qab.

Ob tus tswv thiab qhev tuaj yeem xa lossis txais cov ntaub ntawv, yog li ntawd, cov cuab yeej tuaj yeem nyob hauv ib ntawm plaub lub xeev no: tus tswv xa, tus tswv tau txais, tus xa tus qhev, tus qhev tau txais.

Kauj ruam 2: Tsev qiv ntawv

Koj tuaj yeem nrhiav kuv lub tsev qiv ntawv ntawm no.

Txhawm rau rub tawm

Nyem rau DOWNLOADS khawm nyob rau hauv kaum sab xis saum toj, hloov lub npe uas tsis tau nyem DHT12.

Txheeb xyuas tias DHT nplaub tshev muaj DHT12.cpp thiab DHT12.h.

Muab DHT lub tsev qiv ntawv tais ceev tseg koj / tsev qiv ntawv / ntawv tais ceev tseg.

Koj yuav xav tsim lub tsev qiv ntawv subfolder yog nws yog koj thawj lub tsev qiv ntawv.

Rov pib dua IDE.

Kauj Ruam 3: Tus cwj pwm

Qhov kev tsis ncaj ncees no sim ua raws tus cwj pwm ntawm tus qauv DHT lub tsev qiv ntawv ntsuas (thiab luam ntau tus lej), thiab kuv ntxiv cov cai los tswj i2c olso tib yam.

Txoj hauv kev yog tib yam ntawm DHT lub tsev qiv ntawv sensor, nrog qee qhov ntxiv xws li lwg taw tes ua haujlwm.

Kauj Ruam 4: Kev siv I2c

Txhawm rau siv nrog i2c (chaw nyob thiab lub hauv paus SDA SCL tus pin) tus tsim yog:

DHT12 dht12;

thiab coj tus nqi pib rau SDA SCL tus pin.

(Nws tuaj yeem rov txhais dua nrog cov kws qhia tshwj xeeb rau esp8266, xav tau rau ESP-01). los yog

DHT12 dht12 (uint8_t addressOrPin)

addressOrPin -> chaw nyob

hloov chaw nyob.

Kauj Ruam 5: Ib Txoj Kev Siv Hlau

Txhawm rau siv ib lub xaim:

DHT12 dht12 (uint8_t addressOrPin, muaj tseeb)

addressOrPin -> pin

tus nqi boolean yog xaiv ntawm oneWire lossis i2c hom.

Kauj Ruam 6: Nyeem Tsis Txaus

Koj tuaj yeem siv Nws nrog "cuam tshuam", "nyeem yooj yim" lossis "puv": Tsis raug cai, tsuas yog thawj zaug nyeem ua qhov tseeb nyeem ntawm lub ntsuas, lwm qhov nyeem uas dhau los ua 2secs. luv yog cov nqi khaws cia ntawm thawj zaug nyeem.

// Kev nyeem ntawv ntawm lub sensor muaj 2secs ntawm lub sijhawm dhau los, tshwj tsis yog tias koj dhau qhov ntsuas qhov ntsuas

// Nyeem kub li Celsius (lub neej ntawd) ntab t12 = dht12.readTemperature (); // Nyeem kub li Fahrenheit (isFahrenheit = true) ntab f12 = dht12.readTemperature (tseeb); // Sensor nyeem ntawv kuj tseem tuaj yeem ntev txog 2 vib nas this 'qub' (nws lub sensor qeeb heev) ntab h12 = dht12.readHumidity (); // Xam qhov ntsuas cua sov hauv Fahrenheit (lub neej ntawd) ntab hif12 = dht12.computeHeatIndex (f12, h12); // Suav ntsuas qhov ntsuas cua sov hauv Celsius (isFahreheit = cuav) ntab hic12 = dht12.computeHeatIndex (t12, h12, cuav); // laij tus taw tes hauv Fahrenheit (lub neej ntawd) ntab dpf12 = dht12.dewPoint (f12, h12); // laij cov lwg taw tes hauv Celsius (isFahreheit = cuav) ntab dpc12 = dht12.dewPoint (t12, h12, cuav);

Kauj Ruam 7: Nyeem Yooj Yim

Nyeem yooj yim kom tau txais cov xwm txheej ntawm kev nyeem.

// Kev nyeem ntawv ntawm lub sensor muaj 2secs ntawm lub sijhawm dhau los, tshwj tsis yog tias koj dhau qhov yuam kev ntsuas

bool chk = dht12.read (); // nyeem tseeb yog ok, teeb meem nyeem tsis raug

// Nyeem kub li Celsius (lub neej ntawd)

ntab t12 = dht12.readTemperature (); // Nyeem kub li Fahrenheit (isFahrenheit = true) ntab f12 = dht12.readTemperature (tseeb); // Sensor nyeem ntawv kuj tseem tuaj yeem ntev txog 2 vib nas this 'qub' (nws lub sensor qeeb heev) ntab h12 = dht12.readHumidity (); // Xam qhov ntsuas cua sov hauv Fahrenheit (lub neej ntawd) ntab hif12 = dht12.computeHeatIndex (f12, h12); // Suav ntsuas qhov ntsuas cua sov hauv Celsius (isFahreheit = cuav) ntab hic12 = dht12.computeHeatIndex (t12, h12, cuav); // laij tus taw tes hauv Fahrenheit (lub neej ntawd) ntab dpf12 = dht12.dewPoint (f12, h12); // laij cov lwg taw tes hauv Celsius (isFahreheit = cuav) ntab dpc12 = dht12.dewPoint (t12, h12, cuav);

Kauj ruam 8: Nyeem tag nrho

Nyeem tag nrho kom tau txais cov xwm txheej tshwj xeeb.

// Kev nyeem ntawv ntawm lub sensor muaj 2secs ntawm lub sijhawm dhau los, tshwj tsis yog tias koj dhau qhov ntsuas qhov ntsuas

DHT12:: ReadStatus chk = dht12.readStatus (); Serial.print (F ("\ nRead sensor:")); hloov (chk) {rooj plaub DHT12:: OK: Serial.println (F ("OK")); tawg; rooj plaub DHT12:: ERROR_CHECKSUM: Serial.println (F ("Checksum yuam kev")); tawg; rooj plaub DHT12:: ERROR_TIMEOUT: Serial.println (F ("yuam kev tas sij hawm")); tawg; rooj plaub DHT12:: ERROR_TIMEOUT_LOW: Serial.println (F ("Sijhawm yuam kev ntawm lub teeb liab qis, sim muab siab rub tawm tsis kam")); tawg; rooj plaub DHT12:: ERROR_TIMEOUT_HIGH: Serial.println (F ("Sijhawm yuam kev ntawm lub teeb liab qis, sim muab qis rub tawm tsis kam")); tawg; rooj plaub DHT12:: ERROR_CONNECT: Serial.println (F ("Txuas yuam kev")); tawg; rooj plaub DHT12:: ERROR_ACK_L: Serial.println (F ("AckL yuam kev")); tawg; rooj plaub DHT12:: ERROR_ACK_H: Serial.println (F ("AckH yuam kev")); tawg; rooj plaub DHT12:: ERROR_UNKNOWN: Serial.println (F ("Tsis paub yuam kev DETECTED")); tawg; rooj plaub DHT12:: TSIS MUAJ: Serial.println (F ("Tsis muaj qhov tshwm sim")); tawg; default: Serial.println (F ("Tsis paub yuam kev")); tawg; }

// Nyeem kub li Celsius (lub neej ntawd)

ntab t12 = dht12.readTemperature (); // Nyeem kub li Fahrenheit (isFahrenheit = true) ntab f12 = dht12.readTemperature (tseeb); // Sensor nyeem ntawv kuj tseem tuaj yeem ntev txog 2 vib nas this 'qub' (nws lub sensor qeeb heev) ntab h12 = dht12.readHumidity (); // Xam qhov ntsuas cua sov hauv Fahrenheit (lub neej ntawd) ntab hif12 = dht12.computeHeatIndex (f12, h12); // Suav ntsuas qhov ntsuas cua sov hauv Celsius (isFahreheit = cuav) ntab hic12 = dht12.computeHeatIndex (t12, h12, cuav); // laij tus taw tes hauv Fahrenheit (lub neej ntawd) ntab dpf12 = dht12.dewPoint (f12, h12); // laij tus lej taw tes hauv Celsius (isFahreheit = cuav) ntab dpc12 = dht12.dewPoint (t12, h12, cuav);

Kauj Ruam 9: Daim Duab Sib Txuas

Nrog cov piv txwv, muaj daim duab txuas, nws yog ib qho tseem ceeb kom siv qhov rub tawm kom raug.

Ua tsaug rau Bobadas, dplasa thiab adafruit, los qhia cov cai hauv github (qhov twg kuv coj qee cov cai thiab cov tswv yim).

Kauj ruam 10: Arduino: OneWire

Arduino: OneWire
Arduino: OneWire

Kauj Ruam 11: Arduino: I2c

Arduino: Kuv 2c
Arduino: Kuv 2c

Kauj ruam 12: Esp8266 (D1Mini) OneWire

Esp8266 (D1Mini) OneWire
Esp8266 (D1Mini) OneWire

Kauj Ruam 13: Esp8266 (D1Mini) I2c

Esp8266 (D1Mini) I2c
Esp8266 (D1Mini) I2c

Kauj ruam 14: Ua tsaug

Chaw ua si Arduino (https://playground.arduino.cc/Main/DHT12SensorLibrary)

i2c project series (Sau):

  • Kub ntsuas qhov ntsuas kub
  • Analog nthuav dav
  • Cov nthuav dav
  • Zaub Zaub

Pom zoo: