Cov txheej txheem:

IoT Ua Yooj Yim: Saib Xyuas Ntau Yam Sensors: 7 Cov Kauj Ruam
IoT Ua Yooj Yim: Saib Xyuas Ntau Yam Sensors: 7 Cov Kauj Ruam

Video: IoT Ua Yooj Yim: Saib Xyuas Ntau Yam Sensors: 7 Cov Kauj Ruam

Video: IoT Ua Yooj Yim: Saib Xyuas Ntau Yam Sensors: 7 Cov Kauj Ruam
Video: Tshuaj theem vim li cas thiaj tau nqi ?/ Siv kho mob dab tsi?/paris polyphylla использовать для? 2024, Kaum ib hlis
Anonim
IoT Ua Yooj Yim: Saib Xyuas Ntau Yam Sensors
IoT Ua Yooj Yim: Saib Xyuas Ntau Yam Sensors
IoT Ua Yooj Yim: Saib Xyuas Ntau Yam Sensors
IoT Ua Yooj Yim: Saib Xyuas Ntau Yam Sensors

Ob peb lub lis piam dhau los, Kuv tau tshaj tawm ntawm no cov lus qhia txog kev ntsuas ntsuas kub siv DS18B20, lub ntsuas hluav taws xob uas sib txuas lus hla lub npav 1-Hlau, xa cov ntaub ntawv hla internet nrog NodeMCU thiab Blynk:

IoT Ua Yooj Yim: Saib Xyuas Qhov Kub Nyob Qhov Twg

Tab sis dab tsi peb tsis tau tshawb nrhiav, yog ib qhov zoo ntawm qhov ntsuas qhov zoo uas yog qhov muaj peev xwm khaws ntau cov ntaub ntawv, los ntawm ntau lub ntsuas hluav taws xob txuas nrog tib lub npav 1-xaim. Thiab, tam sim no nws yog lub sijhawm los tshawb nrhiav nws.

Peb yuav nthuav qhov uas tau tsim los ntawm kev qhia zaum kawg, tshuaj xyuas tam sim no ob lub DS18B20 lub ntsuas, teeb tsa ib qho hauv Celcius thiab lwm qhov hauv Fahrenheit. Cov ntaub ntawv yuav raug xa mus rau Blynk App, raws li qhia hauv kab lus saum toj no.

Kauj Ruam 1: Nqi Khoom

  • NodeMCU ESP 12-E (*)
  • 2 X DS18B20 Kub Sensor
  • Resistor 4.7K Ohms
  • BreadBoard
  • Thaiv

(*) Txhua yam khoom siv ESP tuaj yeem siv ntawm no. Feem ntau yog NodeMCU V2 lossis V3. Ob leeg yuav ua haujlwm zoo ib txwm.

Kauj Ruam 2: DS18B20 Kub Sensor

DS18B20 Kub Sensor
DS18B20 Kub Sensor

Peb yuav siv hauv qhov kev qhia no tiv thaiv dej tsis haum ntawm DS18B20 sensor. Nws yog qhov muaj txiaj ntsig zoo rau qhov kub thiab txias nyob rau thaj tsam ntub, piv txwv li ntawm cov av noo. Lub ntsuas ntsuas tau sib cais thiab tuaj yeem ntsuas ntsuas kom txog 125oC (Adafrut tsis pom zoo kom siv nws ntau dua 100oC vim nws lub tsho PVC cable).

DS18B20 yog lub ntsuas digital uas ua rau nws zoo siv txawm tias nyob deb deb! Cov 1-xaim digital ntsuas qhov ntsuas yog qhov ncaj ncees (± 0.5 ° C ntau ntawm qhov ntau) thiab tuaj yeem muab txog 12 qhov khoom ntawm qhov tseeb los ntawm onboard digital-to-analog converter. Lawv ua haujlwm zoo nrog NodeMCU siv tus lej digital nkaus xwb, thiab koj tseem tuaj yeem txuas ntau tus rau tib tus pin, txhua tus muaj qhov tshwj xeeb 64-ntsis ID hlawv hauv lub hoobkas kom sib txawv lawv.

Lub sensor ua haujlwm los ntawm 3.0 txog 5.0V, txhais tau tias nws tuaj yeem siv ncaj qha los ntawm ib qho ntawm 3.3V NodeMCU pins.

Lub sensor muaj 3 xaim:

  • Dub: GND
  • Liab: VCC
  • Daj: 1-Cov Ntaub Ntawv Hlau

Ntawm no, koj tuaj yeem pom cov ntaub ntawv tag nrho: DS18B20 Datasheet

Kauj Ruam 3: Txuas lub Sensors rau NodeMCU

Txuas cov Sensors rau NodeMCU
Txuas cov Sensors rau NodeMCU
  1. Txuas 3 lub xov hlau los ntawm txhua lub ntsuas ntawm mini Breadboard raws li qhia hauv daim duab saum toj no. Kuv siv cov khoom sib txuas tshwj xeeb txhawm rau txhim kho lub sensor lub cable zoo dua.
  2. Nco ntsoov tias ob lub ntsuas hluav taws xob nyob ua ke. Yog tias koj muaj ntau dua 2 lub cim, koj yuav tsum ua tib yam.

    • Liab ==> 3.3V
    • Dub ==> GND
    • Daj ==> D4
  3. Siv 4.7K ohms resistor ntawm VCC (3.3V) thiab Cov Ntaub Ntawv (D4)

Kauj Ruam 4: Txhim Kho Cov Tsev Qhua Zoo

Txhawm rau siv DS18B20 kom raug, ob lub tsev qiv ntawv yuav xav tau:

  1. OneWire
  2. DallasTemperature

Nruab ob lub tsev qiv ntawv hauv koj li Arduino IDE Library tso nyiaj.

Nco ntsoov tias OneWire lub tsev qiv ntawv YUAV TSUM yog qhov tshwj xeeb, hloov kho kom siv nrog ESP8266, txwv tsis pub koj yuav tau txais qhov yuam kev thaum sau ua ke. Koj yuav pom qhov kawg ntawm qhov txuas saum toj no.

Kauj Ruam 5: Kuaj Cov Sensors

Kuaj Cov Ntsuas
Kuaj Cov Ntsuas

Txhawm rau ntsuas cov ntsuas, rub tawm cov ntawv hauv qab no los ntawm kuv GitHub:

NodeMCU_DS18B20_Dual_Se nsor_test.ino

/**************************************************************

*Ntau Qhov Kev Ntsuas Kub Xa**2 x OneWire Sensor: DS18B20*Txuas nrog NodeMCU D4 (lossis Arduino Pin 2)**Tsim los ntawm Marcelo Rovai - 25 Lub Yim Hli 2017 **************** ****************************************************/ #suav nrog # suav nrog #define ONE_WIRE_BUS 2 // DS18B20 ntawm NodeMCU tus pin D4 OneWire oneWire (ONE_WIRE_BUS); DallasTemperature DS18B20 (& oneWire); teeb tsa tsis muaj dab tsi () {Serial.begin (115200); DS18B20.begin (); Serial.println ("Txheeb Xyuas Dual Sensor cov ntaub ntawv"); } void loop () {ntab temp_0; ntab temp_1; DS18B20.requestTemperatures (); temp_0 = DS18B20.getTempCByIndex (0); // Sensor 0 yuav ntes Temp hauv Celcius temp_1 = DS18B20.getTempFByIndex (1); // Sensor 0 yuav ntes Temp hauv Fahrenheit Serial.print ("Temp_0:"); Serial.print (temp_0); Serial.print ("oC. Temp_1:"); Serial.print (temp_1); Serial.println ("oF"); ncua (1000); }

Saib ntawm cov cai saum toj no, peb yuav tsum pom tias cov kab tseem ceeb tshaj plaws yog:

temp_0 = DS18B20.getTempCByIndex (0); // Sensor 0 yuav ntes Temp hauv Celcius

temp_1 = DS18B20.getTempFByIndex (1); // Sensor 0 yuav ntes Temp hauv Fahrenheit

Thawj tus yuav rov qab tus nqi los ntawm Sensor [0] (saib "ntsuas (0)") hauv Celcius (saib ib feem ntawm txoj cai: "getTempC". Kab thib ob cuam tshuam nrog Sensor [1] thiab yuav xa cov ntaub ntawv rov qab Hauv Fahrenheit. Koj tuaj yeem muaj ntawm no "n" sensors txij li koj muaj qhov sib txawv "ntsuas" rau txhua tus ntawm lawv.

Tam sim no xa cov cai hauv koj NodeMCU thiab saib xyuas qhov ntsuas kub siv Serial Monitor.

Daim duab saum toj no qhia pom qhov tshwm sim. Tuav txhua tus ntawm cov ntsuas hauv koj txhais tes, koj yuav tsum pom qhov kub nce.

Kauj Ruam 6: Siv Blynk

Siv Blynk
Siv Blynk
Siv Blynk
Siv Blynk

Thaum koj pib ntes cov ntaub ntawv ntsuas kub, nws yog lub sijhawm pom nws los ntawm txhua qhov chaw. Peb yuav ua qhov no siv Blynk. Yog li, txhua cov ntaub ntawv khaws tseg yuav raug nthuav tawm hauv lub sijhawm tiag tiag ntawm koj lub xov tooj ntawm tes thiab peb tseem yuav tsim keeb kwm khaws cia rau qhov ntawd.

Ua raws cov theem hauv qab no:

  1. Tsim Txoj Haujlwm Tshiab.
  2. Muab nws lub npe (hauv kuv kis "Dual Temperature Monitor")
  3. Xaiv Ntaus Tshiab - ESP8266 (WiFi) ua "Kuv Li"
  4. Luam theej duab AUTH TOKEN los siv hauv tus lej (koj tuaj yeem xa nws mus rau koj tus email).
  5. Xws li ob "Gauge" Widgets, txhais:

    • Tus lej pin yuav tsum tau siv nrog txhua lub sensor: V10 (Sensor [0]) thiab V11 (Sensor [1])
    • Qhov kub thiab txias: -5 txog 100 oC rau Sensor [0]
    • Qhov kub thiab txias: 25 txog 212 oC rau Sensor [1]
    • Zaus los nyeem cov ntaub ntawv: 1 thib ob
  6. Suav nrog "Keeb Kwm Keeb Kwm" Widget, txhais V10 thiab V11 ua tus pin virtual
  7. Nias "Ua Si" (Daim duab peb sab ntawm kaum sab xis)

Yog lawm, Blynk App yuav hu xov tooj rau koj tias NodeMCU tawm ntawm kab. Nws yog lub sijhawm los upload tag nrho cov cai ntawm koj Arduino IDE. Koj tuaj yeem tau txais nws ntawm no:

NodeMCU_Dual_Sensor_Blynk_Ext.ino

Hloov "cov ntaub ntawv dag" nrog koj tus kheej daim ntawv pov thawj.

/ * Daim ntawv pov thawj Blynk */

char auth = "Koj li BLYNK AUTH CODE NTAWM NO"; / * WiFi daim ntawv pov thawj */ char ssid = "Koj li SSID"; char pass = "KOJ PASSWORD";

Thiab qhov ntawd yog nws!

Nyeem tag nrho cov cai. Nws yog qhov tseem ceeb ntawm cov cai yav dhau los, qhov uas peb nkag mus nrog Blynk tsis thiab cov haujlwm tshwj xeeb. Nco tseg 2 kab kawg ntawm txoj cai. Cov ntawd yog qhov tseem ceeb tshaj plaws ntawm no. Yog tias koj muaj cov cim ntsuas ntau ntxiv khaws cov ntaub ntawv, koj yuav tsum muaj cov kab sib npaug tshiab raws li cov ntawd (nrog cov cim tshiab uas muaj feem cuam tshuam).

/**************************************************************

* IoT Ntau Qhov Kev Ntsuas Kub nrog Blynk * Blynk lub tsev qiv ntawv tau ntawv tso cai nyob hauv MIT daim ntawv tso cai * Tus lej piv txwv no yog nyob rau pej xeem. **Ntau OneWire Sensor: DS18B20*Tsim los ntawm Marcelo Rovai - 25 Lub Yim Hli 2017 ************************************** ****************************//*ESP & Blynk*/ #include #include #define BLYNK_PRINT Serial // Hais tawm qhov no rau lov tes taw luam ntawv thiab txuag chaw / * Blynk daim ntawv pov thawj * / char auth = "Koj li BLYNK AUTH CODE NTAWM NO"; / * WiFi daim ntawv pov thawj */ char ssid = "Koj li SSID"; char pass = "KOJ PASSWORD"; / * TIMER */ #suav nrog SimpleTimer timer; / * DS18B20 Kub Sensor */ #include #include #define ONE_WIRE_BUS 2 // DS18B20 ntawm arduino pin2 sib xws rau D4 ntawm lub rooj tsav xwm lub cev OneWire oneWire (ONE_WIRE_BUS); DallasTemperature DS18B20 (& oneWire); koj temp_0; koj temp_1; teeb tsa tsis muaj dab tsi () {Serial.begin (115200); Blynk.begin (auth, ssid, dhau); DS18B20.begin (); timer.setInterval (1000L, getSendData); Serial.println (""); Serial.println ("Txheeb Xyuas Dual Sensor cov ntaub ntawv"); } tsis muaj dab tsi voj () {timer.run (); // Pib Pib SimpleTimer Blynk.run (); } /******************************************************** ****Xa cov ntaub ntawv Sensor mus rau Blynk ***************************************** *********/ void getSendData () {DS18B20.requestTemperatures (); temp_0 = DS18B20.getTempCByIndex (0); // Sensor 0 yuav ntes Temp hauv Celcius temp_1 = DS18B20.getTempFByIndex (1); // Sensor 0 yuav ntes Temp hauv Fahrenheit Serial.print ("Temp_0:"); Serial.print (temp_0); Serial.print ("oC. Temp_1:"); Serial.print (temp_1); Serial.println ("oF"); Blynk.virtualWrite (10, temp_0); // tus pin virtual V10 Blynk.virtualWrite (11, temp_1); // tus pin virtual V11}

Thaum cov cai tau rub tawm thiab ua haujlwm, txheeb xyuas Blynk app. Nws yuav tsum tam sim no tseem ua haujlwm raws li tau hais los saum toj no luam tawm ntawm kuv lub iPhone.

Kauj Ruam 7: Xaus

Xaus
Xaus

Raws li ib txwm muaj, Kuv vam tias txoj haujlwm no tuaj yeem pab lwm tus pom lawv txoj hauv kev zoo siab hauv ntiaj teb cov khoom siv hluav taws xob, neeg hlau, thiab IoT!

Thov mus ntsib kuv GitHub rau cov ntaub ntawv hloov tshiab: NodeMCU Dual Temp Monitor

Yog xav paub ntau ntxiv, thov mus saib kuv qhov blog: MJRoBot.org

Saludos los ntawm sab qab teb ntawm lub ntiaj teb!

Pom koj ntawm kuv cov lus qhia tom ntej!

Ua tsaug, Marcelo

Pom zoo: