Enhancing LEGO SPIKE Prime Line Follower With C: Speed & Stability Comparison
by sunata-s0907 in Circuits > Robots
239 Views, 1 Favorites, 0 Comments
Enhancing LEGO SPIKE Prime Line Follower With C: Speed & Stability Comparison

I tried controlling the LEGO SPIKE Prime using C language to evaluate its usability, processing speed, and potential for robot competitions. To test its performance, I implemented a Line Follower algorithm.
Two Key Experiments
- Comparing the Line Follower performance using SPIKE App’s Word Blocks vs. C language
- Maximizing Line Follower speed using C language with PD control
Supplies
1 PC with Windows 10 or 11 operating system.
Comparing SPIKE App Word Blocks Vs. C Language

I created a Line Follower program using both SPIKE App (Word Blocks) and C language, keeping the control logic the same.
The C language version provided more stable driving performance compared to the SPIKE App.
Below is the source code for both versions:
Improving Line Follower Speed With C

I tested how much I could increase the Line Follower speed using C language.
Without extensive tuning, I achieved speeds of approximately 820 deg/s.
Adding a second color sensor or optimizing the robot assembly could further improve stability.
Development Environment & Resources
For C programming, I used this development environment.
If you want to try it, there is a beginner-friendly tutorial available, including a trial (as of February 2025).
🔹 Download the program used in this article: [Download Link]
Future Tests & Robot Competition Applications
I plan to conduct further tests on the usefulness of C language for robot competitions and will share my findings in upcoming articles. Stay tuned!
To See More
If you want to see a demonstration of SPIKE-RT in action, please refer to the following.
・Introducing SPIKE-RT: the C Language Software Platform for LEGO SPIKE Prime
・Comparing LEGO SPIKE Prime Programming : Which is Best for Robotics Competitions? - 1
・Comparing LEGO SPIKE Prime Programming : Which is Best for Robotics Competitions? - 2
・Comparing LEGO SPIKE Prime Programming : Which is Best for Robotics Competitions? - 3
・Comparing LEGO SPIKE Prime Programming : Which is Best for Robotics Competitions? - 4