Cov txheej txheem:

Siv Ultrasonic Distance Sensor thiab Serial Monitor Output.: 6 Kauj Ruam
Siv Ultrasonic Distance Sensor thiab Serial Monitor Output.: 6 Kauj Ruam
Anonim
Siv Ultrasonic Distance Sensor thiab Serial Monitor Output
Siv Ultrasonic Distance Sensor thiab Serial Monitor Output

Hav guys! Xav kawm paub yuav siv li cas saib xyuas cov ntawv tso tawm. Zoo ntawm no koj tau txais cov lus qhia zoo txog yuav ua li cas! Hauv cov lus qhia no, kuv yuav coj koj mus rau cov kauj ruam yooj yim xav tau txhawm rau txheeb xyuas qhov nrug deb siv lub ntsuas hluav taws xob ultrasonic thiab tshaj tawm nws ntawm lub ntsuas saib.

Kauj ruam 1: Kauj Ruam 1: Rub tawm Arduino IDE

Kauj ruam 1: Rub tawm Arduino IDE
Kauj ruam 1: Rub tawm Arduino IDE

Rub tawm thiab Txhim Kho Arduino IDE (Kev Sib Tham Sib Tham Ib puag ncig) siv qhov txuas hauv qab no:

www.arduino.cc/en/Main/Software Xaiv thiab khaws cov version uas zoo tshaj rau koj li kev ua haujlwm thiab teeb tsa.

Kauj Ruam 2: Kauj Ruam 2: Cov Khoom Kho Vajtse

  1. 1 Arduino pawg thawj coj saib
  2. 1 khob cij
  3. 1 Ultrasonic sensor
  4. Jumper xov hlau
  5. Resistors

Kauj Ruam 3: Kauj Ruam 3: Tsim Kho Vajtse

Kauj Ruam 3: Tsim Kho Vajtse
Kauj Ruam 3: Tsim Kho Vajtse

1) Ntxiv lub ntsuas hluav taws xob ultrasonic rau lub khob cij. Muaj 4 pins hauv lub ntsuas ultrasonic. Lawv yog Vcc (5V fais fab mov), Trig (Trigger), Echo, Gnd (Groud). Txuas Vcc mus rau 5V lub zog xa khoom, Gnd rau hauv av, Ncha rau tus pin 13, Ua rau tus pin 11 nrog cov xov hluav taws xob thiab cov tiv thaiv pom hauv daim duab.

2) Cov duab saum toj no qhia tau tias kev sib txuas yuav tsum zoo li cas.

Kauj Ruam 4: Kauj Ruam 4: Rub Tawm thiab Ua Haujlwm Txoj Haujlwm

Rub tawm qhov txuas program arduino rau koj lub laptop. Txuas lub arduino rau koj lub laptop, thiab khiav qhov program.

Hauv arduino IDE, Qhib Cov Cuab Yeej-> saib xyuas qhov chaw tso lub onstacle ze thiab deb ntawm lub ntsuas ultrasonic. Saib xyuas qhov tso tawm hauv cov saib. Qhov no yuav tsum qhia qhov deb ntawm ultrasonic sensor thiab qhov teeb meem.

Kauj Ruam 5: Kauj Ruam 5: Nkag Siab Qhov Kev Kawm

Ua ntej peb nkag siab tias ultrasonic sensor ua haujlwm li cas. Ib qho Ultrasonic sensor yog lub cuab yeej uas tuaj yeem ntsuas qhov deb mus rau ib qho khoom siv los ntawm kev siv lub suab nthwv dej. Nws ntsuas qhov nrug los ntawm kev xa tawm lub suab nthwv dej ntawm qhov tshwj xeeb thiab mloog rau lub suab nthwv dej kom thim rov qab. Nws pings cov teeb meem nrog ultrasound. Pawg tswj hwm Arduino xa cov mem tes luv los ua kom pom tau, tom qab ntawd mloog rau lub plawv dhia ntawm tus pin tib yam siv tus mem tesIn () muaj nuj nqi.

pulseIn () muaj nuj nqi yuav tos tus pin mus HIGH tshwm sim los ntawm lub suab nrov nrov thiab nws yuav pib lub sijhawm, tom qab ntawd nws yuav tos tus pin mus LOW thaum lub suab yoj yuav xaus uas yuav nres lub sijhawm. Thaum kawg qhov kev ua haujlwm yuav rov qab qhov ntev ntawm cov mem tes hauv microseconds. Txhawm rau kom tau txais qhov nrug peb yuav sib npaug lub sijhawm los ntawm 0.034 thiab faib nws los ntawm 2 raws li tau piav qhia hauv kab zauv no. Thaum kawg peb yuav luam tawm tus nqi ntawm qhov deb ntawm Serial Monitor.

Hauv txheej txheem teeb tsa, tshaj tawm tus pin 4 raws li Kev Nkag Mus thiab intializes buttonOn ua qhov tsis raug.

Hauv txoj kev voj, tus nqi tam sim no ntawm khawm nkag tau nyeem. yog tias nws raug nias, nws toggles khawm los ntawm tawm mus rau. Lub sijhawm tom ntej lub pob tau nias nws toggles los ntawm on to off. Kev ncua tau ntxiv los txo cov suab nrov thiab zam kev hloov pauv sai.

Pom zoo: