an engineering journalShivam Hegadi
workingPCB DesignRoboticsElectronicsProgramming

Line-Following Robot with a Custom PCB

A small two-wheel robot that follows a line using IR sensors, built around a custom PCB instead of a breadboard and jumper wires.

started Jan 10, 2026updated Feb 20, 2026
Line-Following Robot with a Custom PCB

Links

Components

  • ATmega328P (bare chip, programmed with an Arduino as ISP)
  • 5x TCRT5000 IR reflectance sensors
  • TB6612FNG motor driver
  • 2x N20 gear motors
  • 18650 battery with a small protection board
  • 16MHz crystal, 22pF caps

Files

What I was trying to make

I'd built a line follower before on a breadboard with an Arduino Uno sitting on top, and it worked but it was a mess of wires that fell apart if I looked at it wrong. I wanted a version where the electronics were an actual board, both because it would be more reliable and because I wanted to learn PCB design on something small before trying it on anything more complicated.

Design process

This was my first real PCB, done in KiCad. I started by laying out the schematic exactly like my breadboard version: ATmega328P, five IR sensors in a row facing down, a motor driver, and a spot for the battery connector. Getting comfortable with KiCad's schematic editor took a weekend by itself, mostly because I kept trying to do things the Eagle way from a tutorial I'd watched instead of the KiCad way.

The board outline is shaped to match the 3D printed chassis, with the sensor row at the front edge angled down slightly so the sensors sit closer to the ground than a flat board would allow.

Electronics and components

Five IR sensors were probably overkill for a line follower this simple, three would have worked, but I wanted extra margin for sharper corners. The ATmega328P runs at 16MHz off an external crystal since I wanted the option to reflash it without needing a bootloader once things were working.

Build process

I ordered the first board run through a standard fab, five boards for cheap since ordering one board isn't really cheaper than ordering five. Soldering was mostly hand soldering with a fine tip iron, the ATmega328P and TB6612FNG are both in packages just large enough to hand solder without hot air, which was intentional in the design since I didn't have hot air equipment at the time.

Problems and failed attempts

The first board revision had a mistake in the crystal load capacitor footprint, I'd used the wrong capacitance value from a datasheet I skimmed too quickly, and the oscillator wouldn't start reliably. I ended up bodge-wiring different capacitors onto that first board to confirm the fix before ordering a corrected revision.

I also placed the ISP programming header too close to the battery connector on the first revision, which meant I had to unplug the battery every time I wanted to reflash the chip. Small thing, but annoying enough that I fixed it on rev 2.

What changed between versions

  • rev 1: wrong crystal load capacitors, oscillator unreliable, worked around with bodge wires
  • rev 1: ISP header too close to battery connector, awkward to reflash
  • rev 2: corrected capacitor footprint, moved ISP header to the opposite edge of the board
  • rev 2 (current): added a status LED, which sounds minor but made debugging sensor readings much faster since I could blink out simple codes instead of needing serial output

Final result

Rev 2 works reliably on the test track I built out of black tape on cardboard. It follows curves fine and handles a sharp 90 degree corner if I slow the base speed down. Straight-line speed is limited by how fast the sensor read loop can run, which is something I'd look into optimizing if I built a faster version.

KiCadline followerATmega328PIR sensorsPCB