Uy jihozlarini ovoz bilan boshqarish tizimini yaratish MaxBotix mb1240 ultratovush masofa sensori Arduino qo'llanma
Oqil. KURS ISHI
- Bu sahifa navigatsiya:
- Maxbotix MB1240 Arduino misol kodi – tugmasi bilan tetik
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:
Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling
ma'muriyatiga murojaat qiling