📖 Lesson 4.2 – IR Sensor Circuit
🎯 Learning Objectives
After completing this lesson, students will be able to:
✅ Connect an IR Obstacle Sensor with Arduino UNO
✅ Understand sensor wiring
✅ Read sensor output using Arduino
✅ Display detection status on Serial Monitor
✅ Test object detection
✅ Verify proper sensor operation
1. Introduction
In the previous lesson, we learned:
- What an IR Sensor is
- How infrared reflection works
- Parts of an IR Sensor Module
- Applications of IR Sensors
Now it is time to connect the sensor with Arduino UNO and observe how it detects obstacles.
This lesson forms the foundation for:
- Obstacle Detection Systems
- Obstacle Avoiding Robots
- Smart Dustbins
- Automatic Water Dispensers
2. Project Overview
The system works as:
Obstacle
↓
IR Sensor
↓
Arduino UNO
↓
Serial Monitor
When an object comes in front of the sensor, Arduino will detect it and display a message.
3. Components Required
| Component | Quantity |
|---|---|
| Arduino UNO | 1 |
| IR Obstacle Sensor Module | 1 |
| USB Cable | 1 |
| Jumper Wires | 3 |
| Computer/Laptop | 1 |
4. Understanding the IR Sensor Pins
Most IR obstacle sensors have three pins:
| Pin | Function |
|---|---|
| VCC | Power Supply |
| GND | Ground |
| OUT | Digital Output |
5. Arduino Connections
| IR Sensor | Arduino UNO |
|---|---|
| VCC | 5V |
| GND | GND |
| OUT | D2 |
Circuit Diagram
IR Sensor Module Arduino UNO
VCC -----------> 5V
GND -----------> GND
OUT -----------> D2
6. Why Use Digital Pin D2?
The IR sensor provides:
HIGH
or
LOW
output.
Therefore we use:
digitalRead()
instead of:
analogRead()
Digital Pin D2 reads these signals easily.
7. Understanding Sensor Output
Most IR modules work as:
| Condition | Output |
|---|---|
| No Obstacle | HIGH |
| Obstacle Detected | LOW |
This may vary slightly depending on the sensor module.
Example
No object present:
HIGH
Arduino interprets:
No Obstacle
Object detected:
LOW
Arduino interprets:
Obstacle Detected
8. Arduino Program
int sensorPin = 2;
int sensorValue;
void setup()
{
pinMode(sensorPin, INPUT);
Serial.begin(9600);
}
void loop()
{
sensorValue = digitalRead(sensorPin);
Serial.println(sensorValue);
delay(200);
}
9. Program Explanation
Define Sensor Pin
int sensorPin = 2;
Stores the sensor pin number.
Configure Input Pin
pinMode(sensorPin, INPUT);
Sets D2 as an input pin.
Read Sensor Output
sensorValue = digitalRead(sensorPin);
Reads HIGH or LOW from the sensor.
Display Value
Serial.println(sensorValue);
Shows the reading on Serial Monitor.
10. Uploading the Program
Step 1
Connect Arduino UNO.
Step 2
Open Arduino IDE.
Step 3
Select:
Tools → Board → Arduino UNO
Step 4
Select Correct COM Port.
Step 5
Upload Program.
Step 6
Open Serial Monitor.
Step 7
Set Baud Rate:
9600
11. Testing the Sensor
Test 1 – No Obstacle
Keep sensor facing open space.
Serial Monitor:
1
1
1
1
Meaning:
HIGH
No obstacle detected.
Test 2 – Hand Detection
Place your hand in front of the sensor.
Serial Monitor:
0
0
0
0
Meaning:
LOW
Obstacle detected.
12. Improved Program
Instead of displaying 0 and 1:
int sensorPin = 2;
void setup()
{
pinMode(sensorPin, INPUT);
Serial.begin(9600);
}
void loop()
{
if(digitalRead(sensorPin) == LOW)
{
Serial.println("Obstacle Detected");
}
else
{
Serial.println("No Obstacle");
}
delay(300);
}
Output
No Object
No Obstacle
Object Present
Obstacle Detected
13. Testing Different Objects
Try detecting:
Hand
Notebook
Mobile Phone
White Paper
Black Object
Observe detection performance.
14. Adjusting Sensor Sensitivity
Use the blue potentiometer.
Clockwise
Increase detection range.
Anti-Clockwise
Decrease detection range.
Test until stable detection is achieved.
15. Observation Table
| Object | Detected? |
|---|---|
| Hand | Yes / No |
| Mobile | Yes / No |
| Notebook | Yes / No |
| White Paper | Yes / No |
| Black Object | Yes / No |
16. Real-World Applications
This same circuit is used in:
Obstacle Avoiding Robots
Smart Dustbins
Automatic Water Dispensers
Industrial Object Counters
Automatic Doors
Conveyor Systems
17. Common Beginner Mistakes
Mistake 1
Connecting OUT to the wrong pin.
Correct:
OUT → D2
Mistake 2
Using:
analogRead()
instead of:
digitalRead()
Mistake 3
Testing under direct sunlight.
IR performance may reduce.
Mistake 4
Ignoring sensitivity adjustment.
18. Troubleshooting
No Output
Check:
- Power Supply
- Wiring
- COM Port
Always Detecting Obstacle
Check:
- Potentiometer Adjustment
- Sensor Placement
Never Detecting Obstacle
Check:
- Wiring
- Detection Range
- Object Distance
Unstable Detection
Check:
- Loose Wires
- Strong Sunlight
📊 Summary
In this lesson, we learned:
✅ IR Sensor Wiring
✅ Arduino Connection
✅ Digital Input Reading
✅ Serial Monitor Output
✅ Obstacle Detection Testing
✅ Sensor Calibration
The IR sensor can now successfully detect nearby objects and communicate that information to Arduino.
📖 Key Terms
Digital Output
HIGH or LOW signal from the sensor.
Obstacle Detection
Detecting nearby objects without contact.
Calibration
Adjusting sensor sensitivity.
Reflection
IR light bouncing back from an object.
Digital Input
Arduino reading HIGH or LOW signals.
🎯 Quiz
1. Which Arduino pin is used in this lesson?
A. A0
B. D13
C. D2 ✅
D. D8
2. Which function reads the IR sensor output?
A. analogRead()
B. digitalRead() ✅
C. digitalWrite()
D. Serial.read()
3. What output is usually generated when an obstacle is detected?
A. HIGH
B. LOW ✅
C. 1023
D. Analog Signal
4. Which pin of the sensor connects to Arduino 5V?
A. GND
B. OUT
C. VCC ✅
D. D2
5. Why is calibration important?
A. To upload code
B. To improve detection performance ✅
C. To increase memory
D. To reduce voltage
🏠 Assignment
Task 1
Connect the IR sensor module and verify obstacle detection.
Task 2
Display “Obstacle Detected” and “No Obstacle” on Serial Monitor.
Task 3
Test the sensor with five different objects.
Task 4
Adjust the potentiometer and observe detection range changes.
Task 5
Create an observation table showing object detection results.