
No. 18 • Digital
Obstacle Avoidance Sensor
ตรวจจับสิ่งกีดขวางด้านหน้าด้วย IR emitter/receiver
Component NameObstacle Avoidance Sensor
Part No. / Model-
Interface TypeDigital
PinsVCC, GND, OUT
Note: พื้นผิวสีดำหรือเงาอาจทำให้ตรวจจับคลาดเคลื่อน
Wiring Example
ตัวอย่างการต่อวงจรกับ Arduino UNO
| Sensor Pin | Arduino Pin |
|---|---|
| VCC | 5V |
| GND | GND |
| OUT | D2 |
Arduino IDE Code
// Obstacle Avoidance Sensor
// Board: Arduino UNO
// Read digital output from the sensor module.
const int SENSOR_PIN = 2;
void setup() {
Serial.begin(9600);
pinMode(SENSOR_PIN, INPUT);
}
void loop() {
int state = digitalRead(SENSOR_PIN);
Serial.print("Sensor state: ");
Serial.println(state);
delay(300);
}