Complete Build Guide: Ultrasonic Radar + Line Following
This project combines two cutting-edge robotics systems into one intelligent autonomous platform. The robot features:
HC-SR04 ultrasonic sensor mounted on servo motor performs continuous environmental scanning with radar-like capability.
Dual IR sensors track black/white lines with adaptive speed control and smooth curve navigation.
Arduino Uno processes multi-sensor data in real-time and executes complex behavioral algorithms.
Three independent DC motors with L298N driver provide smooth, synchronized motion control.
| # | Component Name | Quantity | Specification | Unit Price (BDT) | Total (BDT) | Purpose |
|---|---|---|---|---|---|---|
| 1 | Arduino Uno Rev3 | 1 | ATmega328P, 16MHz Clock | ৳900 | ৳900 | Main Controller/Microcontroller |
| 2 | HC-SR04 Ultrasonic Sensor | 1 | 5V, 2cm-400cm Range | ৳120 | ৳120 | Obstacle Detection & Distance Measurement |
| 3 | Infrared Line Sensor Module | 2 | 5V, Analog Output, Adjustable | ৳150 each | ৳300 | Left & Right Line Detection |
| 4 | SG90 Servo Motor | 1 | 5V, 0-180°, 10g Torque | ৳250 | ৳250 | Rotate Ultrasonic Sensor for 360° Scan |
| 5 | DC Gear Motor (Yellow/Black) | 2 | 6V, 200RPM, Metal Gears, 0.5kg Torque | ৳280 each | ৳560 | Left & Right Wheel Drive |
| 6 | L298N Motor Driver Module | 1 | Dual Channel, 2A Max, PWM Speed Control | ৳320 | ৳320 | Motor Control & Direction Management |
| 7 | 7.4V Li-ion Battery Pack | 1 | 2x18650 Lithium Cells, 1500mAh, Protected | ৳750 | ৳750 | Main Power Supply for Motors |
| 8 | Battery Connector & Holder | 1 | JST XT60 / Tamiya Connector with Wires | ৳180 | ৳180 | Safe Battery Connection & Hot Swap |
| 9 | Slide On/Off Power Switch | 1 | 5A Capacity, 2-Pin | ৳50 | ৳50 | Safe Power Management (visible in diagram) |
| 10 | Robot Chassis (3WD/4WD) | 1 | 170x140mm, Aluminum Frame, Wheels Included | ৳700 | ৳700 | Robot Body & Structural Support |
| 11 | Breadboard (830 point) | 2 | Full Size, Self-Adhesive Back | ৳150 each | ৳300 | Prototyping & Circuit Layout (as shown) |
| 12 | Jumper Wire Set | 1 set | Male-Male & Male-Female, 20+ pieces, Assorted Colors | ৳200 | ৳200 | Component Interconnection |
| 13 | USB Type-A to B Cable | 1 | 2.0 Standard, Arduino Compatible | ৳120 | ৳120 | Arduino Programming & Serial Communication |
| 14 | Servo Motor Bracket | 1 | Metal Mount, Ultrasonic Sensor Adapter | ৳80 | ৳80 | Mount Servo & HC-SR04 Together |
| 15 | Motor Wheel Coupling | 2 | Motor Shaft to Wheel Adapter | ৳40 each | ৳80 | Connect Motors to Wheels |
| 16 | Capacitors Assortment | 1 set | 100μF, 10μF (Ceramic & Electrolytic) | ৳150 | ৳150 | Noise Filtering & Power Stabilization |
| 17 | Resistors Assortment | 1 set | Various values (1k, 10k, 220Ω, etc.) | ৳100 | ৳100 | Sensor Calibration & Safety Protection |
| 18 | Super Glue & Hot Glue Gun | 1 set | Multi-purpose Adhesive + Glue Sticks | ৳200 | ৳200 | Assembly & Component Mounting |
| 19 | Heat Shrink Tubing Set | 1 set | Various diameters, Assorted Colors | ৳150 | ৳150 | Wire Protection & Professional Finish |
| 20 | Workstation Mat & Tools | 1 set | Soldering Mat, Cutting Mat, Mini Tools | ৳400 | ৳400 | Safe Assembly & Soldering Workspace |
Complete System (All Components Included)
Prices accurate for Bangladesh market (February 2026) • May vary by supplier & location • Includes all necessary components for assembly, testing, and programming
1. Capacitors: 100μF across motor power lines (prevents voltage spikes)
2. Heat Shrink Tubing: Professional finish and wire safety
3. Servo Bracket: To mount ultrasonic sensor on servo motor
4. Motor Couplings: Connect motor shafts to wheels properly
These components were added because they're essential for reliable operation and longevity of the robot.
LEFT SENSOR:
RIGHT SENSOR:
POWER CONNECTIONS:
MOTOR 1 CONTROL (Left Wheel):
MOTOR 2 CONTROL (Right Wheel):
Attach the two 200RPM gear motors to the front left and right sides of the chassis using metal L-brackets and M3 screws. Ensure motor shafts point downward and rotate freely without obstruction.
⚠️ Alignment critical: Motors must be parallel for straight-line movement.
Mount the wheels onto the motor shafts using the coupling adapters. Ensure wheels are centered and balanced. Spin manually to verify smooth rotation with no wobble.
✓ Check: Wheels should spin freely at least 10 revolutions without stopping.
Mount the battery holder on the chassis bottom using double-sided foam tape or Velcro strips. Position centrally to maintain balance. Route battery connector wires along the chassis edge toward the power switch.
⚠️ Safety: Install ON/OFF slide switch in the battery positive line.
Use Velcro strips to secure Arduino Uno and L298N motor driver on the chassis top. Arduino should be centered front; L298N placed near the motors to minimize wire lengths. This arrangement allows easy access to USB port for programming.
💡 Tip: Leave 2-3cm spacing between boards for airflow and component access.
Install the two IR line sensors on the chassis bottom front, 4-5cm apart. Mount them exactly 1.5-2cm above the ground using flexible brackets. The sensors must face downward to detect the black/white line beneath the robot.
⚠️ Critical: Height adjustment determines detection accuracy. Test before final mounting.
Secure SG90 servo motor on the chassis top-center using a metal bracket. Attach the HC-SR04 ultrasonic sensor to the servo motor arm using the sensor bracket adapter. This creates a rotating radar head that scans 180° (or full 360° with modifications).
💡 Tip: Secure wires along servo arm to prevent tangling during rotation.
Use breadboards to organize power distribution. Connect the positive rail to battery + (through switch), negative rail to battery GND. This creates clean power distribution for all sensors. Use 100μF capacitors across motor power inputs for noise filtering.
⚠️ Critical: Ensure common ground between battery and Arduino (use GND jumper wire).
Wire the ultrasonic sensor following the pin map: VCC→5V, GND→GND, TRIG→Pin7, ECHO→Pin8. Use color-coded jumper wires: Red for power, Black for ground, Yellow for TRIG, Blue for ECHO. Double-check all connections before powering.
✓ Test: Upload test sketch, verify distance readings in Serial Monitor.
Left sensor: VCC→5V, GND→GND, OUT→A0. Right sensor: VCC→5V, GND→GND, OUT→A1. Keep sensor wires together and away from motor wires to minimize noise interference. Use shielded cable if possible.
✓ Test: Place on white/black surfaces, observe analog values changing (should differ by 100+ points).
Servo has three wires: Brown (GND)→Arduino GND, Red (VCC)→Arduino 5V, Orange (Signal)→Arduino Pin 9 (PWM). If servo drawing too much current, use separate 5V power supply for servo only. Connect 100μF capacitor across servo power pins.
⚠️ Warning: 200mA servo current + sensors can exceed Arduino 5V output. Consider external 5V supply.
Motor 1: IN1→Pin2, IN2→Pin3, ENA→Pin10. Motor 2: IN3→Pin4, IN4→Pin5, ENB→Pin11. Connect +12V to battery+ and GND to battery GND (MUST be same as Arduino GND). OUT terminals connect to motor leads. Use solder for reliable connections.
⚠️ Critical: Motor polarity determines rotation direction. Test direction and swap wires if needed.
Before powering on: Use multimeter to verify battery voltage (7-8V), check for short circuits (resistance between ±), confirm common ground connections. Power on without motors connected first. Check LED lights on Arduino and L298N. Then test motors individually.
✓ Success: Arduino powers up, no sparks, no burn smell, motors can be controlled separately.
Action: Connect battery. Arduino LED should light. L298N indicator LEDs should turn on.
Expected: No sparks, no burning smell, no excessive heat.
If problem: Disconnect immediately. Check for short circuits using multimeter.
Action: Hold robot in air. Upload motor test code. Activate Motor 1 forward.
Expected: Left wheel spins clockwise (adjust code if counter-clockwise).
Adjustment: If reverse, swap motor terminal connections or flip HIGH/LOW logic in code.
Action: Gradually increase PWM value (0→255) using analogWrite.
Expected: Motor speed increases smoothly. No grinding or jerking noise.
Measure: Motor stalls at PWM < 100. Smooth operation at PWM 150-255.
Action: Upload servo test code. Servo should sweep 0°→180°→0°.
Expected: Smooth rotation without jerking or grinding. HC-SR04 rotates with servo.
Measure: Each sweep takes ~3-4 seconds. Current draw <200mA.
Action: Open Serial Monitor (9600 baud). Move hand in front of sensor.
Expected: Distance readings change (0-400cm range). No negative values.
Verify: 5cm distance shows ~50 on display. 30cm distance shows ~300. Linear relationship.
Action: Read analog values. Place on white paper. Note value (e.g., 200). Place on black line. Note value (e.g., 800).
Expected: Minimum 300-point difference between white/black. Adjust potentiometers if gap <200.
Calibration: Set threshold at midpoint: (200+800)/2 = 500 in code.
Setup: Place robot on table. No obstacles. Upload integrated code.
Expected: Robot moves forward in straight line. Speed consistent.
Measure: Travel 1 meter in ~5-8 seconds at PWM 200. Adjust motor speeds if drifting left/right.
Setup: Create test track with black tape on white paper (30-50cm width). Curves optional.
Expected: Robot follows line smoothly. Corrects drift automatically. Completes track without falling off.
Metrics: Time to complete track. Number of corrections. Success rate (>95%).
Setup: Robot moving forward. Place hand/object ~30cm ahead.
Expected: Robot stops before obstacle. Servo scans left/right. Backs up and turns.
Measure: Stopping distance < 10cm. Detection reliability >90%.
Action: Upload code with Serial output. Run Processing/Python script to display radar graphics.
Expected: Green radar arc shows obstacles as red dots. Real-time updates as servo scans.
Output: Visual confirmation of ultrasonic sensor accuracy and scanning pattern.
Test: Robot follows line for 5-10 minutes continuously.
Monitor: Battery voltage (should stay >6.5V). Temperature of L298N (should stay <50°C). Motor behavior (no stalling).
Success: Completes multiple laps without requiring intervention.
Setup: Multi-room house or outdoor area with obstacles, ramps, corners.
Test: Robot navigates independently, avoids obstacles, recovers from line loss.
Success Criteria: Completes path without external help. Adapts to changing light conditions.
Date: __/__/____ Test Location: ________________
COMPONENT TESTS:
✓ Motors: L____RPM R____RPM (Rotation direction: OK/SWAP)
✓ Servo: Min___° Max___° Speed: __°/sec
✓ Ultrasonic: Min___cm Max___cm Accuracy: ±__cm
✓ Line Sensors: White-Value____ Black-Value____ Difference____
INTEGRATION TESTS:
✓ Forward Motion: Time for 1m: ____ sec (Target: 5-8 sec)
✓ Line Following: Success Rate: ___% Oscillation: None/Slight/Heavy
✓ Obstacle Avoidance: Detection Distance: __cm Recovery: OK/Fail
✓ Battery Life: Runtime: ____ min Final Voltage: __ V
ISSUES FOUND & FIXES:
1. _________________________________ → Fixed by: ______________
2. _________________________________ → Fixed by: ______________
3. _________________________________ → Fixed by: ______________
NEXT STEPS:
□ PID Tuning needed for line following
□ Servo power supply upgrade required
□ Motor speed synchronization adjustment
□ Sensor calibration optimization
□ Code optimization for battery life
This complete sketch handles all robot functions: motor control, sensor reading, obstacle detection, and line following.
1. NewPing (for ultrasonic sensor) - Install via Arduino IDE Library Manager
2. Servo (built-in) - Already included with Arduino IDE