Cov txheej txheem:
- Kauj ruam 1:
- Kauj ruam 2:
- Kauj ruam 3:
- Kauj ruam 4:
- Kauj Ruam 5: Nkag Mus Rau Koj Arduino Hauv Is Taws Nem
- Kauj Ruam 6:
- Kauj ruam 7:
- Kauj Ruam 8: Qhia Cov Ntaub Ntawv Sensor ntawm Lub Vev Xaib
Video: Pib Nrog Arduino thiab Ethernet: 8 Kauj Ruam
2024 Tus sau: John Day | [email protected]. Kawg hloov kho: 2024-01-30 09:26
Koj Arduino tuaj yeem sib txuas lus tau yooj yim nrog lub ntiaj teb sab nraud ntawm kev siv Ethernet txuas. Txawm li cas los ua ntej peb pib, nws yuav xav tias koj muaj kev nkag siab yooj yim ntawm kev sib tham hauv computer, xws li kev paub yuav ua li cas txuas cov khoos phis tawj mus rau lub hub/router nrog RJ45 cables, IP thiab MAC chaw nyob yog dab tsi, thiab ntxiv rau. Ib qho ntxiv, ntawm no yog qhov nrawm nrawm txog Ethernet.
Koj yuav xav tau Arduino Uno lossis lub rooj sib tham sib txuas nrog Ethernet daim thaiv uas siv W5100 Ethernet maub los IC (zoo nkauj npaum li lawv txhua tus) raws li daim duab.
Tsis tas li ntawd koj yuav xav tau lub hwj chim ntawm lub rooj tsavxwm dhau ntawm DC lub qhov (socket) sab nraud - W5100 IC siv tam sim no ntau dua li lub zog USB tuaj yeem muab tau. Lub 9V 1.5A ntsaws pob/kab mob hauv phab ntsa yuav txaus.
Kauj ruam 1:
Thaum kawg - cov ntaub thaiv npog tau kub - yog li ceev faj tsis txhob kov W5100 tom qab siv txuas ntxiv. Yog tias koj tsis paub meej - qhov no yog W5100 IC.
Kauj ruam 2:
Thaum koj muaj koj Ethernet-enabled Arduino, thiab muaj lub zog sab nraud txuas nrog-nws yog lub tswv yim zoo los tshuaj xyuas txhua yam haujlwm. Qhib Arduino IDE thiab xaiv Cov Ntaub Ntawv> Piv Txwv> Ethernet> Webserver. Qhov no thauj cov duab kos yooj yim uas yuav tso saib cov ntaub ntawv sib sau los ntawm cov kev nkag mus sib piv ntawm lub vev xaib. Txawm li cas los xij tsis upload nws tseem, nws xav tau kev hloov kho me ntsis.
Koj yuav tsum tau hais qhia tus IP chaw nyob ntawm Ethernet daim ntaub thaiv - uas tau ua tiav hauv daim duab. Qhov no yog qhov yooj yim, mus rau kab:
Tus IP chaw nyob IP (10, 1, 1, 77);
Thiab hloov nws kom phim koj tus kheej teeb. Piv txwv li, hauv peb lub tsev tus router tus IP chaw nyob yog 10.1.1.1, lub tshuab luam ntawv yog 10.1.1.50 thiab txhua lub PC yog hauv qab no… 50. Yog li kuv yuav teeb kuv daim thaiv IP rau 10.1.1.77 los ntawm kev hloov kab rau:
byte mac = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
Txawm li cas los xij yog tias koj tsuas muaj ib daim thaiv xwb cia li tso tseg. Tej zaum yuav muaj qhov xwm txheej tsawg kawg ntawm kev muaj MAC chaw nyob zoo ib yam li koj cov khoom siv uas twb muaj lawm, yog li yuav yog lwm lub sijhawm los hloov nws.
Kauj ruam 3:
Txawm li cas los xij yog tias koj tsuas muaj ib daim thaiv xwb cia li tso tseg. Tej zaum yuav muaj qhov xwm txheej tsawg kawg ntawm kev muaj MAC chaw nyob zoo ib yam li koj cov khoom siv uas twb muaj lawm, yog li yuav yog lwm lub sijhawm los hloov nws.
Thaum koj tau ua koj qhov kev hloov pauv, txuag thiab xa cov duab kos. Tam sim no qhib lub vev xaib thiab mus rau tus IP chaw nyob uas koj nkag rau hauv daim duab, thiab koj yuav tsum tau nthuav tawm nrog qee yam zoo ib yam li cov duab.
Dab tsi tshwm sim?
Arduino tau ua haujlwm los muab cov vev xaib yooj yim nrog cov txiaj ntsig ntsuas los ntawm cov tswv yim sib piv. Koj tuaj yeem hloov kho qhov browser kom tau txais qhov txiaj ntsig hloov tshiab. Ua qhov no - thov nco ntsoov tias Ethernet cov ntaub thaiv npog siv cov koob digital 10 ~ 13, yog li koj tsis tuaj yeem siv cov ntawd rau lwm yam. Qee qhov Arduino Ethernet cov ntaub thaiv npog kuj tseem yuav muaj lub microSD daim npav qhov, uas tseem siv lwm tus lej digital - yog li tshawb xyuas nrog cov ntaub ntawv txhawm rau nrhiav seb leej twg.
Kauj ruam 4:
Txawm li cas los xij, tam sim no peb tuaj yeem pom daim thaiv npog Ethernet ua haujlwm peb tuaj yeem txav mus rau qee yam muaj txiaj ntsig dua. Cia peb cais qhov piv txwv yav dhau los hauv txoj hauv kev yooj yim, thiab saib yuav ua li cas peb thiaj tuaj yeem faib tawm thiab nthuav tawm cov ntaub ntawv nthuav tawm ntau dua hauv lub network. Txog kev siv, txhua yam ntawm Ethernet cuam tshuam nrog kev ua haujlwm yog ua los ntawm Ethernet Arduino lub tsev qiv ntawv. Yog tias koj tshuaj xyuas cov duab kos yav dhau los peb nyuam qhuav siv, ntu uas yuav txaus siab yog:
rau (int analogChannel = 0; analogChannel <6; analogChannel ++) {int sensorReading = analogRead (analogChannel); client.print ("analog nkag"); client.print (analogChannel); client.print ("yog"); client.print (sensorReading); client.println (""); } client.println ("");
Cia siab tias ntu no ntawm daim duab yuav tsum paub - nco qab tias peb tau siv cov ntawv cim npe li cas (); yav dhau los thaum xa cov ntaub ntawv mus rau lub thawv saib xyuas? Zoo tam sim no peb tuaj yeem ua qhov qub, tab sis xa cov ntaub ntawv los ntawm peb Ethernet daim ntaub thaiv rov qab mus rau lub vev xaib - ntawm lwm lo lus, hom yooj yim heev ntawm nplooj ntawv web. Yog li cas muaj qee yam koj yuav lossis tsis xav kawm txhawm rau ua hom ntawv cov zis hauv hom ntawv nyeem tau - HTML code. Kuv tsis yog tus tsim lub vev xaib (!) Yog li yuav tsis nkag mus rau HTML ntau dhau.
Txawm li cas los xij yog tias koj xav tau los ua haujlwm tau zoo ua cov nplooj ntawv web nrog koj Arduino thiab ntxiv rau, ntawm no yuav yog qhov pib zoo. Hauv kev txaus siab ntawm kev yooj yim, ob txoj haujlwm hauv qab no yuav muaj txiaj ntsig tshaj plaws:
client.print ("yog");
Client.print (); tso cai rau peb xa cov ntawv lossis cov ntaub ntawv rov qab mus rau nplooj ntawv web. Nws ua haujlwm zoo ib yam li serial.print (), yog li tsis muaj dab tsi tshiab nyob ntawd. Koj kuj tseem tuaj yeem hais qhia hom ntaub ntawv tib yam nkaus li nrog cov ntawv luam tawm (). Lawm, koj tuaj yeem siv nws xa cov ntaub ntawv rov qab ib yam. Lwm txoj kab muaj txiaj ntsig yog:
client.println ("");
uas xa tus lej HTML rov qab mus rau lub vev xaib qhia nws kom pib kab tshiab. Ib feem uas ua rau lub tsheb rov qab los/kab tshiab yog
uas yog tus lej HTML (lossis "tag") rau kab tshiab.
Yog li yog tias koj tab tom tsim ntau yam piav qhia nplooj ntawv web page, koj tuaj yeem tsuas yog ntxig lwm cov cim HTML hauv tus neeg siv khoom.print (); nqe lus Yog tias koj xav kawm paub ntau ntxiv txog HTML cov lus txib, ntawm no yog lub xaib qhia zoo.
Thaum kawg - nco ntsoov tias daim duab tsuas yog xa cov ntaub ntawv thaum nws tau thov, uas yog thaum nws tau txais kev thov los ntawm lub vev xaib.
Kauj Ruam 5: Nkag Mus Rau Koj Arduino Hauv Is Taws Nem
Txog tam sim no - zoo heev. Tab sis dab tsi yog tias koj xav nkag mus rau koj Arduino los ntawm sab nraum lub network hauv zos?
Koj yuav xav tau tus IP zoo li qub - uas yog IP chaw nyob uas koj tus muab kev pabcuam hauv internet muab rau koj qhov kev sib txuas xav tau nyob twj ywm. Yog tias koj tsis muaj IP zoo li qub, tsuav koj tso koj lub modem/router hloov pauv mus tas li ntawm koj tus IP yuav tsum tsis txhob hloov pauv. Txawm li cas los xij uas tsis yog kev daws teeb meem zoo.
Yog tias koj tus ISP tsis tuaj yeem muab tus IP zoo li qub rau koj, koj tseem tuaj yeem txav mus tom ntej nrog txoj haujlwm los ntawm kev siv lub koom haum uas muaj Dynamic DNS. Cov koom haum no muab koj tus kheej IP tus tswv lub npe zoo li (piv txwv li mojo.monkeynuts.com) hloov tus lej, taug qab koj qhov hloov pauv IP chaw nyob thiab txuas nws mus rau lub npe tswv tshiab. Los ntawm qhov kuv tuaj yeem sau tau, koj lub modem xav tau kev txhawb nqa (muaj cov neeg tsim khoom tsim rau …) cov kev pabcuam DDNS no.
Ua piv txwv, ob lub tuam txhab yog No-IP thiabDynDNS.com. Thov nco ntsoov tias kuv tsis tau siv ob qho no, lawv tsuas yog muab ua piv txwv. Tam sim no, txhawm rau nrhiav koj tus IP chaw nyob … feem ntau qhov no tuaj yeem pom los ntawm kev nkag mus rau hauv koj lub router tus thawj tswj hwm nplooj - nws feem ntau yog 192.168.0.1 tab sis tuaj yeem sib txawv. Txheeb nrog koj tus neeg muab khoom lossis ISP yog tias lawv muab khoom kho vajtse. Rau qhov ua piv txwv no, yog tias kuv nkag mus rau 10.1.1.1 hauv lub vev xaib, thiab tom qab nkag mus rau kuv tus lej tswj hwm tus lej nkag, cov vijtsam hauv qab no tau nthuav tawm raws li daim duab.
Kauj Ruam 6:
Yam koj tab tom nrhiav yog koj li WAN IP chaw nyob, zoo li koj tuaj yeem pom hauv daim duab saum toj no. Txhawm rau kom pranksters nyob deb, Kuv tau blacked tawm qee qhov ntawm kuv qhov chaw nyob.
Qhov tom ntej uas yuav tsum tau ua yog tig rau chaw nres nkoj-xa mus. Qhov no qhia tus router qhov twg txhawm rau xa cov lus thov tuaj ntawm lub ntiaj teb sab nraud. Thaum tus qauv tau txais qhov kev thov ntawd, peb xav xa qhov kev thov ntawd mus rau tus lej chaw nres nkoj ntawm peb daim thaiv thaiv Ethernet. Kev siv:
EthernetServer server (125);
ua haujlwm hauv peb cov duab kos tau teeb tsa tus naj npawb chaw nres nkoj rau 125. Txhua lub modem teeb tsa lub vijtsam yuav zoo sib xws, tab sis raws li piv txwv ntawm no yog ib qho hauv daim duab.
Kauj ruam 7:
Yog li koj tuaj yeem pom los ntawm kab naj npawb ib hauv daim duab saum toj no, tus lej chaw nres nkoj inbound tau teeb tsa rau 125, thiab IP chaw nyob ntawm Ethernet daim ntaub thaiv tau teeb tsa rau 10.1.1.77 - zoo ib yam li hauv daim duab.
Tom qab txuag cov chaw, peb txhua tus tau teeb tsa. Qhov chaw nyob sab nraud ntawm kuv daim thaiv thaiv Ethernet yuav yog WAN: 125, yog li txhawm rau nkag mus rau Arduino Kuv yuav ntaus kuv li chaw nyob WAN nrog: 125 thaum kawg mus rau qhov browser ntawm lub vev xaib nyob deb, uas yuav tiv toj Ethernet khoos phis tawj rov qab los tsev.
Ib qho ntxiv, koj yuav xav tau hloov kho koj lub modem teeb tsa firewall, txhawm rau tso chaw nres nkoj 125 kom "qhib" rau kev thov nkag. Thov txheeb xyuas koj cov ntaub ntawv modem kom paub ntau ntxiv txog yuav ua li cas. Tam sim no los ntawm ib qho twg hauv Is Taws Nem txuas nrog lub cuab yeej hauv ntiaj teb pub dawb, Kuv tuaj yeem nkag mus rau kuv tus WAN thiab tus lej chaw nres nkoj rau hauv qhov URL thiab tau txais cov txiaj ntsig. Piv txwv li, los ntawm lub xov tooj thaum nws txuas nrog Is Taws Nem ntawm LTE cov ntaub ntawv xov tooj.
Yog li ntawm theem no koj tuaj yeem tam sim no tso saib cov ntaub ntawv ntawm nplooj ntawv web yooj yim tsim los ntawm koj Arduino thiab nkag mus los ntawm txhua qhov chaw uas tsis muaj kev txwv Internet. Nrog koj cov kev paub dhau los Arduino tam sim no koj tuaj yeem siv cov ntaub ntawv los ntawm cov ntsuas lossis lwm qhov ntawm cov duab kos thiab tso tawm kom pom rov qab.
Kauj Ruam 8: Qhia Cov Ntaub Ntawv Sensor ntawm Lub Vev Xaib
Raws li piv txwv ntawm kev nthuav tawm cov ntaub ntawv ntsuas ntawm lub vev xaib, cia siv tus nqi pheej yig thiab nrov tshaj qhov ntsuas kub thiab av noo - DHT22. Koj yuav tsum teeb tsa DHT22 Arduino lub tsev qiv ntawv uas tuaj yeem pom ntawm nplooj ntawv no. Yog tias qhov no yog koj thawj zaug nrog DHT22, sim ua piv txwv piv txwv uas suav nrog lub tsev qiv ntawv yog li koj nkag siab tias nws ua haujlwm li cas.
Txuas DHT22 nrog cov ntaub ntawv tus pin rau Arduino D2, Vin rau 5V tus pin thiab GND rau… GND. Tam sim no rau peb cov duab kos - los tso saib qhov kub thiab txias ntawm lub vev xaib. Yog tias koj tsis nyob ntawm HTML koj tuaj yeem siv cov kev pabcuam online xws li qhov no los tsim cov cai, uas koj tuaj yeem hloov kho los siv hauv daim duab. Hauv qhov piv txwv hauv qab no, cov ntaub ntawv ntsuas kub thiab av noo los ntawm DHT22 tau muab rau hauv nplooj ntawv yooj yim:
#suav nrog "SPI.h"#suav nrog "Ethernet.h"
// rau DHT22 sensor
#suav nrog "DHT.h" #define DHTPIN 2 #define DHTTYPE DHT22
// Nkag mus rau MAC chaw nyob thiab IP chaw nyob rau koj tus tswj hwm hauv qab no.
// Tus IP chaw nyob yuav nyob ntawm koj lub network hauv zos: byte mac = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; Tus IP chaw nyob IP (10, 1, 1, 77);
// Pib ua Ethernet server lub tsev qiv ntawv
// nrog IP chaw nyob thiab chaw nres nkoj koj xav siv // (chaw nres nkoj 80 yog lub hauv paus rau HTTP): EthernetServer server (125); DHT dht (DHTPIN, DHTTYPE);
void teeb tsa ()
{dht.begin (); // Qhib kev sib txuas lus txuas thiab tos rau qhov chaw nres nkoj qhib: Serial.begin (9600); thaum (! Serial) {; // tos rau qhov chaw nres nkoj txuas mus txuas. Xav tau rau Leonardo nkaus xwb} // pib Ethernet txuas thiab server: Ethernet.begin (mac, ip); server.begin (); Serial.print ("server nyob ntawm"); Serial.println (Ethernet.localIP ()); }
void lub voj ()
{// mloog rau cov neeg siv khoom tuaj EthernetClient tus neeg siv = server.available (); yog (tus neeg siv khoom) {Serial.println ("tus neeg siv khoom tshiab"); // qhov http thov xaus nrog kab dawb paug boolean currentLineIsBlank = muaj tseeb; thaum (client.connected ()) {yog (client.available ()) {char c = client.read (); Serial.write (c); // yog tias koj tau mus txog qhov kawg ntawm kab (tau txais kab ntawv tshiab // cim) thiab kab tsis muaj dab tsi, qhov kev thov http tau xaus, // yog li koj tuaj yeem xa lus teb yog (c == 'n' && currentLineIsBlank) {// xa tus qauv http teb lub taub hau client.println ("HTTP/1.1 200 OK"); client.println ("Cov ntsiab lus-Hom: ntawv/html"); client.println ("Kev sib txuas: kaw"); // qhov kev sib txuas yuav raug kaw tom qab ua tiav cov lus teb client.println ("Refresh: 30"); // rov ua nplooj ntawv tshiab txhua 30 vib nas this client.println (); client.println ("");
client.println ("");
// tau txais cov ntaub ntawv los ntawm DHT22 sensor
ntab h = dht.readHumidity (); ntab t = dht.readTemperature (); Serial.println (t); Serial.println (h);
// los ntawm no peb tuaj yeem nkag mus rau peb tus kheej tus lej HTML los tsim lub vev xaib
client.print ( Chaw Ua Haujlwm Huab Cua
Chaw ua haujlwm kub - );
client.print (t);
client.print ( degrees Celsius
);
client.print ( cov
Vaum - );
client.print (h);
client.print ( feem pua
);
client.print ( cov
Nplooj ntawv rov ua dua tshiab txhua 30 vib nas this <
. );
tawg;
} yog (c == 'n') {// koj tab tom pib kab tshiab currentLineIsBlank = muaj tseeb; } lwm tus yog (c! = 'r') {// koj tau txais tus yam ntxwv ntawm kab tam sim noLineIsBlank = cuav; }}} // muab sijhawm rau lub vev xaib browser kom tau txais cov ntaub ntawv ncua (1); // kaw qhov txuas: client.stop (); Serial.println ("tus neeg siv txuas nrog"); }}
Nws yog kev hloov kho ntawm IDE lub vev xaib piv txwv piv txwv uas peb tau siv yav dhau los - nrog qee qhov kev hloov kho. Ua ntej, lub vev xaib yuav rov ua dua tshiab txhua 30 feeb - qhov ntsuas no tau teeb tsa hauv kab:
client.println ("Hloov tshiab: 30"); // rov ua nplooj ntawv tshiab txhua 30 vib nas this
… Thiab kev cai HTML rau peb nplooj ntawv web pib hauv qab kab:
// los ntawm no peb tuaj yeem nkag mus rau peb tus kheej tus lej HTML los tsim lub vev xaib
Tom qab ntawd koj tuaj yeem yooj yim ntxig qhov xav tau HTML hauv tus neeg siv khoom.print () ua haujlwm los tsim cov txheej txheem uas koj xav tau.
Yog li ntawd koj muaj nws, lwm txoj hauv kev muaj txiaj ntsig kom muaj koj Arduino cuam tshuam nrog lub ntiaj teb sab nraud. Qhov tshaj tawm no tau coj tuaj rau koj los ntawm pmdway.com - txhua yam rau cov neeg tsim khoom thiab cov neeg nyiam siv hluav taws xob, nrog kev xa khoom dawb thoob ntiaj teb.
Pom zoo:
Nws Pib Cua Txias Siv Servo thiab DHT11 Kub thiab Vaum Sensor Nrog Arduino: 8 Kauj Ruam
Auto Cooling Fan Siv Servo thiab DHT11 Kub thiab Vaum Sensor Nrog Arduino: Hauv qhov kev qhia no peb yuav kawm paub pib li cas & tig kiv cua thaum qhov kub nce siab tshaj ib qib
DC Lub Cev Pib Pib, Ceev thiab Kev Taw Qhia Siv Tus Kheej Potentiometer, OLED Zaub & Khawm: 6 Cov Kauj Ruam
DC Motor Smooth Start, Speed and Direction Siv Tus Kheej Potentiometer, OLED Display & Buttons: Hauv qhov kev qhia no peb yuav kawm paub siv L298N DC MOTOR CONTROL tus tsav tsheb thiab lub hwj chim kom tswj tau DC lub zog pib zoo, nrawm thiab qhia nrog ob lub khawm thiab tso saib tus nqi potentiometer ntawm OLED Zaub. Saib cov yeeb yaj kiab
Nab hab sej rau Tsis Yog-Pib Pib Pib: 7 Kauj Ruam
Nab hab sej rau Tsis -Yog li Pib Pib: Nyob zoo, zaum kawg, yog tias koj tau mob siab rau, peb tau kov ntawm qhov pib ntawm nab nab - luam tawm, thaum thiab rau loops, nkag & tso tawm, yog, thiab pib ntawm easygui. kuj yog kev faib dawb pub dawb ntawm easygui thiab pycal-kuv tus kheej module.this nyeem yuav suav nrog: ntau dua
Phau Ntawv Qhia Pib Pib rau Arduino IDE Nrog NodeMCU ESP8266: 6 Cov Kauj Ruam
Phau Ntawv Qhia Pib Pib rau Arduino IDE Nrog NodeMCU ESP8266: Arduino IDE Kev teeb tsa rau NodeMCU ESP8266
ESP32 Nrog Kev Sib Koom OLED (WEMOS/Lolin) - Pib Pib Arduino Style: 4 Kauj Ruam
ESP32 Nrog Kev Sib Koom OLED (WEMOS/Lolin) - Pib Pib Arduino Style: Yog tias koj zoo li kuv, koj dhia ntawm lub sijhawm kom tau txais koj txhais tes ntawm ESP8266 tshiab tshaj plaws/zoo tshaj plaws … thiab muab nws hla nws qhov chaw. ESP32 tsis txawv tab sis kuv tau pom tias tsis muaj ntau heev nyob rau ntawd tseem tsis tau hais txog cov ntaub ntawv. Qhov