Cov txheej txheem:

Yuav Siv DHT11 Sensor Siv Arduino: 5 Kauj Ruam
Yuav Siv DHT11 Sensor Siv Arduino: 5 Kauj Ruam

Video: Yuav Siv DHT11 Sensor Siv Arduino: 5 Kauj Ruam

Video: Yuav Siv DHT11 Sensor Siv Arduino: 5 Kauj Ruam
Video: 051 Tuabneeg Yuav Siv Tug Nplaig 2024, Hlis ntuj nqeg
Anonim
Yuav Ua Li Cas Siv DHT11 Sensor Siv Arduino
Yuav Ua Li Cas Siv DHT11 Sensor Siv Arduino
Yuav Ua Li Cas Siv DHT11 Sensor Siv Arduino
Yuav Ua Li Cas Siv DHT11 Sensor Siv Arduino
Yuav Ua Li Cas Siv DHT11 Sensor Siv Arduino
Yuav Ua Li Cas Siv DHT11 Sensor Siv Arduino

Hauv qhov kev qhia no peb yuav sim DHT11 sensor siv Arduino.

DHT11 tuaj yeem siv los ntsuas qhov kub thiab txias.

Yuav tsum muaj cov khoom siv:

  • Arduino Nano Cov
  • DHT11 Kub thiab Vaum Sensor
  • Mini USB
  • Jumper cables

Yuav tsum muaj tsev qiv ntawv:

DHT Library

Kauj Ruam 1: Txuas DHT11 rau Arduino

Txuas DHT11 rau Arduino
Txuas DHT11 rau Arduino
Txuas DHT11 rau Arduino
Txuas DHT11 rau Arduino
Txuas DHT11 rau Arduino
Txuas DHT11 rau Arduino

Txuas DHT11 rau Arduino siv jumper cables.

Saib daim duab lossis ua raws cov lus qhia hauv qab no.

DHT11 rau Arduino

+ => + 5V

tawm => D12

- => GND

Tom qab ntawd txuas arduino rau lub khoos phis tawj siv lub mini USB

Kauj Ruam 2: Ntxiv DHT Library

Ntxiv DHT Library
Ntxiv DHT Library
Ntxiv DHT Library
Ntxiv DHT Library
Ntxiv DHT Library
Ntxiv DHT Library

Lub tsev qiv ntawv DHT tuaj yeem rub tawm ntawm no:

DHT11 Lub Tsev Qiv Ntawv.

Txhawm rau ntxiv lub tsev qiv ntawv saib thr duab saum toj no lossis ua raws cov lus qhia hauv qab no:

Qhib Sketch ==> Xws li Lub Tsev Qiv Ntawv ==> ntxiv. Zip Library

Nrhiav lub tsev qiv ntawv cov ntaub ntawv uas koj tau rub tawm.

Yog tias nws ua tiav, kaw Arduino thiab qhib nws dua.

Kauj Ruam 3: Xaiv Arduino Board

Xaiv Pawg Arduino
Xaiv Pawg Arduino

Nkag mus rau Cov Cuab Yeej thiab kho kho lub arduino board rau daim duab saum toj no.

Pawg "Arduino Nano"

Proccesor "ATmega328P (Old Bootloader)"

Txog cov kab lus ua tiav ntau ntxiv, koj tuaj yeem nyeem ntawm "Yuav Ua Li Cas Siv Arduino Nano v.3" uas kuv tau ua yav dhau los.

Kauj Ruam 4: Txoj Haujlwm

Program
Program

Suav nrog cov cai no los nyeem tus nqi los ntawm DHT11 sensor

// DHT Kub & Humidity Sensor // Unified Sensor Library Piv Txwv // Sau los ntawm Tony DiCola rau Adafruit Industries // Tshaj tawm hauv qab daim ntawv tso cai MIT.

// Xav tau cov tsev qiv ntawv Arduino hauv qab no:

// - DHT Sensor Library: https://github.com/adafruit/DHT-sensor-library // - Adafruit Unified Sensor Lib:

#suav nrog

#ncig #ncig

#define DHTPIN 2 // Cov lej pin txuas nrog DHT sensor

// Plaub hau HUZZAH ESP8266 nco tseg: siv tus pin 3, 4, 5, 12, 13 lossis 14 - // Tus pin 15 tuaj yeem ua haujlwm tab sis DHT yuav tsum raug txiav tawm thaum lub sijhawm rub tawm.

// Tsis pom zoo hom sensor uas siv:

//#define DHTTYPE DHT11 // DHT 11 #define DHTTYPE DHT22 // DHT 22 (AM2302) //#define DHTTYPE DHT21 // DHT 21 (AM2301)

// Saib phau ntawv qhia kom ntxaws txog kev thaiv lub xov tooj thiab siv:

//

DHT_Unified dht (DHTPIN, DHTTYPE);

uint32_t ncua MS;

void teeb tsa () {

Serial.begin (9600); // Pib ntaus ntawv. dht.begin (); Serial.println (F ("DHTxx Unified Sensor Piv Txwv")); // Luam tawm cov ntsuas kub kom paub meej. sensor_t sensor; dht.temperature (). getSensor (& sensor); Serial.println (F ("------------------------------------")); Serial.println (F ("Kub Sensor")); Serial.print (F ("Hom Sensor:")); Serial.println (sensor.name); Serial.print (F ("Driver Ver:")); Serial.println (sensor.version); Serial.print (F ("ID tshwj xeeb:")); Serial.println (sensor.sensor_id); Serial.print (F ("Tus nqi siab tshaj:")); Serial.print (sensor.max_value); Serial.println (F ("° C")); Serial.print (F ("Tus nqi qis:")); Serial.print (sensor.min_value); Serial.println (F ("° C")); Serial.print (F ("Kev daws teeb meem:")); Serial.print (sensor.resolution); Serial.println (F ("° C")); Serial.println (F ("------------------------------------")); // Sau cov ntsiab lus ntsuas cov av noo. dht.humidity (). getSensor (& sensor); Serial.println (F ("Humidity Sensor")); Serial.print (F ("Sensor yam:")); Serial.println (sensor.name); Serial.print (F ("Driver Ver:")); Serial.println (sensor.version); Serial.print (F ("ID tshwj xeeb:")); Serial.println (sensor.sensor_id); Serial.print (F ("Tus nqi siab tshaj:")); Serial.print (sensor.max_value); Serial.println (F ("%")); Serial.print (F ("Tus nqi qis:")); Serial.print (sensor.min_value); Serial.println (F ("%")); Serial.print (F ("Kev daws teeb meem:")); Serial.print (sensor.resolution); Serial.println (F ("%")); Serial.println (F ("------------------------------------")); // Teeb ncua ntawm kev nyeem ntawv sensor raws li cov ntsiab lus sensor. delayMS = sensor.min_delay / 1000; }

void voj () {

// Ncua nruab nrab ntawm kev ntsuas. ncua (delayMS); // Tau txais qhov xwm txheej kub thiab luam tawm nws tus nqi. sensors_event_t kev tshwm sim; dht.temperature (). getEvent (& kev tshwm sim); yog (isnan (event.temperature)) {Serial.println (F ("Yuam kev ntsuas kub!")); } lwm {Serial.print (F ("Kub:")); Serial.print (xwm txheej.temperature); Serial.println (F ("° C")); } // Tau txais cov xwm txheej ntub dej thiab sau nws tus nqi. dht.humidity (). getEvent (& kev tshwm sim); yog (isnan (event.relative_humidity)) {Serial.println (F ("Yuam kev nyeem cov av noo!")); } lwm {Serial.print (F ("Vaum:")); Serial.print (event.relative_humidity); Serial.println (F ("%")); }}

Los yog rub tawm cov ntawv hauv qab Sketch uas kuv tau muab hauv qab no.

Tom qab ntawd nyem upload thiab tos kom nws ua tiav.

Kauj ruam 5: Qhov tshwm sim

Qhov tshwm sim
Qhov tshwm sim
Qhov tshwm sim
Qhov tshwm sim

Txhawm rau pom qhov ntsuas ntawm qhov ntsuas kub thiab av noo, nyem Serial Monitor. Qhov txiaj ntsig yuav tshwm nyob rau ntawd.

Yog ua tiav cov txiaj ntsig yuav zoo li daim duab 1

yog tias lub sensor tsis tau teeb tsa nws yuav zoo li daim duab 2

ua tsaug rau koj nyeem, yog tias muaj lus nug tsuas yog sau nws hauv kab lus

Pom zoo: