Cov txheej txheem:

TheAir - Gas Sensor Project: 10 Kauj Ruam
TheAir - Gas Sensor Project: 10 Kauj Ruam

Video: TheAir - Gas Sensor Project: 10 Kauj Ruam

Video: TheAir - Gas Sensor Project: 10 Kauj Ruam
Video: Lil Nas X, Jack Harlow - INDUSTRY BABY (Official Video) 2024, Hlis ntuj nqeg
Anonim
TheAir - Txoj Haujlwm Roj Sensor
TheAir - Txoj Haujlwm Roj Sensor

Cov pa roj carbon monoxide thiab carbon dioxide, tseem hu ua CO thiab CO2. Cov pa uas tsis muaj xim, tsis muaj ntxhiab, tsis qab thiab muaj qhov txaus ntshai thaum nyob hauv qhov ntau nyob hauv chav kaw. Yog tias koj nyob ib leeg hais piv txwv hauv chav tub ntxhais kawm ntawv uas nyob ib leeg tsis zoo, tsis muaj cua nkag tau zoo thiab rau qee qhov laj thawj, lub khob cij ua rau muaj suab nrov txawv txawv thaum ua qhob noom xim kasfes. Tom qab ntawd koj tuaj yeem ntsib nrog cov pa no thiab thaum qhov ntawd tshwm sim, cia siab tias nws tsuas yog xaus nrog mob taub hau me me, ua rau muaj kev mloog zoo nws yuav tsis muaj peev xwm lossis tseem tua koj (txawm tias tsawg heev).

Yog li kuv txiav txim siab los nrog txoj haujlwm no. Kuv lub tswv yim yog qhov yooj yim, siv cov kiv cua los ua kom muaj huab cua. Huab cua zoo thiab cua tsis zoo thiaj li hais tau. Txog kev siv hluav taws xob ntxiv, Kuv tau ntxiv qhov ntsuas kub ntxiv, khawm rau phau ntawv qhib kiv cua thiab tseem muaj lub vev xaib rau cov uas nyiam saib cov txheeb cais thiab/lossis qhib cov kiv cua los ntawm lawv lub computer.

Raws li tub ntxhais kawm, niam txiv, ib leeg lossis ib tus neeg nyob. Nov yog qee yam uas koj ib txwm nyiam kom zam thaum nyob hauv koj lub tsev yooj yim. Qhov no pab cov uas nyiam ua lawv lub neej yooj yim dua.

Khoom siv

  • Raspberry Pi 3+
  • Mini-usb them nyiaj 5V/2.5A
  • Micro-sd daim npav
  • Sensors

    • MQ-7 (CO)
    • MQ-135 (CO2)
    • DS18B20 (kub)
  • 2 x 12V DC ntxuam
  • 2 x 2n2222 transistors
  • LCD 16*2 zaub
  • Pushbutton
  • YWB 3008
  • Logi qib converter
  • Ethernet cable (teeb tsa vim li cas)

Kauj Ruam 1: Teeb Raspberry Pi

Raspberry Pi Teeb
Raspberry Pi Teeb
Raspberry Pi Teeb
Raspberry Pi Teeb

Ua ntej ua haujlwm nrog Rpi, peb yuav xav tau qee qhov software.

  • WinSCP lossis FilleZilla (yeem yog tias koj xav xa cov ntaub ntawv los ntawm koj lub computer mus rau Rpi)
  • Win32 disc lossis Etcher (uas koj xav tau ntau dua)
  • Putty lossis MobaXterm (uas koj xav tau ntau dua)
  • Raspbian duab nrog desktop

Ua ntej kuv pib kuv xav hais tias thaum ua qhov kev qhia no, thaum kuv xaiv qhov program hla lwm qhov, Tsis txhais tau tias kuv qhia nws. Piv txwv li kuv nyiam siv lwm yam vim tias muaj neeg siv zoo dua tab sis Win32 muaj qhov kev xaiv los ua thaub qab. Tam sim no uas tsis tawm ntawm kuv qhov system, cia pib.

Yog tias koj twb muaj Rpi uas txuas nrog koj lub network wifi, hla mus rau qib 3.

Ua ntej peb yuav siv Etcher los tso duab Raspbian ntawm koj daim npav SD. Tam sim no ua ntej peb rub tawm daim npav sd, peb yuav hloov qee qhov "khoom" hauv cmdline.txt cov ntaub ntawv, uas tuaj yeem pom hauv daim duab. Qhib cov ntaub ntawv.txt -> Ntxiv kab no "ip = 169.254.10.1" (tsis hais cov cim) ntawm qhov kawg ntawm kab (tag nrho ntawm 1 kab) -> Txuag cov ntaub ntawv

Qhov thib ob ua qhov npliag npliag hu ua "ssh" hauv khau raj-muab faib (tsis hais cov cim).

Tom qab ntawd koj tuaj yeem nyab xeeb tshem tawm Microsd thiab muab tso rau hauv Rpi.

Qhov laj thawj rau qhov nyuaj coded zoo li tus IP yog ua kom yooj yim dua rau kev txuas mus rau Rpi. Yog tias qee qhov laj thawj Rpi tsis muaj ip nrog DHCP ces koj yooj yim siv ip zoo li qub.

Kauj Ruam 2: Ua Kev Sib Txuas thiab Txuas Rpi Wireless rau Koj Lub Zos Network

Ua Kev Sib Txuas thiab Txuas Rpi Wireless rau Koj Lub Zos Network
Ua Kev Sib Txuas thiab Txuas Rpi Wireless rau Koj Lub Zos Network
Ua Kev Sib Txuas thiab Txuas Rpi Wireless rau Koj Lub Zos Network
Ua Kev Sib Txuas thiab Txuas Rpi Wireless rau Koj Lub Zos Network
Ua Kev Sib Txuas thiab Txuas Rpi Wireless rau Koj Lub Zos Network
Ua Kev Sib Txuas thiab Txuas Rpi Wireless rau Koj Lub Zos Network
Ua Kev Sib Txuas thiab Txuas Rpi Wireless rau Koj Lub Zos Network
Ua Kev Sib Txuas thiab Txuas Rpi Wireless rau Koj Lub Zos Network

Peb tab tom yuav khau raj Rpi -> txuas lub ethernet cable ntawm lub khoos phis tawj thiab Rpi.

  1. Pib Putty thiab sau rau hauv no:

    • Tus tswv lub npe (lossis tus IP chaw nyob): 169.254.10.1
    • Chaw nres nkoj: 22
  2. Lub davhlau ya nyob twg pops thiab koj ntaus hauv lub neej ntawd username & password:

    • Username: pib
    • Lo lus zais: raspberry

Tam sim no peb tau txuas nrog hauv zos rau rpi, peb xav kom Rpi muaj kev sib txuas rau koj li wifi.

  1. Ntxiv: ntaus hauv "sudo raspi-config"
  2. Ntawm no koj yuav tsum hloov tus password rau pi tus neeg siv (vim li cas kev nyab xeeb)
  3. Tom qab ntawd mus rau Kev Xaiv Hauv Zos -> Hloov Sijhawm (xaiv qhov raug) -> Tom qab ntawd mus rau Wifi Lub Tebchaws -> xaiv lub tebchaws.
  4. Kaw raspi-config thiab rov pib dua.
  5. Thaum nkag mus, ib ntus ua rau koj tus kheej siv hauv paus -> sudo -i
  6. Sau cov lus txib no los ntxiv koj lub network rau Rpi (cov lej hauv qab no)

    • password = "password" (nrog cov lus hais)
    • Lub npe network = "SSID"
    • Nco ntsoov siv ob zaug >>!

ncha "password" | wpa_passphrase "SSID" >> /etc/wpa_supplicant/wpa_supplicant.conf

Tam sim no rov pib dua

Thaum rov txuas dua, txheeb xyuas koj tus ip los ntawm kev ntaus ntawv:

ifconfig

thiab kos wlan0, ib sab ntawm inet.

Tam sim no peb muaj internet txuas, cia ua qhov hloov tshiab "nrawm".

sudo apt hloov tshiab

sudo apt dist -upgrade -y

Qhov no yuav siv sijhawm me ntsis.

Kauj Ruam 3: Sensor DS18B20 (ntsuas kub)-1-xaim

Sensor DS18B20 (kub)-1-xaim
Sensor DS18B20 (kub)-1-xaim
Sensor DS18B20 (kub)-1-xaim
Sensor DS18B20 (kub)-1-xaim

Nrog txhua qhov haujlwm, ib txwm yuav yog qhov tshwj xeeb uas yuav tsum tau ua lossis lwm qhov nws yuav tsis ua haujlwm tam sim.

Lub sijhawm no peb muaj nws nrog DS18B20 qhov ntsuas kub uas xav tau 1-xaim uas kuv yuav tsis piav qhia vim li cas tab sis kuv yuav piav qhia yuav ua li cas thiaj ua haujlwm tsawg kawg.

Txog qhov no peb yuav tsum rov qab mus rau raspi-teeb tsa ntawm Rpi, lub vijtsam xiav zoo.

  1. Mus rau Interfacing options
  2. Xaiv 1-Hlau thiab xaiv pab kom.

Ua tiav …

Tso dag xwb.

Tam sim no peb yuav xav tau kho /boot/config.txt

sudo nano /boot /config.txt

Ntxiv kab no hauv qab.

# Qhib ib txoj kab

dtoverlay = w1-gpio

Tam sim no sudo rov pib dua qhov khoom thiab tam sim no peb tau ua tiav.

Txhawm rau txheeb xyuas seb nws puas ua haujlwm, txuas lub sensor mus rau Rpi tom qab ntawd rov qab mus rau lub davhlau ya nyob twg thiab ntaus tus lej no (Saib cov kauj ruam tom ntej Kho vajtse yuav ua li cas txuas lub ntsuas kub).

cd/sys/bus/w1/devices/w1_bus_master1

ls ua

Koj yuav tsum pom qee yam nrog tus lej thiab ntawv hauv xiav tsaus nyob rau sab laug, nco ntsoov sau cov ntaub ntawv no rau tom qab thaum peb yuav ua haujlwm nrog cov cai los ntawm github.

Yog tias qee qhov laj thawj nws tsis ua haujlwm, tshawb xyuas qhov txuas uas nkag mus tob rau hauv nws.

Kauj Ruam 4: MCP3008 - Analog Sensing

MCP3008 - Analog Sensing
MCP3008 - Analog Sensing
MCP3008 - Analog Sensing
MCP3008 - Analog Sensing

Raws li peb tau hloov pauv rau qhov ntsuas kub, peb kuj tseem yuav tsum tau hloov qee qhov rau lwm qhov ntsuas txij li lawv yuav tsum tau nyeem hauv cov ntaub ntawv sib piv. Nov yog qhov MCP3008 los ua ke, peb kuj yuav tsum tau hloov SPI interface.

sudo raspi-teeb tsa

Mus rau Interfacing Options -> Xaiv SPI -> pab kom.

Ces Tiav.

Kauj ruam 5: Kho vajtse

Peb tsis tau ua tiav nrog Rpi tab sis txaus kom peb tuaj yeem pib tsim thiab muab kho vajtse ua ke.

Qee cov lus qhia yog txhawm rau txheeb xyuas koj cov kev sib txuas thaum tsim kom paub tseeb tias koj tsis … tshuab Rpi.

Tsis tas li, hauv Schematic koj yuav pom qee lub Cheebtsam nyob ntawm nws ib zaug xwb txawm hais tias peb yuav ua haujlwm nrog ntau dua 1 ntawm cov khoom ib yam. Nws tsuas yog txhais tau tias koj yuav tsum rov ua cov txheej txheem tib yam ntawm kev tsim 1 yam ntawd. Muaj 1 qhov tshwj xeeb me me, mq-x sensors tsis xav tau qib hloov pauv ntxiv lossis MCP3008. Tsuas yog ntxiv cov kab ntsuab ntsuab (hauv pdf) rau qib hloov pauv thiab MCP3008.

Kev hloov kho ntxiv: Cov kiv cua yuav tsum siv lub transistor los hloov. Kuv siv 2n2222A transistor rau 1 tus kiv cua, vim tias 2 tus kiv cua yuav yog lub nra hnyav.

Yog tias koj muaj lub transistor uas tuaj yeem ua haujlwm loj dua tam sim no zoo, hla qhov kawg ntawm cov kauj ruam no.

Yog tias koj tsis muaj ib tus zoo li kuv, ces koj yuav tsum ua nws zoo li no, 1 tus kiv cua = 1 lub transistor, 2 tus kiv cua = 2 lub transistors, thiab ntxiv rau (txhua tus kiv cua nws tus kheej transistor + diode zoo li hauv pdf).

Koj kuj tseem yuav xav tau ntxiv qee qhov chaws rau app.py hauv backend_project tom qab hauv Kauj Ruam 7: Git code….

Kauj Ruam 6: Tsim Mariadb Datbase

Tsim Mariadb Datbase
Tsim Mariadb Datbase

Raws li lub npe cuam tshuam, peb yuav tsim cov ntaub ntawv khaws cia kom peb muaj qhov chaw khaws peb cov ntaub ntawv ntsuas.

Thawj yam ua ntej, rub Mariadb ntawm Rpi.

sudo apt-tau nruab mariadb-server

Tom qab kev teeb tsa, cia siv nws.

mysql -u hauv paus

Lo lus zais tsis muaj dab tsi, yog li tsis muaj dab tsi los ntaus. Nias nkag mus.

Cia tsim ib tus neeg siv tam sim no.

CREATE USER 'user'@'%' IDENTIFIED BY 'userdb';

YOOJ YIM YOOJ YIM YOOJ YIM RAU *. * TO 'user'@'%' WITH GRANT OPTION;

NTSEEG NTAWV QHOV TSEEB;

Nias Ctrl + C kom tawm thiab rov pib dua qhov kev pabcuam:

sudo kev pabcuam mysql rov pib dua

Nkag mus nrog lub npe siv: tus siv & tus password: userdb:

mysql -u neeg siv -p

Lub sijhawm los tsim cov ntaub ntawv tam sim no.

TSHUAJ DATABASE project_db DEFAULT CHARACTER SET utf8;

Siv qhov project_db

Tsim lub rooj "historiek" (txhais tau tias keeb kwm).

CREATE TABLE IF NOT EXISTS `historyiek` (` id `INT NOT NULL AUTO_INCREMENT, `sensorID` VARCHAR (5) TSIS NULL, `datum` DATETIME TSIS MUAJ NQE DEFAULT CURRENT_TIMESTAMP, `waarde` FLOAT (4) NULL DEFAULT 0, PRIMARY KEY (`id`)) ENGINE = InnoDB;

Thiab voila, lub database tau ua.

Kauj Ruam 7: Github Code thiab Xeem

Github Code thiab Xeem
Github Code thiab Xeem

Peb tab tom ze rau qhov kawg ntawm peb txoj haujlwm.

Ua ntej peb tau txais cov cai, peb yuav tsum tau import qee cov qauv rau hauv Rpi:

pip3 nruab Flask_MySQL

pip3 nruab flask-socketio

pip3 nruab -U flask -cors

pip3 nruab spidev

Tam sim no peb xav tau cov cai los ua kom nws ua haujlwm, ntaus hauv lub davhlau ya nyob twg:

git clone

Txheeb xyuas yog tias daim nplaub tshev nyob nrog:

ls ua

Tam sim no koj yuav xav tau 2 lub davhlau ya nyob twg yog li ntawd nws yog qhov yooj yim rau nyem rau ntawm lub davhlau ya nyob twg thiab nyem theej tawm ntu:

Mus rau backend_project thiab ntsuas kub siv cd hais kom ua.

Tam sim no ua ntej peb pib ua cov haujlwm rau kev ntsuas lub hom phiaj. Koj puas tseem nco Ntu 3 nrog 1-xaim sensor qhov twg koj yuav tsum sau qee tus lej? Tsis muaj kev txhawj xeeb yog tias koj muaj, tsuas yog saib nrawm ntawm qib 3 dua.

Peb tab tom yuav ntxiv cov lej no rau cov lej vim nws yuav xav paub qhov tseeb sensor thaum siv nws.

Lub davhlau ya nyob twg nrog lub ntsuas kub, koj yuav pom app.py. Peb yuav qhib nws.

sudo nano app.py

Saib rau txoj haujlwm uas hu ua "def temperatuur ():", nyob ntawd koj yuav tau hloov tus "**" nrog cov lej koj sau. Hauv kuv qhov xwm txheej kuv yuav tau txais kab kab ntawv no (txhua tus lej tshwj xeeb).

sensor_file_name = '/sys/devices/w1_bus_master1/28-0316a4be59ff/w1_slave

Sijhawm Kuaj. Ob lub davhlau ya nyob twg hauv ob qho backend_project thiab qhov ntsuas kub, hom:

sej 3 app.py

Tam sim no nco qab qib 5: kho vajtse qhov twg koj xav tau ntxiv cov cai yog tias koj siv ntau tus kiv cua thiab transistors?

Zoo, yog tias tsis rov qab mus rau kauj ruam 5.

Tam sim no peb xav tau ntxiv cov cai raws li kuv tau hais rau app.py hauv backend_project. Txhawm rau ua kom yooj yim dua, Kuv tau ua piv txwv ntawm qhov no hauv cov cai. Txhua kab ntawm kab lus hais uas muaj "fan1" hauv nws, tsis pom zoo cov kab thiab voila, tam sim no koj tuaj yeem siv 2 tus kiv cua.

Yog tias koj xav siv ntau dua tsuas yog 2 tus kiv cua, theej & paste tib cov cai hauv qab nws tab sis nrog tus lej sib txawv. Qhov tsis zoo ntawm qhov no yog kev ua haujlwm tus kheej ntau dua rau koj thiab tsawg dua gpio.pins muaj. Tsis muaj qhov zoo rau qhov no uas kuv paub txog.

Kauj ruam 8: Khiav Code ntawm Boot Up

Khiav Code ntawm Boot Up
Khiav Code ntawm Boot Up

Peb xav tau cov ntawv 2 nab nab los khiav lub sijhawm peb Rpi khau raj nce thiab thaum cov ntawv yuav tsoo, nws yuav tsum rov pib dua ntawm nws tus kheej. Txhawm rau ua qhov no peb yuav ua 2 qhov kev pabcuam.

Txhawm rau ua qhov no, ntaus:

sudo nano /etc/systemd/system/temperature.service

Luam thiab muab lo rau qhov ntsuas kub.service:

[Chav] Nqe lus piav qhia = Kev Pab Kub Tom Qab = ntau tus neeg siv.target

Teeb meem [email protected]

[Kev pabcuam] Hom = yooj yim

ExecStart =/usr/bin/python3 /home/pi/Documents/nmct-s2-project-1-TheryBrian/temperature/app.py

StandardInput = tty-quab yuam

Rov pib dua = ntawm-ua tsis tiav

RestartSec = 60s

[Nruab]

WantedBy = ntau-user.target

Kaw thiab rov ua dua tab sis tom qab ntawd rau backend_project.service:

Thawj qhib cov ntawv:

sudo nano /etc/systemd/system/backend_project.service

Tom qab ntawd rov luam dua thiab muab tshuaj txhuam:

[Chav] Nqe lus piav qhia = backend_project Service

Tom qab = ntau-user.target

Teeb meem [email protected]

[Kev pabcuam]

Hom = yooj yim

ExecStart =/usr/bin/python3 /home/pi/Documents/nmct-s2-project-1-TheryBrian/backend_project/app.py

StandardInput = tty-quab yuam

Rov pib dua = ntawm-ua tsis tiav

RestartSec = 60s

[Nruab]

WantedBy = ntau-user.target

Txuag thiab kaw.

Qhov kawg yog sau qhov no:

sudo systemctl daemon-reload

sudo systemctl pab kom sov.service sudo reboot

Tam sim no peb 2 tus nab npawb ntawv sau yuav tsum khiav ntawm lub khau raj.

Kauj Ruam 9: Teeb Lub Vev Xaib

Thaum koj rub tawm lub chaw cia khoom, koj yuav tsum tau txais daim nplaub tshev hu ua ntej. Nov yog qhov chaw cov ntsiab lus rau lub vev xaib.

Ua ntej peb xav tau apache ua ntej peb tuaj yeem siv daim nplaub tshev. Ua raws li phau ntawv qhia ntawm qhov txuas no rau apache.

Thaum koj npaj txhij. Mus rau qhov chaw uas cov ntawv tais ceev tseg nyob:

cd /Cov ntaub ntawv /nmct-s2-project-1-TheryBrian

Ces ntaus:

sudo mv pem hauv ntej/var/www/html

Thaum qhov ntawd ua tiav, mus rau html nplaub tshev, npaj rau qee qhov haujlwm tsis txaus siab (kuv qhov txhaum).

cd/ua/www/html/

tom qab ntawd nkag mus rau hauv lub nplaub tshev pem hauv ntej thiab pib txav txhua yam mus rau daim nplaub tshev html.

piv txwv:

sudo mv css/var/www/html

Tom qab ntawd rho tawm cov ntawv tais ceev tseg.

Thiab peb tau ua tiav nrog txhua yam.

Hmoov zoo:).

Kauj Ruam 10: Xaiv tau - Cov Qauv Me Me

Yeem - Cov Qauv Me Me
Yeem - Cov Qauv Me Me
Yeem - Cov Qauv Me Me
Yeem - Cov Qauv Me Me

Txog kev sim vim li cas kuv tau ua tus qauv ntawm tsuas yog ib lub thawv nrog txhua yam khoom siv sab hauv yog li kuv tuaj yeem pom yog txhua yam ua haujlwm kom xaj.

Feem ntau qhov haujlwm no yuav ua tiav ntawm qhov loj dua. Piv txwv li: ib chav, ib lub tsev, ib lub hoobkas, khw muag khoom thiab lwm yam …

Tab sis pom tseeb ua ntej peb pib ua qhov hauv phab ntsa (zoo nkauj sib dhos). Peb xub xav pom yog nws tsuas ua haujlwm. Koj tsis tas yuav ua lub thawv rau kev sim, tab sis nws ib txwm lom zem los ua qee yam khoom siv tes ua.

Nov yog kuv qhov piv txwv.

Pom zoo: