Cov txheej txheem:

IoT Ua Yooj Yim: Txheeb Xyuas Cov Ntaub Ntawv Huab Cua Tej Zaum: UV thiab Huab Cua Kub & Vaum: 7 Kauj Ruam
IoT Ua Yooj Yim: Txheeb Xyuas Cov Ntaub Ntawv Huab Cua Tej Zaum: UV thiab Huab Cua Kub & Vaum: 7 Kauj Ruam

Video: IoT Ua Yooj Yim: Txheeb Xyuas Cov Ntaub Ntawv Huab Cua Tej Zaum: UV thiab Huab Cua Kub & Vaum: 7 Kauj Ruam

Video: IoT Ua Yooj Yim: Txheeb Xyuas Cov Ntaub Ntawv Huab Cua Tej Zaum: UV thiab Huab Cua Kub & Vaum: 7 Kauj Ruam
Video: Sib Hawm Dhau (Time Passed) Music Video by: Deeda/Dib Xwb 2024, Hlis ntuj nqeg
Anonim
IoT Ua Yooj Yim: Txheeb Xyuas Cov Ntaub Ntawv Huab Cua Tej Zaum: UV thiab Huab Cua Kub & Vaum
IoT Ua Yooj Yim: Txheeb Xyuas Cov Ntaub Ntawv Huab Cua Tej Zaum: UV thiab Huab Cua Kub & Vaum

Ntawm qhov kev qhia no, peb yuav ntes cov ntaub ntawv nyob deb li UV (Ultra-Violet radiation), huab cua kub thiab av noo. Cov ntaub ntawv no yuav yog qhov tseem ceeb heev thiab yuav siv rau yav tom ntej Chaw Ua Haujlwm Huab Cua.

Daim duab thaiv kab ntawv qhia dab tsi peb yuav tau txais thaum kawg.

Duab
Duab

Kauj Ruam 1: BoM - Cov Nqi Khoom

NodeMCU (ESP8266-12E) - USD 9.00

Vaum thiab Kub Sensor (DHT22) - USD10.00

UV Sensor - USD 4.00

OLED USD 12.00 Nws

Nqaij npuas kib - USD1.00

Kauj Ruam 2: Qhov Analog UV Sensor

Analog UV Sensor
Analog UV Sensor
Analog UV Sensor
Analog UV Sensor
Analog UV Sensor
Analog UV Sensor

Qhov ntsuas hluav taws xob UV no tsim cov khoom sib piv sib piv rau Ultra-Violet hluav taws xob pom ntawm lub teeb pom kev zoo. Nws siv UV photodiode (raws Gallium Nitride), uas tuaj yeem kuaj pom 240-370nm ntau ntawm lub teeb (uas npog UVB thiab feem ntau ntawm UVA spectrum). Lub teeb liab theem los ntawm photodiode me me heev, nyob rau theem nano-ampere, yog li tus qauv tau teeb tsa lub tshuab ua haujlwm ua haujlwm kom nthuav dav lub teeb liab mus rau qib nyeem tau ntau dua (0 txog 1V).

Lub sensor thiab op-amp tuaj yeem siv tau, los ntawm kev txuas VCC mus rau 3.3VDC (lossis 5VDC) thiab GND rau lub zog hauv av. Lub teeb liab analog tuaj yeem tau txais los ntawm tus lej OUT.

Nws cov zis yuav nyob hauv millivolts thiab yuav raug nyeem los ntawm Analog Input ntawm peb NodeMCU. Ib zaug nyeem, peb yuav tsum "hloov" (lossis "daim ntawv qhia chaw") nws rau qhov muaj txiaj ntsig kom ua tau zoo dua los ntawm txoj cai. Peb tuaj yeem ua nws nrog txoj haujlwm readSensorUV ():

/ * Nyeem UV Sensor hauv mV thiab hu rau UV ntsuas qhov ntsuas */

void readSensorUV () {byte numOfReadings = 5; dataSensorUV = 0; rau (int i = 0; i <numOfReadings; i ++) {dataSensorUV+= analogRead (sensorUVPin); ncua (200); } dataSensorUV /= numOfReadings; dataSensorUV = (dataSensorUV * (3.3 / 1023.0)) * 1000; Serial.println (dataSensorUV); indexCalculate (); cov }

Thaum peb muaj cov ntaub ntawv UV peb tuaj yeem suav tau yooj yim UV ntsuas raws li tau hais tseg hauv cov lus saum toj no. Kev ua haujlwm indexCalculate () yuav ua rau peb:

/ * UV Index xam */

void indexCalculate () {if (dataSensorUV <227) indexUV = 0; lwm yog (227 <= dataSensorUV && dataSensorUV <318) indexUV = 1; lwm yog (318 <= dataSensorUV && dataSensorUV <408) indexUV = 2; lwm yog (408 <= dataSensorUV && dataSensorUV <503) index UV = 3; lwm yog (503 <= dataSensorUV && dataSensorUV <606) index UV = 4; lwm yog (606 <= dataSensorUV && dataSensorUV <696) index UV = 5; lwm yog (696 <= dataSensorUV && dataSensorUV <795) index UV = 6; lwm yog (795 <= dataSensorUV && dataSensorUV <881) indexUV = 7; lwm yog (881 <= dataSensorUV && dataSensorUV <976) indexUV = 8; lwm yog (976 <= dataSensorUV && dataSensorUV <1079) index UV = 9; lwm yog (1079 <= dataSensorUV && dataSensorUV <1170) index UV = 10; lwm index UUV = 11; }

Kauj Ruam 3: Txhim Kho Cov Zaub: OLED

Txhim Kho Cov Zaub: OLED
Txhim Kho Cov Zaub: OLED
Txhim Kho Cov Zaub: OLED
Txhim Kho Cov Zaub: OLED

Rau kev ntsuas lub hom phiaj, peb yuav suav nrog OLED ntawm peb lub ntsuas UV (Cov kauj ruam no yog xaiv tau kiag li).

Nws tsis ua li cas thaum ntsuas, siv Serial Monitor, tab sis dab tsi tshwm sim thaum koj tab tom siv koj cov ntawv pov thawj nyob deb ntawm koj lub PC hauv hom ib leeg? Txog qhov ntawd, cia nruab ib qho OLED zaub, SSD1306, uas yog cov yam ntxwv tseem ceeb yog:

  • Zaub loj: 0.96"
  • I2C IIC SPI Serial
  • 128x64 ua
  • Dawb OLED LCD LED

Ua raws daim duab hluav taws xob thiab txuas 4 tus pin ntawm peb OLED:

  • VCC mus rau 3.3V
  • GND mus rau hauv av
  • SCL mus rau NodeMCU (GPIO 2) ==> D4
  • SDA mus rau NodeMCU (GPIO 0) ==> D3

Thaum peb tau txuas nrog cov zaub, cia rub tawm thiab teeb tsa nws lub tsev qiv ntawv ntawm peb Arduino IDE: "ESP8266 OLED Driver rau SSD1306 zaub" tsim los ntawm Daniel Eichhorn (Nco ntsoov tias koj siv Version 3.0.0 lossis loj dua!).

Nruab lub tsev qiv ntawv ntawm koj Arduino IDE, uas tuaj yeem pom ntawm SSD1306Wire.h

Thaum koj rov pib dua IDE, lub tsev qiv ntawv yuav tsum tau teeb tsa.

Lub tsev qiv ntawv txhawb nqa I2C raws tu qauv txhawm rau nkag mus rau OLED zaub siv lub tsev qiv ntawv Wire.h built-in:

/ * OLED */

#include "SSD1306Wire.h" #include "Wire.h" const int I2C_DISPLAY_ADDRESS = 0x3c; const int SDA_PIN = 0; const int SCL_PIN = 2; SSD1306Wire display (I2C_DISPLAY_ADDRESS, SDA_PIN, SCL_PIN);

Cia peb sau qee qhov API tseem ceeb uas yuav siv nrog peb cov zaub OLED. Cov npe ua tiav tuaj yeem nrhiav tau ntawm GITHub muab rau saum toj no.

A. Zaub Tswj:

void init (); // Initialise cov zaub

void displayOn (tsis muaj dab tsi); // Qhib cov zaub ntawm void displayOff (tsis muaj dab tsi); // Tig cov zaub tawm tsis pom tseeb (tsis muaj dab tsi); // Tshem tawm lub zos pixel tsis muaj qhov khoob flipScreenVertically (); // Tig lub zaub upside down

B. Ntawv Ua Haujlwm:

tsis muaj dabtsis drawString (int16_t x, int16_t y, Txoj hlua ntawv); // (xpos, ypos, "Text")

tsis muaj dab tsi setFont (const char* fontData); // Teeb tus font tam sim no.

Muaj lub hauv paus fonts:

  • ArialMT_Plain_10,
  • ArialMT_Plain_16,

  • ArialMT_Plain_24

Thaum ob qho tib si OLED nws tus kheej thiab nws Lub Tsev Haujlwm tau teeb tsa, cia peb sau cov program yooj yim los sim nws. Nkag nrog cov cai hauv qab ntawm koj li IDE, qhov tshwm sim yuav tsum yog ib qho zaub raws li qhia hauv daim duab saum toj no:

* OLED */

#include "SSD1306Wire.h" #include "Wire.h" const int I2C_DISPLAY_ADDRESS = 0x3c; const int SDA_PIN = 0; const int SCL_PIN = 2; SSD1306Wire display (I2C_DISPLAY_ADDRESS, SDA_PIN, SCL_PIN); teeb tsa tsis muaj dab tsi () {Serial.begin (115200); displaySetup (); } void loop () {} / * Pib thiab teeb tsa cov ntaub ntawv ntawm OLED * / void displaySetup () {display.init (); // initialize zaub display.clear (); // Ntshiab cov zaub display.flipScreenVertically (); // Tig cov zaub upside down display.display (); // Muab cov ntaub ntawv tso rau hauv Serial.println ("Pib Pib Tshawb Xyuas"); display.setFont (ArialMT_Plain_24); display.drawString (30, 0, "OLED"); // (xpos, ypos, "Text") display.setFont (ArialMT_Plain_16); display.drawString (18, 29, "Pib qhov kev xeem"); display.setFont (ArialMT_Plain_10); display.drawString (10, 52, "Serial BaudRate:"); display.drawString (90, 52, Txoj hlua (11500)); display.display (); // Muab cov ntaub ntawv tso tawm ncua (3000); }

Txoj haujlwm saum toj no tuaj yeem rub tawm los ntawm kuv GitHub:

NodeMCU_OLED_Test

Kauj Ruam 4: Ib Lub Tshuab UV Hauv Zos

Ib Lub Zos UV Meter
Ib Lub Zos UV Meter
Ib Lub Zos UV Meter
Ib Lub Zos UV Meter

Tam sim no, nrog OLED cov duab teeb tsa, peb tuaj yeem txuas lub roj teeb thiab ua qee qhov kev ntsuas deb siv peb "UV Meter"

#define SW_VERSION "UV_Sensor_V.1"

/ * UV Sensor */ #define sensorUVPin A0 int dataSensorUV = 0; int indexUV = 0; / * OLED */ #include "SSD1306Wire.h" #include "Wire.h" const int I2C_DISPLAY_ADDRESS = 0x3c; const int SDA_PIN = 0; const int SCL_PIN = 2; SSD1306Wire display (I2C_DISPLAY_ADDRESS, SDA_PIN, SCL_PIN); teeb tsa tsis muaj dab tsi () {Serial.begin (115200); displaySetup (); } void loop () {readSensorUV (); displayUV (); ncua (1000); } / * Pib thiab tso saib cov ntaub ntawv teeb tsa ntawm OLED * / void displaySetup () {display.init (); // initialize zaub display.clear (); // Ntshiab cov zaub display.flipScreenVertically (); // Tig cov zaub upside down display.display (); // Muab cov ntaub ntawv tso rau hauv Serial.println ("Pib Pib UV Sensor Test"); display.setFont (ArialMT_Plain_24); display.drawString (10, 0, "MJRoBot"); display.setFont (ArialMT_Plain_16); display.drawString (0, 29, "UV Sensor Test"); display.setFont (ArialMT_Plain_10); display.drawString (0, 52, "SW Ver.:"); display.drawString (45, 52, SW_VERSION); display.display (); ncua (3000); } / * Nyeem UV Sensor hauv mV thiab hu rau UV ntsuas qhov ntsuas * / tsis muaj dab tsi readSensorUV () {byte numOfReadings = 5; dataSensorUV = 0; rau (int i = 0; i <numOfReadings; i ++) {dataSensorUV+= analogRead (sensorUVPin); ncua (200); } dataSensorUV /= numOfReadings; dataSensorUV = (dataSensorUV * (3.3 / 1023.0)) * 1000; Serial.println (dataSensorUV); indexCalculate (); cov } / * UV Index xam * / void indexCalculate () {if (dataSensorUV <227) index UV = 0; lwm yog (227 <= dataSensorUV && dataSensorUV <318) indexUV = 1; lwm yog (318 <= dataSensorUV && dataSensorUV <408) indexUV = 2; lwm yog (408 <= dataSensorUV && dataSensorUV <503) index UV = 3; lwm yog (503 <= dataSensorUV && dataSensorUV <606) index UV = 4; lwm yog (606 <= dataSensorUV && dataSensorUV <696) index UV = 5; lwm yog (696 <= dataSensorUV && dataSensorUV <795) index UV = 6; lwm yog (795 <= dataSensorUV && dataSensorUV <881) indexUV = 7; lwm yog (881 <= dataSensorUV && dataSensorUV <976) indexUV = 8; lwm yog (976 <= dataSensorUV && dataSensorUV <1079) index UV = 9; lwm yog (1079 <= dataSensorUV && dataSensorUV <1170) index UV = 10; lwm index UUV = 11; } /* Zaub UV Qhov Tseem Ceeb ntawm OLED hauv zos* / tsis muaj dab tsi tso tawm UV () {display.clear (); display.setFont (ArialMT_Plain_16); display.drawString (20, 0, "UV Sensor"); display.drawString (0, 23, "UV (mV):"); display.drawString (80, 23, Txoj hlua (dataSensorUV)); display.drawString (0, 48, "UV Index:"); display.setFont (ArialMT_Plain_24); display.drawString (82, 42, Txoj hlua (indexUV)); display.display (); }

Cov cai saum toj no tuaj yeem rub tawm los ntawm kuv GitHun: NodeMCU_UV_Sensor_OLED.ino

Kauj Ruam 5: Txhim Kho DHT22 rau Huab Cua Kub thiab Ntsuas Kev Ntsuas

Txhim kho DHT22 rau Huab Cua Kub thiab Ntsuas Kev Ntsuas
Txhim kho DHT22 rau Huab Cua Kub thiab Ntsuas Kev Ntsuas
Txhim kho DHT22 rau Huab Cua Kub thiab Ntsuas Kev Ntsuas
Txhim kho DHT22 rau Huab Cua Kub thiab Ntsuas Kev Ntsuas

Ib qho ntawm cov cuab yeej siv tshaj plaws rau ntes cov ntaub ntawv huab cua yog DHT22 (lossis nws yog tus kwv DHT11), cov txheeb ze cov av noo thiab ntsuas kub. Nws siv lub ntsuas hluav taws xob muaj peev xwm thiab lub ntsuas cua ntsuas lub cua ib puag ncig thiab nchuav tawm lub teeb liab digital ntawm cov ntaub ntawv tus pin (tsis xav tau cov pins analog xav tau).

Lub ntsuas yuav tsum tau siv nruab nrab ntawm 3.3V thiab 5V thiab yuav ua haujlwm los ntawm -40oC txog +80oC nrog qhov raug ntawm +/- 0.5oC rau qhov kub thiab +/- 2% rau qhov txheeb ze vaum. Nws kuj tseem ceeb uas yuav tsum nco ntsoov tias nws lub sijhawm nkag siab yog nyob rau nruab nrab 2 vib nas this (lub sijhawm tsawg kawg ntawm kev nyeem ntawv). Qhov chaw ntawm Adafruit muab ntau cov ntaub ntawv hais txog ob qho tib si, DHT22 thiab nws tus tij laug DHT11. Yog xav paub ntxiv, thov mus saib DHT22/11 nplooj ntawv qhia.

DHT22 muaj 4 tus pin (tig lub ntsej muag, tus pin 1 yog sab laug tshaj plaws):

  1. VCC (peb yuav txuas rau 3.3V los ntawm NodeMCU);
  2. Cov ntaub ntawv tawm;
  3. Tsis txuas thiab
  4. Hauv av.

Ib zaug feem ntau koj yuav siv lub ntsuas ntawm qhov nrug tsawg dua 20m, 10K tus tiv thaiv yuav tsum txuas nrog ntawm Cov Ntaub Ntawv thiab VCC tus pin. Tus pin tso tawm yuav txuas nrog NodeMCU tus pin D3 (saib daim duab saum toj no). Thaum lub ntsuas tau teeb tsa ntawm peb tus qauv, rub tawm DHT lub tsev qiv ntawv los ntawm Adafruit GitHub chaw cia khoom thiab teeb tsa nws hauv koj li Arduino's Library file. Thaum koj rov qhib koj lub Arduino IDE, "DHT lub tsev qiv ntawv sensor" yuav tsum tau teeb tsa.

Thaum pib ntawm txoj cai, peb yuav tsum suav nrog cov kab:

/* DHT22*/

#suav nrog "DHT.h" #define DHTPIN D2 #define DHTTYPE DHT22 DHT dht (DHTPIN, DHTTYPE); ntab hum = 0; ntab temp = 0;

Ib txoj haujlwm tshiab yuav raug tsim los nyeem lub sensor:

/ * Tau txais cov ntaub ntawv DHT */

tsis muaj dab tsi getDhtData (tsis muaj dab tsi) {ntab tempIni = temp; ntab humIni = hum; temp = dht.readTemperature (); hum = dht.readHumidity (); yog (isnan (hum) || isnan (temp)) // Txheeb xyuas yog tias ib qho twg nyeem tsis tau thiab tawm ntxov (sim dua). {Serial.println ("Ua tsis tau zoo nyeem los ntawm DHT sensor!"); temp = tempIni; hwm = humIni; rov qab; }}

Ua tiav cov cai suav nrog UV thiab DHT cov cim tuaj yeem rub tawm los ntawm kuv GitHub: NodeMCU_UV_DHT_Sensor_OLED

Kauj Ruam 6: Xa Cov Ntaub Ntawv mus rau ThingSpeak.com

Xa Cov Ntaub Ntawv rau ThingSpeak.com
Xa Cov Ntaub Ntawv rau ThingSpeak.com
Xa Cov Ntaub Ntawv mus rau ThingSpeak.com
Xa Cov Ntaub Ntawv mus rau ThingSpeak.com
Xa Cov Ntaub Ntawv mus rau ThingSpeak.com
Xa Cov Ntaub Ntawv mus rau ThingSpeak.com

Txog tam sim no, peb tsuas yog siv NodeMCU ESP12-E ua ntu zus thiab zoo ib yam Arduino board. Tau kawg, peb tsuas yog "khawb" qhov peev xwm tiag tiag ntawm lub ntsej muag me me zoo nkauj thiab tam sim no yog lub sijhawm coj mus rau saum ntuj! Los yog zoo dua rau cov hnub qub! Ehh … to the cloud!;-)

Cia peb pib!

  1. Ua ntej, koj yuav tsum muaj tus as khauj ntawm ThinkSpeak.com
  2. Ua raws cov lus qhia los tsim Channel thiab sau koj li Channel ID thiab Sau API Key
  3. Hloov kho tus lej hauv qab no nrog koj li WiFi network thiab Thinkspeak daim ntawv pov thawj
  4. Khiav qhov program ntawm IDE

Cia peb tawm tswv yim cov cai tseem ceeb tshaj plaws:

Ua ntej tshaj, hu rau ESP8266 lub tsev qiv ntawv, txheeb xyuas WiFi tus neeg siv thiab txheeb xyuas koj li Router hauv zos thiab Thinkspeak cov ntaub ntawv pov thawj:

/* ESP12-E & Thinkspeak*/

#suav nrog WiFiClient tus neeg siv khoom; const char* MY_SSID = "Koj li SSD ID NTAWV"; const char* MY_PWD = "Koj PASSWORD NTAWM NO"; const char* TS_SERVER = "api.thingspeak.com"; Txoj hlua TS_API_KEY = "KOJ CHANNEL WRITE API KEY";

Qhov thib ob, cia suav nrog lub tsev qiv ntawv tseem ceeb heev rau IoT cov haujlwm: SimpleTimer.h:

/ * TIMER */

#suav nrog SimpleTimer timer;

Thib peb, thaum teeb tsa (), peb yuav pib sib txuas lus txuas, hu rau lub luag haujlwm txuas txuas Wii () thiab txheeb xyuas lub sijhawm. Nco ntsoov tias kab ntawm txoj cai: timer.setInterval (60000L, xa cov ntaub ntawv); yuav hu lub luag haujlwm sendDataTS () txhua 60 vib nas this, txhawm rau rub cov ntaub ntawv rau ThinkSpeak channel.

void teeb tsa ()

{… Serial.begin (115200); ncua (10); … TxuasWifi (); timer.setInterval (60000L, xa cov ntaub ntawv); …}

Thaum kawg tab sis tsis tsawg, thaum lub voj (), tsuas yog cov lus txib xav tau yog pib lub sijhawm thiab qhov ntawd yog nws!

void lub voj ()

{… Timer.run (); // Pib SimpleTimer}

Hauv qab no, koj tuaj yeem pom ob txoj haujlwm tseem ceeb siv los tuav Thinkspeak kev sib txuas lus:

ESP12-E txuas nrog koj lub network WiFi:

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

*Txuas WiFi *********************************************** ***/ void connectWifi () {Serial.print ("Txuas rau"+*MY_SSID); WiFi.begin (MY_SSID, MY_PWD); thaum (WiFi.status ()! = WL_CONNECTED) {ncua (1000); Serial.print ("."); } Serial.println (""); Serial.println ("WiFi Txuas"); Serial.println (""); }

ESP12-E xa cov ntaub ntawv rau ThinkSpeak:

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

*Xa Cov Ntaub Ntawv rau Thinkspeak Channel ******************************************** ******/ void sendDataTS (void) {if (client.connect (TS_SERVER, 80)) {String postStr = TS_API_KEY; postStr += "& field1 ="; postStr += String (dataSensorUV); postStr += "& field2 ="; postStr += String (indexUV); postStr += "& teb 3 ="; postStr += Txoj hlua (temp); postStr += "& field4 ="; postStr += Txoj hlua (hum); postStr += "\ r / n / r / n"; client.print ("POST /hloov tshiab HTTP /1.1 / n"); client.print ("Tus tswv tsev: api.thingspeak.com / n"); client.print ("Kev sib txuas: kaw / n"); client.print ("X-THINGSPEAKAPIKEY:" + TS_API_KEY + "\ n"); client.print ("Cov ntsiab lus-Hom: thov/x-www-form-urlencoded / n"); client.print ("Cov ntsiab lus-Ntev:"); client.print (postStr.length ()); client.print ("\ n / n"); client.print (postStr); ncua (1000); } xa ++; client.stop (); cov. }

Cov lej ua tiav tuaj yeem pom ntawm kuv GitHub: NodeMCU_UV_DHT_Sensor_OLED_TS_EXT

Thaum koj muaj cov cai tso rau koj NodeMCU. Cia peb txuas lub roj teeb sab nraud thiab ntsuas qee qhov ntsuas hauv qab lub hnub. Kuv muab Chaw Taws Teeb Chaw Nyob ntawm lub ru tsev thiab pib ntes cov ntaub ntawv ntawm ThingSpeak.com raws li qhia hauv cov duab saum toj no.

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 mus rau hauv lub ntiaj teb zoo ntawm hluav taws xob!

Yog xav paub ntxiv thiab tus lej kawg, thov mus saib kuv qhov kev tso nyiaj GitHub: RPi-NodeMCU-Weather-Station

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

Nyob twj ywm! Kev qhia tom ntej peb yuav xa cov ntaub ntawv los ntawm chaw nres tsheb huab cua nyob deb mus rau hauv nruab nrab, raws li Raspberry Pi Web server:

Duab
Duab

Saludos los ntawm sab qab teb ntawm lub ntiaj teb!

Pom koj hauv kuv cov lus qhia tom ntej!

Ua tsaug, Marcelo

Pom zoo: