Cov txheej txheem:

Raspberry Pi Park Sensor: 3 Cov Kauj Ruam (nrog Duab)
Raspberry Pi Park Sensor: 3 Cov Kauj Ruam (nrog Duab)

Video: Raspberry Pi Park Sensor: 3 Cov Kauj Ruam (nrog Duab)

Video: Raspberry Pi Park Sensor: 3 Cov Kauj Ruam (nrog Duab)
Video: Wait what 😱 Flipper Zero 🐬 2024, Kaum ib hlis
Anonim
Image
Image
Yam Koj Yuav Tsum Muaj
Yam Koj Yuav Tsum Muaj

Hauv cov lus qhia no peb yuav tsim lub tiaj ua si sensor. Lub tswv yim ntawm lub tiaj ua si sensor no yog kom pom ntsuab thaum koj muaj chaw txaus los rub koj lub tsheb mus rau tom qhov chaw nres tsheb, thiab tom qab ntawd tig daj thaum koj mus txog qhov chaw ua ntej, thiab tom qab ntawd liab thaum koj yuav tsum nres. Peb tab tom tsim cov kab ke no nrog peb Raspberry Pi, thiab siv qee qhov kev ncua uas peb tuaj yeem sim yooj yim.

Kauj Ruam 1: Yam Koj Yuav Tsum Tau

Koj yuav xav tau cov khoom siv hauv qab no tsis yog teeb tsa Raspberry Pi.

  1. HC-SR04 Ultrasonic Distance Sensor
  2. Coj (X3)
  3. 330Ω Resistor (X3)
  4. 10KΩ Resistor (x2)
  5. Txiv neej-Txiv neej / Txiv neej-Poj niam Jumper Xov
  6. Cov qhob cij

Kauj Ruam 2: Ua Kev Txuas Hluav Taws Xob

Ua qhov thaiv
Ua qhov thaiv
Ua qhov thaiv
Ua qhov thaiv
Ua qhov thaiv
Ua qhov thaiv
  1. Ua rau qhov ntsuas qhov deb yog GPIO 4, ncha yog GPIO 18, lub teeb ntsuab yog 17, lub teeb daj yog 27 thiab lub teeb liab yog 22.
  2. 330 ohm resistors yog rau cov coj thiab lawv txuas rau qhov zoo ntawm cov leds thiab tom qab ntawd GPIO.
  3. 10K ohm resistors yog rau tus ncho tus pin ntawm qhov deb sensor thiab txuas rau GPIO.

Kauj ruam 3: Code

ntshuam RPi. GPIO ua GPIOimport lub sijhawm

GPIO.setwarnings (Cuav)

GPIO.cleanup ()

GPIO.setmode (GPIO. BCM)

TSI = 4

ECHO = 18

GREEN = 17

LAWD = 27

TZS = 22

GPIO.setup (TRIG, GPIO. OUT)

GPIO.setup (ECHO, GPIO. IN)

GPIO.setup (GREEN, GPIO. OUT)

GPIO.setup (YELLOW, GPIO. OUT)

GPIO.setup (RED, GPIO. OUT)

def ntsuab_light ():

GPIO. tawm (GREEN, GPIO. HIGH)

GPIO.output (YELLOW, GPIO. LOW)

GPIO.output (RED, GPIO. LOW)

def daj_light ():

GPIO. tawm (GREEN, GPIO. LOW)

GPIO.output (YELLOW, GPIO. HIGH)

GPIO.output (RED, GPIO. LOW)

def red_light (): GPIO.output (GREEN, GPIO. LOW)

GPIO.output (YELLOW, GPIO. LOW)

GPIO.output (RED, GPIO. HIGH)

def tau_distance ():

GPIO.output (TRIG, Tseeb)

lub sij hawm.sleep (0.00001)

GPIO.output (TRIG, Cuav)

thaum GPIO.input (ECHO) == Cuav: pib = sijhawm.time ()

thaum GPIO.input (ECHO) == Tseeb: kawg = time.time ()

signal_time = xaus-pib

nrug = signal_time / 0.000058

rov nrug deb

thaum Muaj Tseeb:

nrug = tau_distance ()

sijhawm.s pw (0.05)

luam tawm (nrug)

yog tias nrug> = 25:

ntsuab_light ()

elif 25> nrug> 10:

daj_light ()

elif nrug <= 5:

liab_light ()

Yog tias qhov nrug deb dua lossis sib npaug li 25 cm, peb pom lub teeb ntsuab. Yog tias nws nyob nruab nrab ntawm 10 txog 25 cm, peb yuav tig daj, thiab tom qab ntawd peb yuav tig liab rau tsawg dua lossis sib npaug li 10 cm.

Pom zoo: