Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe

Arduino-based optical proximity sensor using IR LEDs

By Nikhil Agnihotri March 22, 2024

Proximity sensors are used to detect something approaching near. These sensors are useful in many applications like collision avoidance, obstacle detection, path following, touchless sensing, motion detection, and object detection. There are different types of proximity sensors like optical, ultrasonic, capacitive, inductive, and magnetic. The capacitive, inductive, and magnetic proximity sensors are used in specific electronic applications. The optical and ultrasonic proximity sensors have much general use and are quite common among electronics. These sensors come in a wide range according to their technology and distance of sensing.

The most simple kind of proximity sensor is the optical one. These proximity sensors are designed using active infrared sensors, consisting of a pair of IR source and an IR detector. The IR source can be either IR LED (Infrared Light Emitting Diode) or IR Laser Diode. The IR LED or IR Laser Diode transmits infrared light. This light is reflected by any object on which it falls. IR photodiodes that operate as IR detectors are placed in the sensor to capture the reflected IR radiations in a predefined range of distance and angle. Closer is the reflecting object; higher is the intensity of infrared radiation reflected, and lower IR photodiode resistance drops. As a result, IR photodiode passes through greater voltage than when there are no incident IR radiation.

Working of active IR sensors

In this project, a proximity sensor built using IR LED and IR photodiode is used. The proximity sensors built using IR LEDs can sense objects at a short range of few centimeters. The sensor is interfaced with Arduino for application demonstration. In this project, we simply fast blink an LED as the sensor detects a near approaching object. The fast blinking of LED in this project indicates the possibility of a collision with the near approaching object. It gives a visual indication to the user to urge her to act quickly, avoiding a collision.

Example of IR proximity sensor

Components required

  1. Arduino UNO x1
  2. IR LED-Photodiode Module x1
  3. LED x1
  4. Resistor 330Ω x1
  5. Breadboard x1
  6. Connecting wires or jumper wires

Circuit connections

The commonly available IR LED-photodiode pair has three terminals – Ground, VCC, and Output. Connect the VCC and ground terminals of the IR module with 5V out and one of the ground channels of Arduino UNO. Connect the output of the sensor module to pin 2 of the Arduino. Connect the anode of a LED at pin 3 of Arduino UNO while connecting its cathode to the ground. Remember to place a current limiting resistor of 330Ω in series with the LED.

Circuit diagram

Circuit diagram of Arduino and IR LED based proximity sensor

Arduino sketch

unsigned int IRpin = 2;
unsigned int Indicatorpin = 3;

void blink_indicator(){
digitalWrite(Indicatorpin, HIGH);
delay(200);
digitalWrite(Indicatorpin, LOW);
delay(200);
}

void setup() {
pinMode(IRpin, INPUT_PULLUP);
pinMode(Indicatorpin, OUTPUT);
}

void loop() {
if(digitalRead(IRpin) == LOW) blink_indicator();
else digitalWrite(Indicatorpin, LOW);
}

How the circuit works

The IR LED is connected in forward bias in the sensor module. As 5V DC powers the module, the IR LED starts emitting IR radiations. An IR photodiode is placed parallel to the IR LED to detect the reflected radiations. The photodiode is connected in a voltage divider network, whose output goes to the inverting input of LM393 comparator IC. The non-inverting input of the same comparator is connected to a pot for adjustment of the reference voltage. The output of the comparator is taken as the output of the module.

Circuit diagram of IR LED LM393 proximity sensor

When the IR detector receives reflected radiations, its resistance drops. As a result, a voltage higher than the reference voltage is applied at the comparator’s inverting input, and the comparator output turns to LOW.

Arduino is programmed to detect digital input from the IR module. As it detects a LOW logical signal from the IR sensor, it starts blinking LED connected at pin 3. When there is a HIGH logical signal from the IR module in the absence of any near approaching object, Arduino keeps the LED connected at pin 3.

How the code works

The Arduino sketch begins with pin assignment to the IR sensor and indicator LED. In the setup() function, the pin connecting the IR sensor is set to digital input, and the pin connecting indicator LED is set as output. A function blink_indicator() is defined to blink the LED at an interval of 200 milliseconds. In the loop() function, if a LOW is detected at the IR pin, blink_indicator() function is called. Otherwise, the LED pin is set to LOW, keeping the LED off.

Result

Circuit of Arduino and IR LED based proximity sensor

You may also like:


  • What are the top development boards for AI and ML?

  • What are different types of industrial robots?

  • What is LoRa and LoRaWAN?

  • How does LoRa modulation enable long-range communication?

  • What is the role of embedded software in electric vehicles?

  • What are the components of robotic arms and industrial robots?

Filed Under: Arduino Projects, Electronic Projects, Sensors, Tutorials, Video

 

Next Article

← Previous Article
Next Article →

Questions related to this article?
👉Ask and discuss on Electro-Tech-Online.com and EDAboard.com forums.



Tell Us What You Think!! Cancel reply

You must be logged in to post a comment.

EE TECH TOOLBOX

“ee
Tech Toolbox: Internet of Things
Explore practical strategies for minimizing attack surfaces, managing memory efficiently, and securing firmware. Download now to ensure your IoT implementations remain secure, efficient, and future-ready.

EE Learning Center

EE Learning Center
“engineers
EXPAND YOUR KNOWLEDGE AND STAY CONNECTED
Get the latest info on technologies, tools and strategies for EE professionals.

HAVE A QUESTION?

Have a technical question about an article or other engineering questions? Check out our engineering forums EDABoard.com and Electro-Tech-Online.com where you can get those questions asked and answered by your peers!


RSS EDABOARD.com Discussions

  • Reducing "shoot-through" in offline Full Bridge SMPS?
  • High Side current sensing
  • How to simulate power electronics converter in PSpice?
  • Voltage mode pushpull is a nonsense SMPS?
  • Layout IRN reduction in Comparator

RSS Electro-Tech-Online.com Discussions

  • Back to the old BASIC days
  • Parts required for a personal project
  • PIC KIT 3 not able to program dsPIC
  • Failure of polypropylene motor-run capacitors
  • Siemens large industrial PLC parts

Featured – RPi Python Programming (27 Part)

  • RPi Python Programming 21: The SIM900A AT commands
  • RPi Python Programming 22: Calls & SMS using a SIM900A GSM-GPRS modem
  • RPi Python Programming 23: Interfacing a NEO-6MV2 GPS module with Raspberry Pi
  • RPi Python Programming 24: I2C explained
  • RPi Python Programming 25 – Synchronous serial communication in Raspberry Pi using I2C protocol
  • RPi Python Programming 26 – Interfacing ADXL345 accelerometer sensor with Raspberry Pi

Recent Articles

  • What is AWS IoT Core and when should you use it?
  • AC-DC power supply extends voltage range to 800 V DC
  • Infineon’s inductive sensor integrates coil system driver, signal conditioning circuits and DSP
  • Arm Cortex-M23 MCU delivers 87.5 µA/MHz active mode
  • STMicroelectronics releases automotive amplifiers with in-play open-load detection

EE ENGINEERING TRAINING DAYS

engineering

Submit a Guest Post

submit a guest post
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • Battery Power Tips
  • DesignFast
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • EV Engineering
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • Subscribe to our newsletter
  • About Us
  • Contact Us
  • Advertise

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy

Search Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe