Today, we are going to fix that. Here is the actual working datasheet for the MH Flying Fish IR Sensor—no confusion included.
The datasheet says "20cm"? Lie. This is a proximity sensor, not a distance sensor. Max reliable range is ~2.5cm (1 inch). If you need long range, buy an ultrasonic or Time-of-Flight (VL53L0X) sensor. Mh Sensor Series Flying Fish Ir Sensor Datasheet Fixed
Your object is too shiny or too dark. This sensor hates glossy white surfaces (reflects too well) and pure black surfaces (absorbs all IR). For line following, use white tape on black paper. Today, we are going to fix that
void loop() { int sensorState = digitalRead(sensorPin); Mh Sensor Series Flying Fish Ir Sensor Datasheet Fixed