Zbotic Logo Zbotic Logo
  • Home
  • Shop
  • Sale
  • 3D Print Service
  • PCB Service
  • B2B
  • Blogs
  • Contact Us
0 0

View Wishlist Add all to cart

0 0
0 Shopping Cart
Shopping cart (0)
Subtotal: ₹0.00

View cartCheckout

  • Shop
  • About Us
  • Contact Us
  • Reseller
  • Blogs
020 69134444
1800 209 0998
[email protected]
Help Desk
Facebook Twitter Instagram Linkedin YouTube
Zbotic Logo Zbotic Logo
0 0

View Wishlist Add all to cart

0 0
0 Shopping Cart
Shopping cart (0)
Subtotal: ₹0.00

View cartCheckout

All departments
  • 3D Print Service
  • 3D Printer
  • Batteries & Chargers
  • Development Boards
  • Drone Parts
  • EBike parts
  • Sensor Modules
  • Electronic Components
  • Electronic Modules
  • IoT and Wireless
  • Mechanical Parts and Workbench Tools
  • Motors & Drivers & Pumps & Actuators
  • DIY and Robot Kits
  • Show more
  • Home
  • Shop
  • Sale
  • 3D Print Service
  • PCB Service
  • B2B
  • Blogs
  • Contact Us
Return to previous page
Home Arduino & Microcontrollers

Arduino IR Sensor Tutorial: Obstacle Avoidance & Remote Control

Arduino IR Sensor Tutorial: Obstacle Avoidance & Remote Control

March 11, 2026 /Posted byJayesh Jain / 0

Understanding how to use an Arduino IR sensor opens up a world of projects: obstacle-avoiding robots, TV remote decoders, security tripwires, and automated appliances. IR (infrared) sensors are inexpensive, easy to wire, and one of the most versatile components in any maker’s toolkit. In this tutorial we cover both types of IR sensors used with Arduino – the obstacle avoidance sensor and the IR receiver module – with complete wiring diagrams, real working code, and practical project examples.

Table of Contents

  • How IR Sensors Work
  • Types of IR Sensors for Arduino
  • Wiring the IR Obstacle Sensor
  • Obstacle Detection Code
  • Wiring the IR Receiver Module
  • Decoding Remote Signals with IRremote Library
  • Practical Project Examples
  • Frequently Asked Questions

How IR Sensors Work

Infrared light is electromagnetic radiation just beyond the red end of the visible spectrum, invisible to the human eye but detectable by photodiodes and phototransistors. IR-based sensors exploit two phenomena:

IR reflection (used in obstacle sensors): An IR LED emits a beam. When an object is nearby, the beam reflects back and hits an IR photodiode. The sensor outputs a digital LOW when an obstacle is detected and HIGH when the path is clear. Detection range is typically 2-30cm and is adjustable via a potentiometer on the module.

IR modulation (used in remote receivers): TV remotes and similar devices send IR pulses modulated at 38kHz. The TSOP or VS1838-type receiver demodulates this signal and outputs the raw pulse timing that your Arduino reads as serial data packets. The data encodes button codes in formats like NEC, Sony SIRC, or RC5.

Types of IR Sensors for Arduino

Feature IR Obstacle Sensor IR Receiver Module
Purpose Proximity/obstacle detection Remote control signal decoding
Output Digital: HIGH/LOW Timed pulse train (NEC/Sony/RC5)
Components IR LED + photodiode pair TSOP/VS1838 demodulator IC
Range 2-30cm (adjustable) Up to 10m line-of-sight
Typical use Robot line sensing, obstacle avoidance Home automation, remote-controlled devices
Library needed None (digitalRead) IRremote by Arduino-IRremote
Pins used 1 digital input 1 digital input (interrupt-capable preferred)
Recommended: IR Infrared Obstacle Avoidance Sensor Module – The standard obstacle sensor used in robot kits across India, adjustable range with onboard potentiometer.

Wiring the IR Obstacle Sensor

The IR obstacle avoidance sensor module has 3 pins: VCC, GND, and OUT. Wiring is straightforward:

  • Sensor VCC to Arduino 5V
  • Sensor GND to Arduino GND
  • Sensor OUT to Arduino Digital Pin 2 (or any digital pin)

The module has two LEDs: one green LED indicates power-on, and one red LED lights up when an obstacle is detected within range. There is also a small blue potentiometer on the board. Turning it clockwise increases sensitivity (shorter detection distance); counterclockwise decreases sensitivity (longer detection distance). Adjust it for your specific surface and ambient lighting conditions.

Important notes about IR obstacle sensors outdoors: Sunlight contains strong infrared radiation that can saturate the photodiode and cause false detections. These sensors work best indoors or in shaded environments. For outdoor robots, ultrasonic sensors (like HC-SR04) are more reliable.

Obstacle Detection Code

Reading the IR obstacle sensor requires just digitalRead(). The sensor output is active LOW, meaning it goes to 0 when an obstacle is detected and stays at 1 when the path is clear.

// IR Obstacle Sensor - Basic Detection
const int IR_PIN = 2;

void setup() {
  pinMode(IR_PIN, INPUT);
  Serial.begin(9600);
  Serial.println("IR Obstacle Sensor Ready");
}

void loop() {
  int sensorValue = digitalRead(IR_PIN);

  if (sensorValue == LOW) {
    // LOW = obstacle detected (active low logic)
    Serial.println("OBSTACLE DETECTED!");
  } else {
    Serial.println("Path clear");
  }

  delay(100);
}

For a robot with two IR sensors (left and right) for line following or dual-obstacle detection:

// Dual IR Sensor - Obstacle Avoidance Logic
const int LEFT_IR  = 2;
const int RIGHT_IR = 3;

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

void loop() {
  bool leftBlocked  = (digitalRead(LEFT_IR) == LOW);
  bool rightBlocked = (digitalRead(RIGHT_IR) == LOW);

  if (!leftBlocked && !rightBlocked) {
    Serial.println("Move forward");
    // moveForward();
  } else if (leftBlocked && !rightBlocked) {
    Serial.println("Turn right (left blocked)");
    // turnRight();
  } else if (!leftBlocked && rightBlocked) {
    Serial.println("Turn left (right blocked)");
    // turnLeft();
  } else {
    Serial.println("Both blocked - reverse");
    // moveBackward();
  }

  delay(50);
}

Wiring the IR Receiver Module

The IR receiver is used to decode signals from TV remotes and custom IR remote controllers. Common receiver ICs are TSOP1738, VS1838, HX1838, and IRM-3638T. All work the same way and use 3 pins.

For a standalone TSOP/VS1838 IC (not a breakout module):

  • Pin 1 (OUT) to Arduino Digital Pin 11 (or Pin 2/3 for interrupt on Uno)
  • Pin 2 (GND) to Arduino GND
  • Pin 3 (VCC) to Arduino 5V
  • Add a 100 ohm resistor in series on VCC and a 10uF capacitor between VCC and GND to filter power supply noise

For a breakout board module (HX1838 or similar):

  • Module VCC to Arduino 5V
  • Module GND to Arduino GND
  • Module OUT/S to Arduino Digital Pin 11
Recommended: HX1838 VS1838 NEC IR Remote Control Sensor Module – Comes with matching remote, ready for Arduino use right out of the packet.
Recommended: IRM-3638T Integrated IR Receiver – Compact through-hole receiver, ideal for embedding in custom PCBs and project enclosures.

Decoding Remote Signals with IRremote Library

The IRremote library (by Arduino-IRremote on GitHub) handles the timing and protocol decoding for you. Install it from the Arduino Library Manager: Sketch > Include Library > Manage Libraries > search “IRremote” > install the one by Arduino-IRremote (version 4.x recommended).

Step 1: Map your remote’s button codes

Every remote has unique codes for each button. Use this sketch to discover them:

#include <IRremote.hpp>

const int RECV_PIN = 11;

void setup() {
  Serial.begin(9600);
  IrReceiver.begin(RECV_PIN, ENABLE_LED_FEEDBACK);
  Serial.println("Point remote at sensor and press buttons...");
}

void loop() {
  if (IrReceiver.decode()) {
    Serial.print("Protocol: ");
    Serial.println(IrReceiver.decodedIRData.protocol);
    Serial.print("Address:  0x");
    Serial.println(IrReceiver.decodedIRData.address, HEX);
    Serial.print("Command:  0x");
    Serial.println(IrReceiver.decodedIRData.command, HEX);
    Serial.println("---");
    IrReceiver.resume(); // Ready for next signal
    delay(200);
  }
}

Open the Serial Monitor at 9600 baud, press each button on your remote, and note the hex command values. You will use these in your actual project code.

Step 2: Control actions with button codes

#include <IRremote.hpp>

const int RECV_PIN  = 11;
const int LED_PIN   = 13;
const int BUZZER    = 8;

// Button codes from your remote (replace with your own)
#define BTN_1     0x45   // Button 1 command code
#define BTN_2     0x46   // Button 2 command code
#define BTN_POWER 0x40   // Power button command code
#define BTN_VOLUP 0x15   // Volume up

bool ledState = false;

void setup() {
  pinMode(LED_PIN, OUTPUT);
  pinMode(BUZZER, OUTPUT);
  Serial.begin(9600);
  IrReceiver.begin(RECV_PIN, ENABLE_LED_FEEDBACK);
  Serial.println("IR Remote Control Ready");
}

void loop() {
  if (IrReceiver.decode()) {
    uint8_t cmd = IrReceiver.decodedIRData.command;
    Serial.print("Button: 0x");
    Serial.println(cmd, HEX);

    switch (cmd) {
      case BTN_POWER:
        ledState = !ledState;
        digitalWrite(LED_PIN, ledState);
        Serial.println("LED toggled");
        break;

      case BTN_1:
        tone(BUZZER, 440, 200); // Play 440Hz tone for 200ms
        Serial.println("Buzzer beep");
        break;

      case BTN_VOLUP:
        Serial.println("Volume up pressed");
        // Add your logic here
        break;
    }

    IrReceiver.resume();
  }
}

Practical Project Examples

Here are three practical projects you can build with IR sensors that are popular among Indian Arduino hobbyists and students:

Project 1: IR Obstacle-Avoiding Robot

Mount two IR obstacle sensors on the front-left and front-right of a wheeled robot chassis. Connect motors through an L298N or L293D motor driver. Read both sensors in the loop and steer away from whichever side detects an obstacle first. This is a classic first robotics project that can be built for under Rs. 500 in parts.

Project 2: IR Remote-Controlled LED Matrix

Use an 8×8 LED matrix with a MAX7219 driver and your IR receiver. Map remote buttons to display patterns, letters, or animations. Button 1 shows a smiley, button 2 shows an arrow, button 3 shows a number. This project teaches remote protocol decoding and SPI display control simultaneously.

Project 3: Smart Home TV Remote Relay Control

Use an IR receiver and a relay module to control a fan or light with any existing TV remote. Map specific unused buttons on your TV remote to toggle relays connected to appliances. This is the simplest form of home automation that does not require Wi-Fi or a smartphone, making it reliable even during network outages.

Combine with the obstacle sensor for added automation: automatically turn off a room fan when IR detects no one is present for 5 minutes (using a PIR sensor is better for this, but IR can work in narrow corridors).

Tip: When using IR receivers near fluorescent tube lights or CFLs, you may get spurious signals. Fluorescent lamps flicker at 50Hz/100Hz and emit IR. Shield your receiver or use a narrower-angle IR lens to reduce interference. LEDs and sunlight are the main sources of false triggers in Indian home environments.

Frequently Asked Questions

Q: What is the difference between an IR obstacle sensor and a PIR motion sensor?

An IR obstacle sensor actively emits IR light and detects its reflection, working at short range (up to 30cm). It detects any object regardless of temperature. A PIR (passive infrared) sensor passively detects changes in IR radiation from warm bodies (humans, animals) and works at longer ranges (up to 7m). Use obstacle sensors for robots and short-range detection; use PIR for room occupancy and security applications.

Q: My IR receiver does not decode any signals. What should I check?

Check in this order: (1) confirm the OUT pin goes to a digital pin that supports interrupts (pins 2 or 3 on Uno), (2) verify IRremote library version – version 4.x has a different API than version 2.x, (3) ensure you call IrReceiver.resume() after each decode, and (4) check for power supply noise by adding a 10uF capacitor between VCC and GND close to the sensor.

Q: Can I use an IR obstacle sensor as a line follower?

Yes, with caveats. IR obstacle sensors can detect dark lines on light surfaces by detecting the difference in IR reflectivity. However, dedicated line-following sensors (like TCRT5000) are better calibrated for this purpose and give more consistent results. The adjustable threshold on standard obstacle sensors makes them usable but less precise than purpose-built line sensors.

Q: How do I send IR signals from Arduino to control a TV?

Use the IRremote library’s send functions: IrSender.sendNEC(address, command, repeats). First discover the address and command codes of your TV by pointing a remote at an IR receiver and logging them. Then use IrSender with an IR LED (with a 100 ohm series resistor) connected to the send pin (default pin 3 on Uno). This lets Arduino act as a remote control for any IR-controlled device.

Ready to Build Your Next Arduino Project?

Shop sensors, modules, and components at Zbotic.in – India’s trusted electronics store with fast shipping across India.

Browse Arduino Products

Tags: arduino ir sensor, Infrared Sensor, ir obstacle sensor, ir receiver arduino, irremote library, obstacle avoidance robot
Share Post
  • Facebook
  • Linkedin
  • Whatsapp
PLA vs PETG: Which Filament Sh...
blog pla vs petg which filament should you use 594461
blog fpv camera video transmitter buying guide 594466
FPV Camera & Video Transmi...

Related posts

Svg%3E
Read more

Arduino Batch Programming: Flash Multiple Boards Quickly

April 1, 2026 0
Table of Contents Introduction Components and Hardware Setup Wiring Diagram and Connections Complete Code with Explanation Customization and Improvements Troubleshooting... Continue reading
Svg%3E
Read more

Arduino Based Radar System with Ultrasonic Sensor

April 1, 2026 0
Table of Contents Introduction Components and Hardware Setup Wiring Diagram and Connections Complete Code with Explanation Customization and Improvements Troubleshooting... Continue reading
Svg%3E
Read more

Arduino Automatic Plant Monitor: Sunlight, Moisture, Temperature

April 1, 2026 0
Table of Contents Introduction Components and Hardware Setup Wiring Diagram and Connections Complete Code with Explanation Customization and Improvements Troubleshooting... Continue reading
Svg%3E
Read more

Arduino Lie Detector: GSR Sensor Polygraph Project

April 1, 2026 0
Table of Contents Introduction Components and Hardware Setup Wiring Diagram and Connections Complete Code with Explanation Customization and Improvements Troubleshooting... Continue reading
Svg%3E
Read more

Arduino Metal Detector: Build a Treasure Finder

April 1, 2026 0
Table of Contents Introduction Components and Hardware Setup Wiring Diagram and Connections Complete Code with Explanation Customization and Improvements Troubleshooting... Continue reading

Add comment Cancel reply

Your email address will not be published. Required fields are marked

Facebook Twitter Instagram Pinterest Linkedin Youtube

Get the latest deals and more.

Download on Google Play Download on the App Store

Call us: 020 69134444 / 1800 209 0998

Monday - Saturday 09:30 AM - 06:00 PM
For Technical Supports Email: [email protected]
For Sales / Enquiries Email: [email protected]

  • My Account

    • Cart

    • Wishlist

    • Checkout

    • My Orders

    • Track Order

    • My Account

  • Information

    • FAQs

    • Blogs

    • Career

    • About Us

    • Contact Us

    • Payment Options

  • Policies

    • Privacy Policy

    • Terms & Conditions

    • GST Input Tax Credit

    • Shipping Return Policy

    • E-Waste Collection Points

    • Our Sitemap

© Zbotic.in is registered trademark of Moxie Supply Pvt Ltd – All Rights Reserved
Login
Use Phone Number
Use Email Address
Not a member yet? Register Now
Reset Password
Use Phone Number
Use Email Address
Register
Already a member? Login Now