Texnologiyalar vazirligi toshkent axborot texnologiyalar unversteti qarshi filiali


Simlarni ulash - HC-SR04 ni Arduino Uno-ga ulash


Download 1.91 Mb.
Pdf ko'rish
bet14/15
Sana16.06.2023
Hajmi1.91 Mb.
#1497981
1   ...   7   8   9   10   11   12   13   14   15
Bog'liq
18. Ortiqov Sherzod Arduino platformasida ultra

3.4 Simlarni ulash - HC-SR04 ni Arduino Uno-ga ulash 
Endi biz HC-SR04 ultratovushli masofa sensori qanday ishlashini to'liq 
tushunganimizdan so'ng, uni Arduino-ga ulashni boshlashimiz mumkin! 
HC-SR04-ni Arduino-ga ulash juda oson. Sensorni non taxtasiga o'rnatishdan 
boshlang. VCC pinini Arduino-dagi 5V piniga ulang va GND pinini Arduino-dagi 
Ground piniga ulang. Ishimiz tugagach, siz quyida ko'rsatilgan rasmga o'xshash 
narsaga ega bo'lishimiz kerak. 
9-rasm. Natijaviy proekt. 
 
 
 
 
 
 
 
 
 
 
 


32 
Dastur kodi: 
*/
#include  // includes the LiquidCrystal Library
LiquidCrystal
lcd
(
1

2

4

5

6

7
)

// Creates an LCD object. 
Parameters: (rs, enable, d4, d5, d6, d7)
const
int
trigPin = 
9

const
int
echoPin = 
10

long
duration; 
int
distanceCm, distanceInch; 
void
setup
()

lcd.
begin
(
16

2
); 
// Initializes the interface to the LCD screen, and 
specifies the dimensions (width and height) of the display
pinMode
(trigPin, 
OUTPUT
); 
pinMode
(echoPin, 
INPUT
); 

void
loop
()

digitalWrite
(trigPin, 
LOW
); 
delayMicroseconds
(
2
); 
digitalWrite
(trigPin, 
HIGH
); 
delayMicroseconds
(
10
); 
digitalWrite
(trigPin, 
LOW
); 
duration = 
pulseIn
(echoPin, 
HIGH
); 
distanceCm = duration * 
0.034

2

distanceInch = duration * 
0.0133

2

lcd.
setCursor
(
0

0
); 
// Sets the location at which subsequent text 
written to the LCD will be displayed
lcd.
print
(
"Distance: "
); 
// Prints string "Distance" on the LCD
lcd.
print
(distanceCm); 
// Prints the distance value from the sensor
lcd.
print
(
" cm"
); 
delay
(
10
); 
lcd.
setCursor
(
0

1
); 
lcd.
print
(
"Distance: "
); 
lcd.
print
(distanceInch); 
lcd.
print
(
" inch"
); 
delay
(
10
); 
}


33 
XULOSA 
Arduino-ni HC-SR04 ultratovush sensori yordamida masofani o'lchash uchun 
dasturlashning sodda va yaxshiroq usuli mavjud va bu NewPing kutubxonasidan 
foydalanadi. 
Oldin tushuntirilgan kodda biz sensorni qo'lda ishga tushirdik va qabul 
qilingan signal pulsining davomiyligini o'lchadik. Keyin ushbu natijalarga ko'ra biz 
masofani hisoblab chiqdik. NewPing kutubxonasidan foydalanib, biz faqat bitta kod 
qatori bilan masofani olishimiz mumkin.


34 

Download 1.91 Mb.

Do'stlaringiz bilan baham:
1   ...   7   8   9   10   11   12   13   14   15




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling