This repository provides two hands-on MATLAB Live Scripts and starter Simulink models, designed to teach students how to model a traffic light as a state machine in Stateflow and Simulink. In the first set, the Live Script and accompanying starter Simulink model guides students through building a model of a traffic light only, demonstrating key Stateflow concepts. In the second set, the Live Script and accompanying starter model guide students through deploying the traffic light model on an Arduino board, using LEDs to represent traffic light bulbs. This interactive, hands-on activity provides students with an opportunity to practice embedded programming skills and code generation with MATLAB and Simulink.
Required MathWorks® Products (https://www.mathworks.com)
Requires MATLAB release R2025b or newer
Required Hardware for Arduino deployment
- Arduino Board (Uno or Mega)
- USB Type A to B cable (Arduino to computer connection)
- Small breadboard
- 3 220 Ohm resistoers
- 3 LEDs (ideally in traffic light colors)
- Connecting wires
- Open this repository in MATLAB Online, or clone and download this repository to your local machine and open in MATLAB.
- Install the Simulink Support Package for Arduino Hardware in MATLAB.
- Connect your Arduino board to your computer via USB.
- From the "Model Only" folder, open the "TrafficLight_Model_Instructions.mlx" Live Script to follow the step by step instructions.
- Modify and run the "traffic_start.slx" starter Simulink model.
- If needed, review the completed version of the model in "traffic.slx".
- From the "Implement Model Arduino" folder, open the "Traffic_Light_Arduino_Instructions.mlx" Live Script to follow the step by step instructions.
- Modify the "traffic_arduino_start.slx" starter Simulink model. Wire up the Arduino board to LEDs as instructed in the Live Script. Follow instructions to deploy the Simulink model on the Arduino board conneected to LEDs.
- If needed, review the completed version of the model in "traffic_arduino.slx".
The license is available in the License.txt file in this GitHub repository.
Copyright 2025 The MathWorks, Inc.