Module capteur infrarouge d’évitement d’obstacles HW-201, interrupteur de proximité pour voiture intelligente et Arduino
| Broche | Signal | Description |
|---|---|---|
VCC |
power | Positive supply input for the IR obstacle sensor module, typically 3.3–5V. |
GND |
ground | Ground reference for power and the OUT signal. |
OUT |
digital | Digital comparator output indicating obstacle detection, usually active-low. |
| De | Vers | Fil |
|---|---|---|
board:5V |
x1:VCC |
red |
board:GND |
x1:GND |
black |
board:D2 |
x1:OUT |
green |
Cet exemple a été écrit et vérifié à la compilation pour le arduino-uno. Codey Online l'adapte pour vous à toute autre carte prise en charge.
// HW-201 Infrared Obstacle Avoidance Module
// Reads the module's digital OUT pin and prints obstacle status to Serial.
// Many HW-201 modules are active-low: OUT goes LOW when an obstacle is detected.
const int sensorPin = 2;
void setup() {
pinMode(sensorPin, INPUT);
Serial.begin(9600);
while (!Serial) {
;
}
Serial.println("HW-201 Infrared Obstacle Avoidance Module");
Serial.println("Active-low output: LOW = obstacle detected, HIGH = no obstacle");
}
void loop() {
int state = digitalRead(sensorPin);
if (state == LOW) {
Serial.println("Obstacle detected");
} else {
Serial.println("No obstacle");
}
delay(200);
}
Décrivez ce que vous voulez créer. Codey Online écrit le code, dessine le schéma de câblage, le compile et flashe votre carte directement depuis le navigateur.
Commencez gratuitement