Cov txheej txheem:

Raspberry Pi Carbon Monoxide Sensor: 6 Kauj Ruam
Raspberry Pi Carbon Monoxide Sensor: 6 Kauj Ruam

Video: Raspberry Pi Carbon Monoxide Sensor: 6 Kauj Ruam

Video: Raspberry Pi Carbon Monoxide Sensor: 6 Kauj Ruam
Video: How To Use A Geophone With Raspberry Pi and an ADC - Seismic and Footstep Detection 2024, Hlis ntuj nqeg
Anonim
Raspberry Pi Carbon Monoxide Sensor
Raspberry Pi Carbon Monoxide Sensor

Internet ntawm Yam yog cov khoom siv uas txuas nrog internet thiab muaj cov yam ntxwv ntawm kev hloov pauv tus kheej, kev teeb tsa tus kheej, Kev sib tham hauv kev sib tham sib tham thiab muaj cov yam ntxwv tshwj xeeb ntawm lub cev thiab lub cev. Sensors yog cov cuab yeej uas ntsuas qee yam ntawm lub cev thiab ib puag ncig thiab feem ntau yog siv los sau cov ntaub ntawv hauv IoT cov cuab yeej. Rau lub hom phiaj ntawm txoj haujlwm no peb tau xaiv Carbon Monoxide sensor txhawm rau ntsuas qib Carbon Monoxide tam sim no ntawm ib puag ncig. Cov cuab yeej peb tsim tau tuaj yeem siv hauv tsheb txhawm rau txhawm rau pom muaj cov pa roj carbon monoxide sab hauv lub tsheb; qhov no tseem ceeb heev hauv lub neej tiag vim tias muaj cov pa roj carbon monoxide nyob hauv ib puag ncig kaw yog qhov txaus ntshai rau tib neeg kev noj qab haus huv.

Khoom siv

Raspberry Pi 3

MQ-7 Cov pa roj carbon Monoxide Sensor

Cov qhob cij

1K Ohm tus tiv thaiv

470 Ohm tus tiv thaiv

MCP3008 8 Channel, 10-ntsis ADC nrog SPI Interface

Khoos phis tawj

Kauj ruam 1: Teeb tsa Pi

Teeb tsa Pi
Teeb tsa Pi

Ua raws li daim duab qhia chaw teeb tsa koj lub Circuit Court. Rau kev sib tham sib version ntawm daim duab, mus ntsib circuito.io daim duab

Kauj Ruam 2: Txhim Kho Cov Pob Yuav Tsum Muaj

Txij li koj yuav tsis tau tag nrho cov pob khoom tsim nyog tau teeb tsa, peb yuav tsum teeb tsa lawv siv pip:

pip nruab lub raj mis flask_restful flask_wtf thov

Kauj ruam 3: Code

Koj tuaj yeem pom txhua qhov chaws rau txoj haujlwm no hauv peb qhov chaw cia khoom github Nco ntsoov thaum koj rub nws mus rau koj lub khoos phis tawj hauv cheeb tsam thiab khaws cov ntaub ntawv teeb tsa zoo ib yam li koj xa nws mus rau pi.

Qhib cov ntaub ntawv sensor.py thiab hloov kab ntawm cov lej uas muaj localhost los ua tus IP chaw nyob ntawm koj lub computer. Koj tuaj yeem nrhiav kev qhia paub yuav nrhiav tus IP chaw nyob ntawm koj lub khoos phis tawj ntawm no.

Peb yuav tsum txav cov ntaub ntawv sensor.py mus rau raspberry pi, yog li khiav cov lus txib no los ntawm COSensor phau ntawv teev npe

scp sensor.py pi@"sau pi ip chaw nyob ntawm no":.

Kauj ruam 4: Configuring Text Messages

Txij li peb cov phiaj xwm ceeb toom peb los ntawm kab ntawv thaum Carbon Monoxide qib siab dhau, peb yuav tsum muaj peev xwm xa xov los ntawm tus lej hauv paus. Txhawm rau ua qhov no, peb yuav siv lub platform hu ua Twilio. Ua ntej tshaj, sau npe rau tus lej sim dawb. Tom ntej no, peb yuav tsum rub ob peb pob khoom. Yog tias koj twb muaj Node.js teeb tsa nrog version v8.0.0 lossis siab dua, hla mus rau kauj ruam 2. Koj tuaj yeem tshawb xyuas koj li version nrog:

node -v

Thawj pob yog Node.js uas tuaj yeem rub tawm los ntawm lawv lub xaib ntawm no. Nco ntsoov teeb tsa rau koj qhov kev ua haujlwm raug, thiab tom qab ntawd qhib nws thiab ua raws cov lus qhia kom sai.

Tom ntej no, peb yuav tsum teeb tsa Twilio CLI. Qhov no tau teeb tsa thiab hloov kho nrog Node pob tus thawj tswj nrog cov lus txib hauv qab no:

npm nruab twilio -cli -g

npm nruab twilio -cli@latest -g

Txij ntawm no mus, peb yuav tsum txuas Twilio CLI rau peb tus as khauj. Txhawm rau ua qhov no, peb xav tau ob daim ntawv ntawm cov ntaub ntawv: peb Tus lej SID thiab Tus Thawj Coj Token los ntawm Twilio Console. Tom qab ntawd khiav twilio tus ID nkag mus thiab nkag mus rau cov ntaub ntawv xav tau.

twilio login

Yog li tam sim no peb tau txuas peb tus lej tab sis tseem xav tau tus lej xov tooj. Koj tuaj yeem yuav ib qho los ntawm Twilio nrog cov nyiaj sim uas koj tau muab. Tom qab ntaus cov lus txib hauv qab no, pawg ntawm tus lej yuav tshwm sim; xaiv ib.

twilio tus xov tooj: yuav: hauv zos --country-code Asmeskas --sms-enabled

Tam sim no, txhawm rau Twilio ua haujlwm hauv peb qhov haujlwm, peb yuav tsum teeb tsa nws cov pob khoom. Hom

pip nruab twilio

Sab hauv cov key.py cov ntaub ntawv, peb yuav tsum nkag mus rau hauv peb tus lej SID thiab Auth Token rau siv tom qab. Yuav tsum muaj qhov chaw tsis muaj dab tsi rau koj theej thiab muab cov txiaj ntsig no pov tseg.

passwords = {"twilio": {"account_sid": "paste your sid here", "auth_token": "paste your token here"}}

Nrog txhua qhov no ua tiav, tam sim no yog lub sijhawm los teeb tsa email sib xws nrog peb cov haujlwm los ntawm Gmail API.

Kauj ruam 5: Kho Gmail API

Txhawm rau teeb tsa gmail API, ua ntej tshaj plaws koj yuav tsum tau mus ntsib google dashboard. Ntawm no koj tuaj yeem tso npe rau txoj haujlwm tshiab siv qhov 'tsim qhov project' xaiv. Tom qab tsim txoj haujlwm tshiab, yuav muaj lus teb sai sai uas hais tias "Koj tsis muaj APIs muaj los siv tau. Txhawm rau pib, thov mus ntsib API Lub Tsev Qiv Ntawv ".

Tom qab ntawd tuaj xyuas ntawm no. Hauv lub npov tshawb nrhiav xaiv Gmail API. Tom qab koj nyem rau Gmail API qhov kev xaiv, yuav muaj kev xaiv los Pab kom API no. Tom qab koj qhib Gmail API, koj yuav tsum tsim cov ntaub ntawv pov thawj rau koj kom siv tau. Yog li nyem rau "Tsim Daim Ntawv Pov Thawj", qhov no yuav coj koj mus rau lub qhov rais nug koj kom xaiv API. Muaj, xaiv Gmail API, tom qab ntawd xaiv qhov kev xaiv raug qhov twg koj yuav hu rau Gmail API no los ntawm. Tom qab qhov no koj yuav tsum xaiv koj lub luag haujlwm: qee yam zoo li tus tswv khoom. Tom qab ntawd cov ntaub ntawv json yuav rub tawm rau koj lub khoos phis tawj, uas yuav yog koj li kev pabcuam nyiaj txiag, theej thiab muab cov ntawv no tso rau hauv daim nplaub tshev hauv koj phau ntawv teev npe. Hurray ces koj li API tau qhib thiab koj tus as khauj tau sau npe siv Gmail API no. Tam sim no los txog qhov lom zem, hais tias peb xav xa email siv koj tus lej sau npe nrog Gmail API. Mus ntsib lub vev xaib no txhawm rau siv txog tus lej thiab tus lej ua haujlwm li cas xa email los ntawm tus lej sau npe. Thawj qhov yuav tsum nco ntsoov yog txheeb xyuas SCOPE uas tso cai rau koj xa email. Qhov uas xa email zoo li: “https://www.googleapis.com/auth/gmail.send”. Koj tuaj yeem pom cov npe ntawm kev tso cai ntawm no

Txhua yam koj ua siv Gmail API zoo li nkag mus rau daim ntawv lo ntawm email, lossis xa email, cov tshiab pickle token tau tsim, qhov no tshwm sim thawj zaug koj siv daim ntawv thov. Txhua lub sijhawm tom qab yog tias koj ntxiv qhov tshiab qhov tshiab token pickle tau tsim, uas tso cai rau txhua txoj haujlwm koj tuaj yeem ua tiav siv gmail API. Txhua lub sijhawm koj khiav koj daim ntawv thov hloov pauv qhov tshiab pickle token tau tsim.

Kauj ruam 6: Khiav lub Sensor

Tam sim no peb tuaj yeem ua tiav peb qhov program. Qhib kev sib tham ssh rau koj tus raspberry pi thiab hauv ib qho kev khiav:

sej 3 sensor.py

Hauv koj lub computer, khiav

nab hab sej api.py

Tam sim no, peb tuaj yeem nkag mus rau cov ntaub ntawv thiab sau npe kom tau txais cov ntawv ceeb toom los ntawm lub vev xaib. Qhib lub vev xaib thiab ntaus hauv https:// localhost: 5000 kom pom CO qib tam sim no. Nkag mus rau nplooj ntawv sau npe thiab nkag rau hauv koj cov ntaub ntawv kom tau txais cov ntawv ceeb toom.

Tam sim no txhua yam tau teeb tsa, koj yuav tsum tau txais ntawv ceeb toom yog tias pom CO, uas cia siab tias yuav tsis tshwm sim.

Pom zoo: