Uy jihozlarini ovoz bilan boshqarish tizimini yaratish MaxBotix mb1240 ultratovush masofa sensori Arduino qo'llanma


Download 451.92 Kb.
bet6/7
Sana24.12.2022
Hajmi451.92 Kb.
#1062267
1   2   3   4   5   6   7
Bog'liq
Oqil. KURS ISHI

Pin

Arduino

GND

GND

V+

5 V

Pin 2paper size

Pin 2paper size

Pin 4

Pin 3paper size

Tugma pin 1

Pin 4

Tugma pin 2

GND


Maxbotix MB1240 Arduino misol kodi – tugmasi bilan tetik


Sensorni tetik bilan boshqarish uchun ushbu misol eskizidan foydalanishingiz mumkin. Bunday holda, sensor tugmachani bosganingizda o'qishni oladi va ketma-ket monitorda masofani o'lchashni ko'rsatadi. Agar o'qish olish istayman qachon siz ham faqat read_sensor vazifasini qo'ng'iroq mumkin.
Serial.println("Sensor is ready, waiting for button press!");
}
void read_sensor()
{ digitalWrite(triggerPin, HIGH);
delayMicroseconds(20);
digitalWrite(triggerPin, LOW);
duration = pulseIn(readPin, HIGH);
distance = duration / 58;
delay(100); }
void print_data() {
Serial.print("distance = ");
Serial.print(distance);
Serial.println(" cm"); }
void loop() {
buttonState = digitalRead(buttonPin);
if (buttonState == LOW && previous == HIGH && millis() - time > debounce) {
read_sensor();
print_data();
time = millis(); }
previous = buttonState;
}
Serial monitorda quyidagi chiqishni ko'rishingiz kerak (Ctrl + Shift + M).



Download 451.92 Kb.

Do'stlaringiz bilan baham:
1   2   3   4   5   6   7




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