Fork me on GitHub

Project Notes

#806 FC-51 IR Obstacle Avoidance Sensor Module

Testing a common infrared obstacle avoidance sensor module, and reviewing the behaviour of the LM393-based comparator circuit when used directly or with a microcontroller (Arduino). Includes suggestions for practical use.

Build

Notes

This is a common infrared obstacle avoidance sensor module, often referred to as the “FC-51”, “MH-B” or with the branding “MH-Sensor-Series Flying-fish”. As yet, I’ve been unable to determine the original designer or manufacturer of the modules. They are widely available - I purchased the module used here from an aliexpress seller for SG$1.03 in Dec-2025.

module

Specifications

I haven’t found an original datasheet for the module, however all sellers provide a similar details.

Product Description:

  • Product name: infrared obstacle avoidance module (from 2 to 30cm adjustable)
  • Product size: 31.3mm X 14.2mm X 6.6mm (length x width x height)
  • Board color: blue
  • Product weight: 3.42g (including packaging)

Use:

  • When no obstacle detected:
    • OUT port level is high (5V)
    • green obstacle detector LED is off
  • When no obstacle detected, circuit board on the green light is lit, the OUT port at the same time
    • OUT port level is low (0V)
    • green obstacle detector LED is on
  • Obstacles can be detected from 2-30cm, with a 35° maximum angle of detection
  • Detection distance can be adjusted with the potentiometer:
    • clockwise increases the detection distance
    • counter-clockwise reduces the detection distance
  • Detection is performed with active infrared reflection, therefore the reflectivity, size and shape of the target will affect the detection range.
  • The sensor module output port OUT can be directly connected to the microcontroller I/O port, can also direct drive a 5V relay for example
  • Uses an LM393 comparator
  • Can use 3.3V to 5V DC power. When powered, the power indicator LED will be on.

Module schematic:

module-schematic

The LM393 is used in simple comparator mode without feedback. It compares the received IR signal with the threshold set with the potentiometer. LM393 package details:

lm393-package

Initial Module Tests

Although primarily intended to be used with a microcontroller, the module provides a binary signal that could be used in any appropriate circuit.

The output has a built-in 10kΩ pull-up and output indicator LED, so the main concern is to provide a relatively high-impedance load so as to avoid floating the output between states.

For initial testing with the module, I have added an external nFET to drive a “clear” indicator LED:

Obstacle Built-in LED External LED
Clear OFF ON
Detected ON OFF

Designed with Fritzing: see fc-51-basic-test.fzz.

bb

schematic

Setup on a breadboard. This is the “clear” state (nothing detected):

bb_build

A scope trace showing a series of object occlusions. The first few at close range show clear on/off transitions, but the 5th showing oscillation as I try I test at maximum range.

test01a

Transition captured at close range:

test01b

When set for long range, I can still get reliable object detection up to about 30cm within a cone of about 35˚:

test02

However, at long range, there can be significant crossover oscillation:

test01c

Using the Module with an Arduino

Most people are probably using this module with a microcontroller. Let’s do some simple tests with an Arduino:

  • detector powered from the Arduino 5V rail
  • detector output connected to Arduino pin 2, as this supports hardware interrupts
  • the built-in LED on pin 13 is used to indicate detector state

Designed with Fritzing: see fc-51-sensor-module.fzz.

bb

schematic

Setup with a breadboard to facilitate connecting a scope to the signals:

bb_build

The Sketch

The sketch implements a simple hardware interrupt-driven scheme but with hysteresis to avoid crossover oscillation:

  • an on-change interrupt sets a detector_flag
  • the getDetectorState function
    • reads a new detector state if a change has been flagged since the last call
    • returns the current detector state
  • the main loop polls the detector state every 100ms.

See fc-51-sensor-module.ino:

/*

  FC-51 IR Obstacle Avoidance Sensor Module Demo

  For info and circuit diagrams see https://github.com/tardate/LittleArduinoProjects/tree/main/Electronics101/IR/fc-51-sensor-module

 */

const int LED_PIN = 13;
const int DETECTOR_PIN = 2;
const int DELAY = 100;
volatile bool detector_flag = HIGH;
bool detector_state = LOW;

/*
 * On detector trigger, set flag
 */
void detectorInterrupt() {
  detector_flag = HIGH;
}

/*
 * Return the current detector state. HIGH - obstacle detected, LOW - no obstacle
 * Reads new value if a change has been detected
 */
bool getDetectorState() {
  if (detector_flag) {
    detector_state = !digitalRead(DETECTOR_PIN);
    detector_flag = LOW;
  }
  return detector_state;
}

/*
 * Command: one-time setup
 */
void setup() {
  pinMode(LED_PIN, OUTPUT);
  pinMode(DETECTOR_PIN, INPUT);
  attachInterrupt(digitalPinToInterrupt(DETECTOR_PIN), detectorInterrupt, CHANGE);
}


/*
 * Command: main loop
 */
void loop() {
  digitalWrite(LED_PIN, getDetectorState());
  delay(DELAY);
}

Arduino Test Results

Capturing the behaviour on a scope:

  • CH1 (Yellow) - detector output (offset -5V)
  • CH2 (Blue) - Arduino output pin13 (offset +1V)

One can see the sketch effectively dampening the response:

test03a

Conclusions

The FC-51 (or similar) modules are simple and quite effective. The circuit uses basic components and can easily be made oneself, but probably not cheaper!

From tests:

  • When set for short range detection (under 20cm), detection transitions are generally quite clean
  • When set for long range detection (up to 30cm and beyond), there can be significant crossover oscillation

Practical considerations:

  • Use the shortest range detection possible to ensure clean transitions
  • For longer range detection, may need dampening or de-bouncing in hardware or code to avoid ringing/oscillation at transition
  • I did note that sunlight and even bright LED lamps can interfere with the reading. One may need to shield from light outside the cone of focus.

Credits and References

About LEAP#806 IRSensorsArduinoLM393

This page is a web-friendly rendering of my project notes shared in the LEAP GitHub repository.

Project Source on GitHub Return to the LEAP Catalog
About LEAP

LEAP is my personal collection of electronics projects - usually involving an Arduino or other microprocessor in one way or another. Some are full-blown projects, while many are trivial breadboard experiments, intended to learn and explore something interesting.

Projects are often inspired by things found wild on the net, or ideas from the many great electronics podcasts and YouTube channels. Feel free to borrow liberally, and if you spot any issues do let me know or send a pull-request.

NOTE: For a while I included various scale modelling projects here too, but I've now split them off into a new repository: check out LittleModelArt if you are looking for these projects.

Project Gallery view the projects as an image gallery Notebook reference materials and other notes Follow the Blog follow projects and notes as they are published in your favourite feed reader