Source: https://mokxi.com/traffic-light-simulator

Simulator

# A traffic light simulator with a crossing button

Mokxi is a free online traffic light simulator that runs in your browser, with nothing to install and no account needed. An Arduino Uno runs a traffic light module through green, yellow and red, a pushbutton asks for the walk signal sooner, and a piezo beeps while it is safe to cross. Press the button during the green and the light changes 1.5 seconds later.

Start building free or build one from three LEDs

- 455 parts on the bench
- 43 boards running now
- 1.00x real time, on every board

Hold the button

## What you can do here

In the circuit above, or in the editor it opens.

- Press the crossing button and watch the green cut short
- Change the green, yellow and walk times in the sketch
- Build the same light from three LEDs and three resistors
- Add a second light for the cross street and keep the two in step
- Rewrite the loop as a state machine on millis() instead of delay()
- Watch the three pins on the logic analyzer as the cycle runs

## What the running circuit shows

One cycle, about fifteen seconds.

The sketch holds green for 8 seconds and yellow for 2, then red while walkers cross: sixteen 2000 Hz beeps a quarter second apart, then twelve quicker ones at 2500 Hz to hurry. In the engine one cycle takes about 15.2 seconds, and the serial monitor prints “cars: green”, “cars: yellow”, “cars: red, walk” and “hurry” as it goes.

During the green the sketch reads the button every 10 ms. Press it a second into the green and it prints “button: walk soon” and ends the green 1.5 seconds later, so in the engine the light turns yellow about 2.5 seconds after it went green instead of 8. The module’s resistors are on its own board, so its three pins go straight to Uno pins 13, 12 and 11; with the green lit, pin 11 sits at about 4.74 V.

## How the light is modeled

Three real LEDs on one small board.

Each lamp is the same diode model as a plain LED, in its own color, behind its own 220 ohm resistor on the module, and the three cathodes share one GND pin: leave GND unwired and nothing lights. The Uno runs the sketch’s compiled code, so delay(), millis() and tone() keep the times they would on a board. The piezo’s tone is not played through your speakers; the piezo shows the frequency it is playing instead.

What it leaves out: the real resistor on your module, which these boards are sold without a schematic for, so 220 ohm is an assumption, and how bright each color looks beside the others. The button never bounces unless you set it to, and the sketch would cope if it did, since it acts only on the first press of each green.

An Arduino traffic light, step by step An Arduino state machine Interrupts or polling The LED circuit simulator

## Questions

Is it free?

Yes. The circuit on this page, every part in it and the editor it opens in are on the free plan, with no card.

Do I need an account?

No. The circuit runs the moment the page does, and the editor opens without one. A free account is only for saving a project to the cloud and sharing it by link.

Can I build the traffic light from Tinkercad here?

Yes. Three LEDs with a 220 ohm resistor each on three pins is the same circuit as this module, and the Arduino traffic light page builds it step by step. A traffic light sketch that uses only pinMode, digitalWrite and delay runs here as it is.

How do I make a traffic light without delay()?

Note the time each light started with millis(), and in loop() check whether its time is up, so the board can read the button between checks. The state machine page shows the pattern on a four-state game.

Does it work on a Chromebook?

Yes. It runs in Chrome with nothing to install, which is how many school coding and engineering classes use it.

## More simulators

Each one opens on a circuit that is already running.

Online circuit simulator Breadboard simulator ESP32 simulator Op-amp simulator Logic gate simulator LED circuit simulator Servo simulator LCD simulator OLED simulator NeoPixel simulator 7 segment display simulator LED matrix simulator Stepper motor simulator Motor driver simulator Ultrasonic sensor simulator Rectifier simulator Digital circuit simulator Potentiometer simulator PWM simulator Relay simulator Shift register simulator DHT11 simulator RFID simulator Accelerometer simulator RGB LED simulator Buzzer simulator MOSFET simulator Circuit simulator for kids Flip-flop simulator Multiplexer simulator Full adder simulator I2C simulator UART simulator Thermistor simulator PIR sensor simulator Oscilloscope simulator Multimeter simulator DC motor simulator Diode simulator Capacitor simulator Series and parallel circuit simulator Wheatstone bridge simulator Voltage regulator simulator Soil moisture sensor simulator Zener diode simulator Solar panel simulator AC circuit simulator Thevenin simulator Decoder simulator Encoder simulator PID simulator Robot arm simulator Load cell simulator IR sensor simulator LM35 simulator HC-05 Bluetooth simulator nRF24L01 simulator

## Cross the road

Open the circuit, press Run and push the button. Nothing to install, and no account needed.

Start building free Open the editor
