Cov txheej txheem:

Raspberry Pi / DHT11 - Ntsuas Vaum thiab Kub: 4 Kauj Ruam
Raspberry Pi / DHT11 - Ntsuas Vaum thiab Kub: 4 Kauj Ruam

Video: Raspberry Pi / DHT11 - Ntsuas Vaum thiab Kub: 4 Kauj Ruam

Video: Raspberry Pi / DHT11 - Ntsuas Vaum thiab Kub: 4 Kauj Ruam
Video: Interfacing DHT11 Humidity and Temperature Sensor using Raspberry Pi Pico 2024, Kaum ib hlis
Anonim
Raspberry Pi / DHT11 - Ntsuas Vaum thiab Kub
Raspberry Pi / DHT11 - Ntsuas Vaum thiab Kub

Kuv xav ntsuas qhov ntsuas kub thiab av noo siv kuv Raspberry Pi. Kuv xaiv DHT11 sensor vim nws muaj zog thiab pheej yig. Kev teeb tsa nws kuj tseem yog cov ntaub ntawv zoo tab sis muaj ntau qhov tsis txaus ntseeg ntawm txoj kev uas kuv xav tsom mus rau.

DHT11 muaj 4 tus pin. Sab laug feem ntau yog rau Vcc lossis tus lej zoo (+) tus pin uas txuas nrog Raspberry Pi 3.3V tus pin. Tus pin tom ntej hla yog cov ntaub ntawv tus lej uas yuav tsum txuas nrog GPIO tus pin ntawm Raspberry Pi. Ob tus pin no yuav tsum txuas nrog siv 4.7K resistor.

Tus lej thib 3 ntawm sab laug tsis siv. Tus sab xis thiab tus pin thib plaub yog hauv av lossis tus pin tsis zoo uas yuav tsum txuas nrog rau ib qho ntawm tus pin hauv av ntawm Raspberry Pi.

Kauj Ruam 1: Cov Cheeb Tsam Yuav Tsum Tau

Cov Cheeb Tsam Yuav Tsum Tau
Cov Cheeb Tsam Yuav Tsum Tau

1. Raspberry Pi

2. DHT11

3. 4.7k resistor

4. Ntau yam xov tooj ntawm tes

5. Cov qhob cij

Kauj Ruam 2: Txuas Yam

Txuas Yam
Txuas Yam
Txuas Yam
Txuas Yam

Txuas Raspberry Pi thiab DHT11 raws li hauv qab no:

DHT11 (+ tus pin) RaspberryPi (3.3V tus pin)

DHT11 (tus lej tus lej) RaspberryPi (tus pin GPIO - Kuv siv GPIO22)

DHT11 (tus lej thib 3) Tsis muaj kev txuas

DHT11 (-tus pin) ------ Raspberry Pi (gnd pin)

Kauj Ruam 3: Txhim Kho Software

Los ntawm kab lus RaspberryPi, ua cov hauv qab no: (NCO TSEG, tsis txhob tso SUDO)

sudo git clone

Koj yuav tsum pom - Cloning rau 'Adafruit_Python_DHT' … tej thaj chaw deb: Suav cov khoom: 249, ua tiav. tej thaj chaw deb: Tag nrho 249 (delta 0), rov qab siv 0 (delta 0), ntim rov qab siv 249 Tau txais cov khoom: 100% (249/249), 77.01 KiB, ua tiav. Kev daws qhov deltas: 100% (142/142), ua tiav.

cd Adafruit_Python_DHT/

sudo apt-tau hloov tshiab sudo apt-tau nruab tsim-qhov tseem ceeb sej-dev python-openssl

ls ua

Koj yuav tsum pom - Adafruit_DHT piv txwv ez_setup.py LICENSE README.md setup.py source

cd Adafruit_DHT/

Koj yuav tsum pom -Beaglebone_Black.py common.py _init_.py platform_detect.py Raspberry_Pi_2.py Raspberry_Pi.py Test.py

sudo python setup.py nruab

(Nco tseg, yog tias koj hla cov kauj ruam no ces koj yuav pom qhov ua yuam kev - Traceback (hu xov tooj tsis ntev los no):

Cov ntaub ntawv "./AdafruitDHT.py", kab 24, hauv ntshuam Adafruit_DHT ImportError: Tsis muaj lub npe hu ua Adafruit_DHT)

cd piv txwv

sudo./AdafruitDHT.py 11 22 (11 = DHT11 thiab 22 = GPIO22 uas koj tau xaiv ua ntej)

Koj yuav tsum pom Temp = 18.0* Vaum = 46.0% (piv txwv li qhov kub thiab txias rau koj ib puag ncig)

Kauj Ruam 4: Yuav Ua Li Cas Nrog Qhov Tawm

Yog li, raws li peb tau pom, cov zis yog "Temp = 18.0* Vaum = 46.0%"

Muaj ntau txoj hauv kev uas koj tuaj yeem siv qhov outpu no, piv txwv li siv qhov kev xeem php file no, test_dht11.php file

Ua ntej tshaj, Kuv tau hloov tsab ntawv AdafruitDHT.py rau/var/www/.

Txhawm rau sim thiab khiav cov ntawv php, hloov mus rau /var /www ces sudo php test_dht11.php

Cov zis tso tawm ob tus lej sawv cev rau qhov kub thiab txias. Cov lej no tuaj yeem sau rau hauv lub database, lossis piv rau cov lus ceeb toom txwv thiab xa kev ceeb toom thiab lwm yam

// <? php // tsis pom zoo cov kab saum toj no - cov lus qhia tsis nyiam php pib hais kom ua //test_dht11.php

// ua tiav cov ntaub ntawv nab hab sej los nyeem DHT11 ntsuas kub

// thiab rho tawm qhov kub thiab txias qhov tseem ceeb $ kub = 0; $ vaum = 0; $ my_pos = 0; $ exec_msg = "sudo /var/www/AdafruitDHT.py 11 22 2> & 1"; $ sim = shell_exec ($ exec_msg); // rho tawm kub $ my_pos = strpos ($ test, "Temp =", 0); $ kub = substr ($ sim, $ my_pos+5, 4); ncha "\ n". $ kub; // rho tawm cov av noo $ my_pos = strpos ($ test, "Humidity =", $ my_pos); $ av noo = substr ($ sim, $ my_pos+9, 4); ncha "\ n". $ av noo; ?>

Pom zoo: