Cov txheej txheem:

Txheeb Xyuas Tsab Ntawv Siv Raspberry Pi: 4 Cov Kauj Ruam
Txheeb Xyuas Tsab Ntawv Siv Raspberry Pi: 4 Cov Kauj Ruam

Video: Txheeb Xyuas Tsab Ntawv Siv Raspberry Pi: 4 Cov Kauj Ruam

Video: Txheeb Xyuas Tsab Ntawv Siv Raspberry Pi: 4 Cov Kauj Ruam
Video: Saib Mis paub Poj niam (hluas nkauj) tus yam ntxwv lub siab 2024, Hlis ntuj nqeg
Anonim
Image
Image
Khoom siv
Khoom siv

Hauv cov lus qhia no, peb yuav kawm paub yuav ua li cas peb tuaj yeem siv PIR (Passive InfraRed) Sensor nrog Raspberry Pi, txhawm rau txhawm rau tsim lub ntsuas hluav taws xob yooj yim. Lawv feem ntau siv nyob rau hauv tub sab tub nyiag lub tswb thiab tau qhib lub teeb pom kev zoo.

Cov txheej txheem ua haujlwm:

Txhua yam khoom uas muaj qhov kub siab tshaj pes tsawg tsis muaj cua sov tso rau hauv daim ntawv hluav taws xob. Feem ntau qhov hluav taws xob no tsis pom rau tib neeg lub qhov muag vim tias nws tawg ntawm lub ntsej muag lub ntsej muag, tab sis nws tuaj yeem kuaj pom los ntawm cov khoom siv hluav taws xob tsim los rau lub hom phiaj no. (Source: Wikipedia)

Lub hom phiaj ntawm kev qhia:

Lub tswv yim tseem ceeb ntawm qhov kev qhia no yog Qhib ON Led yog tias lub suab pom, thiab Tua Tawm Led yog lwm qhov. Raws li kuv tau hais hauv qhov kev qhia koj tuaj yeem siv lub ntsuas hluav taws xob los tswj Lub Teeb Lub Teeb lossis Tswb siv Led.

Kauj Ruam 1: Cov khoom siv

Khoom siv
Khoom siv

Khoom Kho Vajtse:

1. Raspberry Pi 3 Qauv B.

2. PIR Sensor

3. Cov qhob cij

4. 220 Ohms Resistor

5. LED

6. Cov xov hlau

Cov Khoom Siv Software:

1. Raspbian Jessie (Operating System of Raspberry Pi: yog xav paub ntau ntxiv koj tuaj yeem saib mus rau kuv cov lus qhia yav dhau los ntawm no).

2. Python IDLE

Yog li kuv xav tias koj tau ua tiav qee qhov haujlwm tseem ceeb. Yog tias tsis yog, tsis txhob txhawj xeeb kuv qhia koj kom ua raws li kuv cov lus qhia yav dhau los (Pib Koj Thawj Txoj Haujlwm Nrog Raspberry: Tsaus Ntsig LED)

Kauj ruam 2: Circuit Court Assembly

Circuit Court los ua ke
Circuit Court los ua ke
Circuit Court los ua ke
Circuit Court los ua ke

Txoj hlua yog yooj yim heev, PIR sensor muaj peb tus pin:

1. Vcc mus rau 5v ntawm Raspberry's GPIO.

2. GND rau GNS ntawm Raspberry's GPIO.

3. Tawm mus rau 17 GPIO tus pin.

Txhawm rau txuas lub LED thiab tus tiv thaiv koj tuaj yeem ua raws cov theem hauv qab no:

1. Txuas 220Ω resistor rau anode ntawm LED, tom qab ntawd tus tiv thaiv rau 5 V.2. Txuas lub cathode ntawm LED mus rau 4 GPIO tus pin (Saib daim duab saum toj no).

Kauj ruam 3: Python Code

Python Code
Python Code

1. Qhib koj tus Pi thiab Tsim cov ntawv sau tshiab “pir.py” (Koj tuaj yeem sau npe cov ntawv raws li koj nyiam).

2. Ntaus cov cai hauv qab no:

ntshuam RPi. GPIO ua GPIO

ntshuam sij hawm GPIO.setmode (GPIO. BCM) GPIO.setup (17, GPIO. IN) #PIR GPIO.setup (4, GPIO. OUT) #Led sim: time.sleep (2) #kom ruaj khov sensor thaum Muaj tseeb: i = GPIO.input (17) yog tias kuv == 0: #Thaum cov zis tawm los ntawm lub ntsuas suab qis LOW GPIO.output (4, 0) #Tau OFF LED luam tawm ("Tsis pom lub suab pom", i) elif i == 1: #Thaum twg cov zis los ntawm cov ntawv tsa suab yog HIGH GPIO.output (4, 1) #Turn ON LED print ("Tsab ntawv tsa suab pom", i) tshwj tsis yog: GPIO.cleanup ()

3. Thaum koj tau ntaus tag nrho cov cai kos tseg tseg.

4. Khiav tus nab npawb nab npawb los ntawm kev ntaus cov cai hauv qab no hauv lub davhlau ya nyob twg:

- cd Desktop thiab nias Enter (Kuv ntaus Desktop vim kuv tau khaws cov ntaub ntawv hauv pi's Desktop).

- nab hab sej pir.py thiab nias Enter.

Kauj Ruam 4: Rau Kev Txhawb Nqa

Kev Txhawb Nqa
Kev Txhawb Nqa

Koj tuaj yeem sau npe yuav rau kuv li YouTube channel rau kev qhia ntau ntxiv thiab phiaj xwm. Sau npe yuav txhawb nqa. Ua tsaug.

Mus rau kuv tus YouTube Channel -link

Pom zoo: