Werktags vor 14:00 Uhr bestellt = am selben Tag versendet 30 Tage Widerrufsrecht 1 Jahr Garantie
← Zurück zur Übersicht

Schaltplan und Codebeispiel

So schließt du den Infrarot-Hindernisvermeidungsmodul HW-201 an einen Arduino UNO oder ESP32 an, mit einem Beispiel-Sketch, den du direkt hochladen kannst.

IR-Hinderniserkennung mit HW-201

Dieses Projekt verwendet einen HW-201 Infrarot-Hindernisvermeidungssensor, um Objekte in der Nähe zu erkennen. Wenn ein Hindernis in den Erfassungsbereich kommt, wird der digitale Ausgang des Sensors LOW, wodurch die eingebaute LED des Arduino eingeschaltet und Erkennungswarnungen im Serial Monitor ausgegeben werden. Stelle das onboard-Potentiometer am Sensormodul ein, um die Erkennungsdistanz zu kalibrieren.

Anschlussplan: Infrarot-Hindernisvermeidungsmodul HW-201 an einem Arduino UNO
Anschlussplan · Zum Vergrößern klicken
Anschlusstabelle: Infrarot-Hindernisvermeidungsmodul HW-201 an einem Arduino UNO
Anschlusstabelle · Zum Vergrößern klicken
IR_Obstacle_Detection_with_HW_201.ino · kompiliert und getestet
/*
 * ==================================================================
 *  Generated by Codey.online  —  https://www.codey.online
 * ==================================================================
 *  Project   : IR Obstacle Detection with HW-201
 *  Board     : Arduino UNO (arduino:avr:uno)
 *  Parts     : HW-201 Infrared Obstacle Avoidance Module
 *  Libraries : none (built-in)
 *
 *  Codey Online is an AI-powered browser IDE for Arduino and ESP32.
 *  Describe your project and Codey writes the code, draws the wiring
 *  diagram and uploads it to your board, straight from the browser.
 *  This code is free to use, modify and share, without warranty.
 * ==================================================================
 */

// Pin definitions
const int sensorPin = 2;
const int ledPin = 13;

void setup() {
  pinMode(sensorPin, INPUT);
  pinMode(ledPin, OUTPUT);

  Serial.begin(115200);
  Serial.println(F("HW-201 IR Obstacle Sensor Demo"));
  Serial.println(F("Ready: Move an object in front of the sensor."));
}

void loop() {
  // The HW-201 sensor outputs LOW when an obstacle is detected
  int sensorState = digitalRead(sensorPin);

  if (sensorState == LOW) {
    digitalWrite(ledPin, HIGH);
    Serial.println(F("Obstacle Detected!"));
  } else {
    digitalWrite(ledPin, LOW);
    Serial.println(F("Clear (no obstacle)"));
  }

  delay(200);
}

Wiring diagram and example code generated by Codey.online — https://www.codey.online

IR-Hinderniserkennung mit ESP32

Dieses Projekt liest den digitalen Ausgang des HW-201 Infrared Obstacle Avoidance Module aus. Wenn ein Objekt innerhalb der Reichweite erkannt wird, geht der Sensor-Ausgang auf LOW, wodurch die eingebaute LED des ESP32 aufleuchtet und eine Warnung im Serial Monitor ausgegeben wird. Du kannst die Erkennungsdistanz mit dem Potentiometer auf dem Modul anpassen.

Anschlussplan: Infrarot-Hindernisvermeidungsmodul HW-201 an einem ESP32 DevKit V1
Anschlussplan · Zum Vergrößern klicken
Anschlusstabelle: Infrarot-Hindernisvermeidungsmodul HW-201 an einem ESP32 DevKit V1
Anschlusstabelle · Zum Vergrößern klicken
IR_Obstacle_Detection_with_ESP32.ino · kompiliert und getestet
/*
 * ==================================================================
 *  Generated by Codey.online  —  https://www.codey.online
 * ==================================================================
 *  Project   : IR Obstacle Detection with ESP32
 *  Board     : ESP32 DEVKIT V1 (esp32:esp32:esp32doit-devkit-v1)
 *  Parts     : HW-201 Infrared Obstacle Avoidance Module
 *  Libraries : none (built-in)
 *
 *  Codey Online is an AI-powered browser IDE for Arduino and ESP32.
 *  Describe your project and Codey writes the code, draws the wiring
 *  diagram and uploads it to your board, straight from the browser.
 *  This code is free to use, modify and share, without warranty.
 * ==================================================================
 */

// HW-201 IR Obstacle Sensor with ESP32
const int SENSOR_PIN = 4;   // Connected to OUT pin of HW-201
const int LED_PIN = 2;      // Onboard LED

void setup() {
  Serial.begin(115200);
  pinMode(SENSOR_PIN, INPUT);
  pinMode(LED_PIN, OUTPUT);
  
  Serial.println("HW-201 Obstacle Sensor Ready");
}

void loop() {
  // The HW-201 output is active-LOW (LOW when an obstacle is detected)
  int sensorState = digitalRead(SENSOR_PIN);

  if (sensorState == LOW) {
    digitalWrite(LED_PIN, HIGH);
    Serial.println("Obstacle detected!");
  } else {
    digitalWrite(LED_PIN, LOW);
    Serial.println("Path clear");
  }

  delay(200);
}

Wiring diagram and example code generated by Codey.online — https://www.codey.online

Zuletzt angesehen

ESP32-WROOM-32U DevkitC V4 USB-C und externer Antennenanschluss (ipex)

ESP32-WROOM-32U DevkitC V4 USB-C und externer Antennenanschluss (ipex)

€ 11,95