Вернуться на страницу библиотеки модулей

/*
  KY-033 Line Tracking Sensor — reads the digital OUT pin and prints a
  message only when the state changes (sensor moves onto or off a line).

  Calibration: hold the sensor over the surface you want to detect and
  turn the onboard potentiometer until the indicator LED switches right
  at the edge between the line and its background.
*/

const int sensorPin = 7;   // KY-033 OUT -> Arduino digital pin D7

// Some KY-033 boards read HIGH over a black line, others read LOW.
// After calibrating, set this to the level your board shows when the
// sensor is OVER the line. If the two messages are swapped, just flip
// this from HIGH to LOW (or back) — it is the only change needed.
const int LINE_STATE = HIGH;

int lastReading = -1;      // -1 forces a print on the first reading

void setup() {
  pinMode(sensorPin, INPUT);
  Serial.begin(9600);
}

void loop() {
  int reading = digitalRead(sensorPin);

  if (reading != lastReading) {       // only act when the state changes
    if (reading == LINE_STATE) {
      Serial.println("Line detected");
    } else {
      Serial.println("No line");
    }
    lastReading = reading;
  }

  delay(50);   // brief settle time between reads
}

Рекомендуемые ссылки:
Arduino Line Tracking Sensor Module KY-033 (HW-511) — Wiring & Code
KY-033 Linetracking sensor – SensorKit
Using the Tracking Sensor Module KY-033 with Arduino – Phipps Electronics
KY-033 Line Following Robot Arduino: Complete Beginner Tutorial
Line Tracking Sensor KY-033 With Arduino and Buzzer: : 3 Steps – Instructables
ESP32 KY-033 Line Tracking Sensor Module Pinout

Вернуться на страницу библиотеки модулей