Traffic Signal Lab teaching notes
For middle and high school computer science and engineering teachers. Students program the light at one intersection in Blocks or Python, and a scoreboard grades it the way a traffic engineer would.
Using this with a class? Make a free class and add your students yourself: each gets a username and password, with no email or Google account needed. Or give them one join code. Using Google Classroom? Post the link there; with a free class, the link also puts each student in your class, so you see their work. mytekDev is also available from the Google Workspace Marketplace, so your school's Google admin can install it for everyone.A first lesson: Open it on the projector at Level 1 and let it run for a minute. Ask the class what is wrong: Main Street backs up while Oak's green runs on with hardly anyone on it. Ask what one number they would change. Then change Oak's 30 to 15 in Blocks, come back to the intersection, set it to 16x and watch the letter go from D to C.
Set up a free class Share to Google Classroom- About these notes
- A first period
- The five levels
- What students get wrong, and where the app answers it
- What the app simplifies, on purpose
- The timing sheet students hand in
- Setting it up for a class
- Standards
About these notes
Traffic Signal Lab is one intersection: Main Street, five lanes with a center turn lane, and Oak Street, one lane each way, with crosswalks on all four sides. The student writes the program that decides which street gets the green and for how long. The controller does what a real cabinet does by itself: the yellow and the all-red between greens, a minimum green, the walk intervals, and a safety monitor that flashes the light red if two crossing streets ever show green together.
Every level runs the same traffic from the same seed every time, so two programs are graded on the same rush hour. The score is seconds lost per car, measured car by car against the same trip straight through on green, and the level of service letter from the Highway Capacity Manual's bands: A for 10 seconds or less, B to 20, C to 35, D to 55, E to 80, F above.
A first period
Level 1 fits a period with time to talk about the trade.
- Watch (5 minutes) Open it on the projector. The light is already running the starter: Main 30 seconds, Oak 30. Ask what is wrong. Main's line grows; Oak's green runs on with hardly anyone on it.
- Read the score (5 minutes) Set the speed to 16x and let rush hour finish at 8:01: 39.6 seconds lost per car, a D. Ask what seconds lost means, and what an engineer would call good.
- One number (15 minutes) In Blocks, change Oak's wait from 30 to 15 and go back to the Simulator: the light starts over with the new program. At 16x it ends at 29.3, a C, and Level 1 is passed. Let pairs try their own splits and report their letters.
- The surprise (15 minutes) Someone will give Main 40. It scores worse, 37.7. Ask why. A longer cycle changes the light less often; most of Main's left turners can only turn at a change, so their line grows, and Oak's drivers wait longer for each green. No fixed split reaches B at this rush hour; a light that can see the cars does better, which is Level 2.
The five levels
Each level opens with the 30/30 starter and a guide card that says what to try. A level is passed on its letter with no faults, plus the level's own rule.
| Level | The problem | The fix it is built for | What it shows |
|---|---|---|---|
| 1. Rush hour on Main (7:41 a.m.) | Main backs up; Oak's green runs on with hardly anyone on it. Starter 39.6, D. Passes at C. | Oak's wait from 30 to 15: 29.3, C. | Cycle and split, and a tradeoff that is not linear: Main 40 scores worse. |
| 2. 2 a.m. | A car waits at Oak's red while Main's green runs for nobody. Starter a B, about 15.6. Passes at A. | One if: turn Oak green, then Main, only when a car is waiting on Oak (either way): about 5.5, A. | Detectors and actuated control; the minimum green the controller holds by itself. |
| 3. The school crossing (7:50 a.m.) | Children cross Main to the school; the button leaves a call and WALK never comes. People wait the whole 20 minutes. Passes at C with nobody waiting over 2 minutes and nobody caught in the road. | Give WALK across Main above turn Oak green, and across Oak above turn Main green. | An input that latches; WALK, the countdown and why its length follows the crossing. |
| 4. The left turn (5:10 p.m.) | A fifth of Main's drivers turn left, waiting for gaps the rush hour does not leave. Starter 71.5, E. Passes at D. | A Main left arrow green and a 10 second wait at the top of the loop: about 31.5, C. | Protected and permitted turns, the flashing yellow arrow, and phase numbers: 1 and 5 for the lefts, 2 and 6 for Main, 4 and 8 for Oak. |
| 5. The ambulance (12:10 p.m.) | Three ambulances, each caught at a red by the starter: 33.7, 35.9 and 47.1 seconds lost getting to the intersection. Passes at C with every ambulance within 10 seconds. | An event, when an ambulance is coming, with turn the ambulance's street green and wait until the ambulance is through: 0.1, 2.4 and 0.4. | Events that interrupt a running program and hand back; preemption; why even an ambulance waits for the yellow. |
Level 4 passes at D because a third phase brings its own yellow and all-red every cycle: every simple arrow program lands near 35 seconds, while lefts with no arrow grade E. Many cities accept a D at the busiest hour.
What students get wrong, and where the app answers it
These come up in almost every class. Each has a place in the app where the student can see the answer for themselves.
| What they think | What the app shows | Where |
|---|---|---|
| The busy street should get more green, so more is better. | More green for Main past 30 seconds scores worse: the cycle gets longer and the left turners and Oak both wait more. | Level 1, Main 40 and Oak 15. |
| A longer yellow is always safer, and a short one just makes people hurry. | The yellow is worked from the speed limit. Cut it below the formula and drivers who cannot stop run the red, and the run does not pass. | The timing sheet, Main's yellow at 2 seconds. |
| Traffic lights are all on timers. | A light that reads its detectors gives Oak a green only when a car is there, and grades an A at night where the timer gets a B. | Level 2. |
| Pressing the button more makes the WALK come sooner. | The first press leaves a call; the others do nothing. The program decides when it is served. | Level 3, button pressed across Main. |
| An ambulance gets a green the moment it is seen. | The controller still runs the yellow and the all-red. Skipping them puts two streets on green, and the safety monitor flashes the light red. | Level 5, the green NOW block. |
| A left turn on a green is always allowed to go. | On a flashing yellow arrow it yields to oncoming cars and people; at rush hour the gaps do not come and the turn lane spills over. | Level 4. |
What the app simplifies, on purpose
- One kind of vehicle, level roads, no lane changes once a driver has picked a lane.
- Every driver keeps to the speed limit. That is why the formula's yellow leaves no red-light runners here; on real streets a correct yellow cuts red-light running a lot, but speeding and distracted drivers still run some.
- Detectors always work.
- Delay is measured car by car in the simulation. Engineers also compute it with the Highway Capacity Manual's equations, which this does not use.
- The school level's children walk slower than the 3.5 feet per second the timing sheet assumes. The national guidance says to consider a slower speed where slow walkers cross often and gives no number; many cities use 3.0 by a school.
- In an emergency the rules allow a controller to cut WALK and the countdown short. This one lets people finish crossing, as many cities do. After an ambulance a real controller goes back to its plan in its own way, not always from where it stopped; here the program carries on with the time its wait had left.
- Which way phase 2 points is up to each city; the app uses one common assignment.
- Real controllers have dozens of settings per phase. This one has the few that matter most.
The timing sheet students hand in
Timing sheet, then Print, gives one page: the intersection drawn from above with the phase numbers on its movements, the student's best run on the level, a box where they wrote why they timed it that way, the timing table with the walking speed each countdown allows, and their program. It is a natural thing to collect at the end of each level.
Setting it up for a class
Nothing to install. Students open it from their projects; each level keeps its own program and its own timing sheet, and the project saves the best run on each level. File, then Add a car from my Files, puts a car a student made in Car Design Lab into the traffic, which does not change the score.
Each level takes about a minute at 16x. The Ride camera puts the student in a driver's seat at the light, with a count of how long the car has sat stopped, which makes the delay number something they feel.
Standards
- CSTA 2-AP-10 (planning the light's program), 2-AP-12 (loops and conditions that read detectors and buttons), 2-AP-17 (testing a program against the scoreboard), 2-DA-09 (the delay and its letter as a model's output).
- CSTA 3A-AP-16 (events: the ambulance block interrupts the running program), 3A-DA-12 (comparing timing plans on the same seeded traffic), 3B-DA-07 (the model's assumptions and what it leaves out).
- NGSS MS-ETS1-1 to 4 and HS-ETS1-4: criteria and constraints, competing solutions compared on the same test, and a computer simulation used to evaluate them.
- AP Computer Science Principles, the topic on simulations: a simplified model of a real system, run to answer a question.
The app follows published practice: the MUTCD for yellow ranges, walk intervals and the flashing yellow arrow, the FHWA Signal Timing Manual for minimum greens, ITE's change interval formulas, and the Highway Capacity Manual's level of service bands. It is not affiliated with any agency or controller manufacturer.
More help
Is something on this page wrong or not clear? Write to us.
Page last reviewed November 2026.
Google, Google Classroom and Chromebook are trademarks of Google LLC.