Autonomous 4-Wheel Robot Light Tracker - Arduino Mega 2560

Simulate and deploy a Run on Target Hardware Arduino algorithm that tracks light and detects bumps.
Updated 1 Sep 2016

View License

A sample model that implements light following and bump detection algorithms on a 4-wheel autonomous vehicle with an Arduino Mega 2560 onboard. The light following algorithm is based on two light sensors mounted in the front of the vehicle that when a difference is sensed, the vehicle turns towards the brighter side. Also implemented is that the vehicle drives faster when the light is dim (proxy for ‘far’), and slower when it is bright (proxy for ‘close’). Bump logic is done with left/right bump sensors, and the vehicle backs up and then turns away from the object it struck.
The model is created in a way to allow for simulation and code generation. Numerous test scenerios are implemented with a Signal Builder block to test aspects of algorithms prior to trying on the final platform.
External mode can be toggled to allow for monitoring of signals and tuning of parameters, and the model currently implements the back_time parameter as tunable when an object is struck.
The ZIP file includes the listing of hardware used, wiring schematics. It is encouraged to continue to expand on more complicated and robust algorithms, new sensors/actuators, etc.

For more information, please refer to:
- Simulink Targets:
- Arduino Support from Simulink:
- Support Package for Arduino Mega:

Facecast was on June 7, recorded video can be located here - (Arduino Support from Simulink video)

Cite As

Dan Lluch (2024). Autonomous 4-Wheel Robot Light Tracker - Arduino Mega 2560 (, MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2012a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Inspired by: Simulink Support Package for Arduino Hardware

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes

Updated license

adding Support Packages for Arduino as acknowledgements on this entry.

added link to recorded facecast in description

- updated picture for file view of model, and included Simulink Web View files

update ZIP file