Chủ Nhật, 16 tháng 2, 2020

Hướng dẫn cách lập trình arduino với cảm biến siêu âm SRF05

Không có nhận xét nào

Code:
// print distance to serial — hy_sr05
// Ty Seyoum
#define ECHOPIN 2 // Pin to receive echo pulse
#define TRIGPIN 3 // Pin to send trigger pulse
void setup(){
Serial.begin(9600); //
pinMode(ECHOPIN, INPUT);
pinMode(TRIGPIN, OUTPUT);
}
void loop(){
digitalWrite(TRIGPIN, LOW); // Set the trigger pin to low for 2uS
delayMicroseconds(2);
digitalWrite(TRIGPIN, HIGH); // Send a 10uS high to trigger ranging
delayMicroseconds(10);
digitalWrite(TRIGPIN, LOW); // Send pin low again
int distance = pulseIn(ECHOPIN, HIGH); // Read in times pulse
distance= distance/58; // Calculate distance from time of pulse
Serial.println(distance);
delay(200); // Wait 50mS before next ranging
}
Video có liên quan:
Hướng dẫn cách lập trình led RGB Arduino UNO R3 cơ bản:https://youtu.be/SbXITmAyuGA
Hướng dẫn cách lập trình đèn led cảnh sát với Arduino UNO R3:https://youtu.be/h6FcRKBype4
Hướng dẫn cách lập trình led nhấp nháy Arduino UNO R3 cơ bản:https://youtu.be/Pip-FOBjKAY
Hướng dẫn cách lập trình led rượt đuổi Arduino UNO R3 cơ bản:https://youtu.be/qZ7oE68CN_4 Chia sẽ kiến thức về điện tử.---------------------------------------------------------------------------------------
Người Biên Tập và chia sẻ:
Nguyễn Văn Khoa
Web: http://www.nguyenvankhoa.com/
Facebook: http://www.facebook.com/NguyenVanKhoaCom
Đăng ký kênh youtube: http://goo.gl/rHDTKK
Rất mong được sự ủng hộ của quý vị - NVK
Xin trân trọng!

Không có nhận xét nào :

Đăng nhận xét