Skip to the content
2 layers54.9 × 68.3 mmShield teensy, the printed circuit board in 3D

An autonomous 2line-following robot built on the Teensy microcontroller with advanced vision-based steering using Pixy2 camera. Designed for precision line tracking with intersection detection and obstacle avoidance.

Size
54.9 × 68.3 mm
Copper layers
2
Thickness
1.6 mm
Parts
16
Nets
29
Pads
71
Tracks, vias
136, 0
Pours
1
Routed
Yes
KiCad
KiCad 9.0 (file 20241229)
Created
12 Feb 2026
Updated
5 Jun 2026

Overview

Shield teensy is an open-source printed circuit board by Ayoub-Ben-Yedder, from the Ayoub-Ben-Yedder/NXP repository on GitHub. It is a 2-layer board of 54.9 × 68.3 mm with 16 parts on 29 nets, routed with 136 tracks and 0 vias.

Its parts include 9 connectors, 4 resistors, 2 diodes and 1 IC.

README

README.md

NXP Line Following Robot

An autonomous 2line-following robot built on the Teensy microcontroller with advanced vision-based steering using Pixy2 camera. Designed for precision line tracking with intersection detection and obstacle avoidance.

Project Overview

This project implements a sophisticated autonomous robot controller that:

  • Follows lines detected by Pixy2 camera vision system
  • Intelligently handles intersections and corners
  • Detects and responds to obstacles using ultrasonic distance sensor
  • Recognizes finish line patterns and stops safely
  • Applies advanced steering algorithms for smooth, stable tracking

Hardware Components

Microcontroller

  • Teensy (primary controller)

Sensors

  • Pixy2 Camera - Line detection and vector tracking
  • HC-SR04 Ultrasonic Sensor - Distance measurement for obstacle detection
    • TRIG: Pin 14
    • ECHO: Pin 15

Actuators

  • Servo Motor - Steering control (Pin 23)
  • DC Motors (x2) - Left and right propulsion
    • Left Motor: PWM (Pin 8), Direction (Pins 6-7)
    • Right Motor: PWM (Pin 18), Direction (Pins 20-19)

Additional

  • LED Indicator - Pin 22
  • Logic Level Converters - For Pixy2 communication

Electronics & PCB Design

The electronics are primarily a Teensy 4.0 shield custom designed with KiCAD. The shield integrates all necessary components (motor drivers, sensor interfaces, power distribution) onto a single PCB that stacks directly onto the Teensy 4.0 microcontroller, providing a clean and compact solution for the robot.

Schematics

PCB Schematic

PCB Layout

PCB Footprint

3D View

PCB 3D View

All design files are located in the electronics/ directory.

Mechanical Design

The mechanical design for this robot was adapted from the NXP CUP FINALS repository. This includes the chassis, motor mounts, sensor brackets, and other structural components required for the robot assembly.

Pin Configuration

text
PWM1 = 8      (Left motor speed)
IN1 = 6       (Left motor direction)
IN2 = 7       (Left motor direction)
PWM2 = 18     (Right motor speed)
IN3 = 20      (Right motor direction)
IN4 = 19      (Right motor direction)

LED = 22
ECHO = 15     (Ultrasonic echo)
TRIG = 14     (Ultrasonic trigger)
SERVO_PIN = 23 (Steering servo)

Key Features

1. Advanced Line Following

  • Processes up to 20 line vectors from Pixy2 camera
  • Weighted steering algorithm that considers vector angles and lengths
  • Minimum vector length filtering to ignore noise
  • Soft steering limits to prevent oscillation

2. Intersection Detection

  • Identifies corner types: top-left, top-right, bottom-left, bottom-right
  • Analyzes angle between consecutive vectors (target ~90°)
  • Applies directional corrections based on intersection position
  • More aggressive steering during turns for accuracy

3. Steering Control

  • Center Angle: 135° (neutral position)
  • Steering Range: 90° (MAX_LEFT) to 180° (MAX_RIGHT)
  • Deadband: ±15° around forward angle to filter horizontal noise
  • Soft Limiting: Reduces extreme steering angles to prevent oscillation
  • Center Bias: Gently pulls steering toward center for stability
  • Delay System: Smooths steering inputs over 2 cycles

4. Obstacle Detection & Avoidance

  • Continuously monitors distance via ultrasonic sensor
  • Filtered readings (average of 3 samples) for stability
  • Stop Distance: 15 cm - triggers reverse and stop
  • Timeout handling for cases where no object is detected

5. Finish Line Recognition

  • Detects horizontal line patterns (angle ≤ 15° from horizontal)
  • Requires 2+ horizontal vectors within 5 pixels of each other
  • Activation delay (10 seconds) to avoid false positives at start
  • Triggers acceleration boost and obstacle check

Build & Upload

This project uses PlatformIO for build and upload management.

Prerequisites

  • VSCode with PlatformIO extension
  • Arduino IDE libraries (Pixy2, Servo)

Building

bash
pio run

Uploading to Device

bash
pio run --target upload

Monitoring Serial Output

bash
pio device monitor

Algorithm Flow

Algorithm Flowchart

  1. Initialization

    • Configure PWM frequencies (20 kHz)
    • Initialize pins and servo to center
    • Initialize Pixy2 in line-tracking mode
    • Record start time for finish line delay
  2. Main Loop (runNXP)

    • Read Pixy2 vectors
    • Filter vectors by length, angle, and position
    • Identify horizontal vectors for finish line detection
    • Sort vectors by length (longest first)
    • Compute steering angle based on vector count:
      • 0 vectors: Maintain last angle
      • 1 vector: Standard line following
      • 2+ vectors: Check for intersection; if ~90° angle detected, apply intersection steering
    • Apply steering corrections (center bias, soft limits)
    • Implement steering delay system for smooth transitions
    • Check finish line and obstacle avoidance conditions
  3. Distance Monitoring

    • Triggered after finish line detection
    • Backs up and stops if obstacle within STOP_DISTANCE

Constants & Tuning Parameters

cpp
MAX_VECTORS = 20          // Max vectors to process per frame
MIN_VECTOR_LENGTH = 10    // Minimum pixels for valid vector

CENTRE_ANGLE = 135        // Neutral steering position
MAX_RIGHT = 180           // Maximum right turn
MAX_LEFT = 90             // Maximum left turn

STOP_DISTANCE = 15        // cm - obstacle stop threshold

PIXY_FORWARD_ANGLE = 270  // Expected angle for straight tracking
PIXY_STEER_DEADBAND = 15  // Angle tolerance for horizontal detection
STEERING_DELAY_CYCLES = 2 // Smoothing delay for steering changes
STEERING_QUEUE_THRESHOLD = 2.0   // Threshold to queue steering change
STEERING_CENTER_BIAS = 5.0       // Pull toward center amount
STEERING_SOFT_LIMIT_START = 11   // When to start softening
STEERING_SOFT_LIMIT_FACTOR = 0.5 // Softening strength
CROSS_CORRECTION_ANGLE = 15      // Intersection correction

Performance Notes

  • Steering Response: Balanced between responsiveness and stability
  • Motor Speed: Default 150 units for forward motion, 130 for finish line
  • Reverse Speed: 100 units for obstacle avoidance
  • Frame Rate: Dependent on Pixy2 refresh rate (typical ~50 FPS)

Troubleshooting

IssueSolution
Robot doesn't follow lineCheck Pixy2 is in "line" mode; verify camera focus; check lighting
Erratic steeringIncrease STEERING_DELAY_CYCLES; adjust STEERING_CENTER_BIAS
Misses turnsLower angle threshold in intersection detection; increase CROSS_CORRECTION_ANGLE
OscillatesEnable soft limiting; increase STEERING_SOFT_LIMIT_FACTOR
Overshoots finish lineReduce finish line acceleration value; increase STOP_DISTANCE

Project Structure

text
NXP/
├── src/
│   ├── main.cpp          # Main robot controller
│   └── README.md         # This file
├── include/
├── lib/
├── platformio.ini        # Build configuration
└── test/

Future Enhancements

  • PID control for smoother steering response
  • Dynamic speed adjustment based on turn sharpness
  • Gyro integration for improved angle estimation
  • Adaptive threshold tuning based on lighting conditions
  • Multi-point finish line detection for reliability

Last Updated: June 2026
Board: Teensy
Camera: Pixy2
Competition: NXP

Parts

16
QtyValueFootprintReferences
2LEDLED_THT:LED_D3.0mmD1, D2
2RResistor_THT:R_Axial_DIN0207_L6.3mm_D2.5mm_P7.62mm_HorizontalR1, R2
2RResistor_THT:R_Axial_DIN0207_L6.3mm_D2.5mm_P2.54mm_VerticalR3, R4
2motor in 1Connector_JST:JST_XH_B3B-XH-A_1x03_P2.50mm_VerticalJ3, J4
1DEV-15583DEV-15583:MODULE_DEV-15583U1
1Encoder 1Connector_JST:JST_XH_B4B-XH-A_1x04_P2.50mm_VerticalJ5
1Encoder 2Connector_JST:JST_XH_B4B-XH-A_1x04_P2.50mm_VerticalJ6
1I2C connConnector_JST:JST_XH_B4B-XH-A_1x04_P2.50mm_VerticalJ8
1SPI connConnector_JST:JST_XH_B4B-XH-A_1x04_P2.50mm_VerticalJ7
1Screw_Terminal_01x02TerminalBlock_MetzConnect:TerminalBlock_MetzConnect_Type055_RT01502HDWU_1x02_P5.00mm_HorizontalJ2
1Servo MotorConnector_JST:JST_XH_B3B-XH-A_1x03_P2.50mm_VerticalJ10
1Ultrason connConnector_JST:JST_XH_B4B-XH-A_1x04_P2.50mm_VerticalJ9

Similar boards

  • 2 layers140.5 × 30 mmType e, the printed circuit board in 3D

    Type e

    google/mozc-devices

    Circuit diagrams and firmware source code for Gboard DIY keyboards

    16 parts3kApache-2.0
  • 2 layers41.4 × 14.5 mmU2f zero, the printed circuit board in 3D

    U2f zero

    conorpp/u2f-zero

    U2F USB token optimized for physical security, affordability, and style

    16 parts2.4k
  • 2 layers122 × 37 mmV0-UmbilicalBoard, the printed circuit board in 3D

    V0-UmbilicalBoard

    VoronDesign/Voron-Hardware

    Cool Hardware designed by the Voron Design group

    16 parts1.1kGPL-3.0
  • 2 layers152 × 57.6 mmVideoslotadapter, the printed circuit board in 3D

    Videoslotadapter

    hoglet67/RGBtoHDMI

    Bare-metal Raspberry Pi project that provides pixel-perfect sampling of Retro Computer RGB/YUV video and conversion to HDMI

    16 parts1kGPL-3.0
  • 2 layers36 × 63.4 mmSmart ringfinal layout, the printed circuit board in 3D

    Smart ringfinal layout

    hackclub/OnBoard

    💡 Join 1,000 teenagers and make your first PCB with a $100 grant!

    16 parts915
  • 2 layers60 × 40 mmHASwitchPlate, the printed circuit board in 3D

    HASwitchPlate

    aderusha/HASwitchPlate

    LCD touchscreen for Home Automation

    16 parts738MIT
  • 2 layers21.1 × 26.9 mmDemo, the printed circuit board in 3D

    Demo

    easyw/kicadStepUpMod

    kicadStepUp: ECAD to MCAD FreeCAD WorkBench

    16 parts704

Questions

How big is the Shield teensy PCB?

It measures 54.9 × 68.3 mm and has 2 copper layers, 1.6 mm thick.

What parts does the Shield teensy use?

16 parts. The full list of its parts is on this page, with links to each part's symbol and footprint where PCBKit's library has them.

Where can I download the Shield teensy KiCad files?

From the Ayoub-Ben-Yedder/NXP repository on GitHub, at the commit this page was made from: the board is electronics/shield teensy.kicad_pcb and its schematic electronics/shield teensy.kicad_sch. PCBKit opens the board in the browser, with nothing to install.

Can I use the Shield teensy design in my own project?

Its repository states no licence, so its author keeps all rights: ask Ayoub-Ben-Yedder before reusing the design.