Cov txheej txheem:

Lub Zeem Muag Sensor Lub Koob Yees Duab: 4 Kauj Ruam
Lub Zeem Muag Sensor Lub Koob Yees Duab: 4 Kauj Ruam

Video: Lub Zeem Muag Sensor Lub Koob Yees Duab: 4 Kauj Ruam

Video: Lub Zeem Muag Sensor Lub Koob Yees Duab: 4 Kauj Ruam
Video: Tshuaj theem vim li cas thiaj tau nqi ?/ Siv kho mob dab tsi?/paris polyphylla использовать для? 2024, Kaum ib hlis
Anonim
Nyob deb lub koob yees duab Sensor
Nyob deb lub koob yees duab Sensor

Cov lus qhia no yuav qhia koj yuav ua li cas thiaj Ua Lub Zeem Muag Sensor Lub Koob Yees Duab siv lub raspberry pi. Txoj haujlwm no yuav siv raspberry pi thiab siv nab hab sej 3 rau kev sau npe hauv qhov haujlwm no Lub Zeem Muag Sensor Lub Koob Yees Duab yuav xub ntsuas tawm 100 cm tom qab ntawd yuav ntsais RGB LED thiab yuav thaij duab. Tom qab ntawd los qhia tias daim duab tau yees duab lawm RGB LED yuav yog xim xiav xim. Tom qab ntawd txhawm rau nkag mus rau daim duab koj mus rau lub rooj saum toj kawg nkaus ntawm raspberry pi uas daim duab tau yees duab.

Koj yuav xav tau:

  • 1 x Raspberry Pi
  • 1 x T-Cobbler
  • 1x Tag Nrho Qhov Loj Breadboard
  • 1x Pi Lub Koob Yees Duab
  • 1 x RGB LED (Cathode)
  • 1 X nrug Sensor
  • 1 x 330 Ω Resistor
  • 1 x 560 Ω Resistor
  • Xiav Hlau
  • Cov xov dub
  • Liab Hlau

Kauj ruam 1:

Duab
Duab

Tau txais cov ntu thiab txuas T-Cobbler mus rau Raspberry Pi thiab cov ntawv ci. Tom ntej teeb tsa hauv av thiab cov xov hluav taws xob. Los ntawm 5.0 v txiav thiab sawb txaus ntawm cov hlau liab kom haum rau hauv lub qhov tom ntej 5.0 v ntawm T-Cobbler thiab muab tso rau sab zoo ntawm qhov zoo thiab qhov tsis zoo ntawm lub rooj tsavxwm ntawm ib sab. Tom qab ntawd ua qhov koj nyuam qhuav tau ua tab sis nrog xaim dub nkag rau hauv GND thiab qhov ntawd nkag mus rau qhov tsis zoo. Tom qab ntawd mus rau lwm sab ntawm lub khob cij thiab txuas ob sab zoo ua ke thiab ob sab tsis zoo ua ke nrog xaim kom qhov zoo yog liab thiab tsis zoo yog dub. Raws li qhia hauv kab lus no

Kauj ruam 2:

Duab
Duab

Siv lub ntsuas nrug, RGB LED, thiab lub koob yees duab pi thiab muab tso rau hauv qhov chaw ntawm tus pi thiab daim txiag ntoo. Txuas lub koob yees duab pi mus rau raspberry pi hauv qhov chaw qhia. Tom qab ntawd muab RGB LED tso rau hauv lub khob cij thiab xyuas kom tseeb tias txhua qhov ua tau zoo nkag mus rau hauv lub qhov uas koj muab tso rau hauv. Nyeem txog dab tsi RGB LED koj muaj thiab ceeb toom tias cov hlau lead yog dab tsi. Tom qab ntawd nrhiav qhov chaw rau qhov ntsuas qhov deb ntawm lub khob cij uas tsis muaj dab tsi nyob hauv txoj kev. Daim ntawv ceeb toom tias cov hlau lead mus qhov twg raws li koj yuav tsum paub rau qib tom ntej.

Kauj ruam 3:

Duab
Duab

Tam sim no ua kom tiav cov xov hluav taws xob hauv Circuit Court thiab nrhiav cov resistors raug rau txoj haujlwm raug. Yog li los sawv cev rau lub zog Kuv tau siv xov tooj liab, rau hauv av Kuv siv cov xov hlau dub, thiab rau GPIO cov xov hlau Kuv tau siv cov xov hlau xiav. Thiab hauv cov kauj ruam no peb tseem yuav muab cov resistors tso rau hauv qhov chaw raug los ntawm qhov deb sensor. Yog tias xav tau ua raws cov txheej txheem yuav ua li cas xaim kab hluav taws xob no.

Kauj ruam 4:

Duab
Duab

Tam sim no rau cov kauj ruam no peb yuav tau coding thiab rau qhov no peb yuav siv nab hab sej 3. dab tsi yuav tsum tshwm sim yog tias yog qhov nrug nruab nrab ntawm koj thiab lub ntsuas nrug deb tshaj 100 cm ces lub koob yees duab yuav yees duab. Tab sis tsuas yog ua ntej daim duab nws yuav nyem liab thiab tom qab yees duab nws yuav yog xim tawv tawv.

Nab hab sej 3 code

ntshuam RPi. GPIO li GPIO los ntawm picamera ntshuam PiCamera los ntawm lub sijhawm ntshuam pw, sijhawm los ntawm gpiozero ntshuam LED, Khawm

lub koob yees duab = PiCamera ()

GPIO.setmode (GPIO. BCM)

GPIO_TRIGGER = 13GPIO_ECHO = 19 liab = LED (16) ntsuab = LED (20) xiav = LED (21) dua = Tseeb

GPIO.setwarnings (Cuav) GPIO.setup (GPIO_TRIGGER, GPIO. OUT) GPIO.setup (GPIO_ECHO, GPIO. IN)

def RedLight (): red.blink () ntsuab.on () xiav.on ()

def BlueLight (): red.on () ntsuab.on () blue.off ()

def GreenLight (): red.on () ntsuab.off () blue.on ()

def nrug (): GPIO.output (GPIO_TRIGGER, Tseeb)

pw tsaug zog (0.00001) GPIO.output (GPIO_TRIGGER, Tsis tseeb)

StartTime = sijhawm () StopTime = sijhawm ()

thaum GPIO.input (GPIO_ECHO) == 0: PibTime = sijhawm ()

thaum GPIO.input (GPIO_ECHO) == 1: StopTime = sijhawm ()

TimeElapsed = StopTime - StartTime nrug = (TimeElapsed * 34300) / 2

rov nrug deb

sim: thaum ntxiv: deb = nrug () yog tias nrug> 100: camera.start_preview () RedLight () RedLight () pw (5) camera.capture ('/home/pi/Desktop/Image.jpg') camera.stop_preview () BlueLight () dua = Sau tsis raug ("Ntsuas Kev Ntsuas = %.1f cm" % deb) pw tsaug zog (1)

# Rov pib dua los ntawm nias CTRL + Cexcept KeyboardInterrupt: luam tawm ("Kev ntsuas ntsuas nres los ntawm Tus Neeg Siv") GPIO.cleanup ()

Pom zoo: