Ultrasonic or IR Sensor: Which Should Your Project Use?
Quick answer
- Choose Ultrasonic: measure distance if you need to know how far.
- Choose Ultrasonic: robot car if your robot must not bump into things.
- Choose IR: line follower if your robot follows a track.
- Choose IR: something is there if you only need yes or no, up close.
How far? Ultrasonic. Is it there? IR. Black or white line? IR.
Side by side
Ultrasonic: measure distance
- Who it's for
- Beginners
- Level
- intermediate
- Cost
- Low
- Main parts
- Uno, HC-SR04, I2C LCD
- Wiring
- Easy
- Code
- About 34 to 46 lines
- It can
- Give centimetres, in any light
- It can't
- Hear soft or slanted things well
Ultrasonic: robot car
- Who it's for
- Intermediate
- Level
- intermediate
- Cost
- High
- Main parts
- Uno, HC-SR04, car chassis, L293D, LCD, battery
- Wiring
- Hard
- Code
- About 59 lines
- It can
- Stop and turn before a wall
- It can't
- Follow a line
IR: line follower
- Who it's for
- Intermediate
- Level
- intermediate
- Cost
- High
- Main parts
- Uno, 2 IR sensors, chassis, L298N or L293D, LCD, battery
- Wiring
- Hard
- Code
- About 27 lines
- It can
- Follow a dark line
- It can't
- Measure distance
IR: something is there
- Who it's for
- Intermediate
- Level
- intermediate
- Cost
- Medium
- Main parts
- Uno, IR sensor, LCD, pump or sorter
- Wiring
- Medium
- Code
- About 28 to 30 lines
- It can
- React to a hand or an object close by
- It can't
- Work well in bright sunlight or with black objects
Written from the parts lists and code in these tutorials. Cost is a rough guide to the parts they list, compared with each other; line counts are of the main program.

