Cảm biến tránh chướng ngại vật Arduino KY-032 là cảm biến tiệm cận hồng ngoại có thể điều chỉnh khoảng cách được thiết kế cho rô bốt có bánh xe. Còn được gọi là AD-032.
Khoảng cách phát hiện cảm biến dao động từ 2cm đến 40cm, nó có thể được điều chỉnh bằng cách xoay núm chiết áp. Điện áp hoạt động là 3.3V-5V nên nó phù hợp với nhiều loại vi điều khiển như Arduino, ESP32, Teensy, ESP8266, Raspberry Pi, và các loại khác.
Nó có khả năng thích ứng mạnh mẽ với ánh sáng xung quanh và khá chính xác để cảm nhận những thay đổi của môi trường xung quanh.
Sơ Đồ Kết Nối
COCe Chạy Chương Trình
int ledPin = 13; // LED pin on arduino
int detectorPin = 3; // obstacle avoidance sensor interface
int val; // variable to store result
//int enablePin = 2; // sensor enable interface (EN)
void setup()
{
pinMode(ledPin, OUTPUT); // Define LED as output interface
pinMode(detectorPin, INPUT); // Define obstacle avoidance sensor as input interface
// [uncomment and remove jumper on module to use enable pin (EN)]
//pinMode(enablePin, OUTPUT);
//digitalWrite(enablePin, HIGH); // Enable sensor
}
void loop()
{
val = digitalRead(detectorPin); // Read value from sensor
if(val == LOW) // When the sensor detects an obstacle, the LED on the Arduino lights up
{
digitalWrite(ledPin, HIGH);
}
else
{
digitalWrite(ledPin, LOW);
}
}
Trả lời