Skip to content

Run a sketch on the bench ​

Every project opens in the same workspace: a pin map, the guide, the code editor and the bench. This page explains how to run a sketch, work the parts on the breadboard preview, talk to the sketch through the serial monitor, and understand what the simulator tells you.

The workspace ​

The Circuit Lab workspace running the Intruder alarm project on an ESP32-S3 DevKitC-1
  1. 1Customize — Makes your own copy, where the circuit can change.
  2. 2Export — Saves the program, diagram, build sheet, parts list or project file.
  3. 3Stop — Shows Run while stopped. Ctrl+Enter or F5 does the same.
  4. 4Guide — What the project does, its parts, the wiring and the steps.
  5. 5Code editor — The sketch. Your edits are saved as you type.
  6. 6Pin map — Every pin, with each part tagged on the pin it uses.
  7. 7Preview — The parts on a breadboard. Press, flip and slide them here.
  8. 8Serial monitor — What the sketch prints, with the time since it started.

In a wide window the workspace has three columns. In a narrower one, the same parts are tabs: Guide, Code and Bench, plus Circuit in your own projects. The pin map then sits at the top of the Guide tab.

The pin map's colours are explained under it: safe pin, avoid, power and ground. While a sketch runs, pins it drives high are shown as driven high.

Run and stop ​

Select Run at the top right, or press Ctrl + Enter or F5. The bench shows running, and Run becomes Stop. On a narrow screen the app switches to the Bench tab.

  • Each run starts the sketch from the beginning, with an empty serial monitor and the clock at zero.
  • What you set on the bench, such as a turned knob or a flipped switch, carries over to the next run.
  • The sketch runs in step with real time: delay(1000) takes a second, and millis() counts real milliseconds.
  • A sketch that never pauses does not freeze the app. Select Stop at any time.

A Raspberry Pi 4 / 5 project has no Run button. It shows Runs on the Pi instead, because the app does not simulate a Pi. See Deploy to a real board.

Work the parts ​

The breadboard preview draws each part with a label under it saying what it is doing. Inputs react to you.

PartWhat you doWhat it shows
LEDWatchon, off, or the PWM level, such as duty 128/255
Push button, touch sensorPress and holdtap and hold; pressed · LOW or touched · HIGH while held
Slide switch, tilt switch, door sensorTap to flipIts state and the level the pin reads
Motion sensor (PIR), obstacle sensor (IR)Tap to flipmotion · HIGH or blocked · reads LOW
Knob, light, soil, water, gas and sound sensorsDrag the sliderThe reading analogRead() returns
Temperature sensorDrag the slider, from −10 to 60 °CThe temperature, starting at 22 °C
Distance sensorDrag the slider, from 2 to 200 cmThe distance, starting at 50 cm
BuzzerWatchThe note's frequency, such as ♪ 440 Hz, or silent
RelayWatchON · contact closed or off · contact open
ServoWatchIts angle in degrees
DC motorWatchIt turns; its speed, running or stopped
Laser moduleWatchbeam on or off

The buzzer is drawn, not played: the app makes no sound. The board's own LED is drawn on the board, and the ESP32-S3's RGB LED shows its red, green and blue values.

A soil sensor's slider sets how moist the soil is. Like the real sensor, the reading goes down as the soil gets wetter.

The serial monitor ​

Everything the sketch prints with Serial.print(), Serial.println() or Serial.printf() appears in the serial monitor. Each line starts with the time since the run began, in minutes, seconds and milliseconds:

text
00:00.000 > Flip the switch to arm.

The monitor keeps the last 500 lines. You can select text in it and copy it. The 115200 baud label is the speed the sketches set with Serial.begin(115200), the speed to use with a real board.

Send a line to the sketch ​

Type in the box type a command, press Enter and press Enter, or select the send button. Some projects show ready-made commands as buttons above the box; select one to send it. The sketch reads what you send with Serial.available(), Serial.readStringUntil() and similar calls.

Try it with Serial echo, in the Basics group of the Projects tab:

  1. Open Serial echo and select Run. The monitor says Type something and press Enter.

  2. Select the hello button above the box, or type hello and press Enter.

  3. The sketch answers:

    text
    You said: hello
    Length: 5
    Louder: HELLO

Hints and errors ​

The simulator watches for mistakes that a real board would make without telling you.

Hints ​

A hint appears in the serial monitor on a line starting with [sim], in a different colour. The sketch keeps running. Each hint is shown once per run.

The hint saysWhat to do
digitalWrite on a pin does nothing yetAdd pinMode(pin, OUTPUT) in setup()
A pin is floating, so it reads at randomUse INPUT_PULLUP in pinMode()
A pin is read at reset to pick the boot modeMove the part to another pin if you can
A pin has no PWM, so analogWrite only switches it on or offUse one of the PWM pins the hint lists

Errors ​

An error stops the run. It appears in red under the code editor, starting with the line number, and the editor marks that line. For example:

text
Line 12: 'ledpin' is not declared. Check the spelling, or declare it first.

Common errors are a misspelt name, a pin that does not exist on the board, analogRead() on a pin with no analog input, an output on an input-only pin, an array index outside the array, and a function the simulator does not have, such as anything from Wi-Fi or a third-party library. Fix the line and select Run again.

Running in the simulator does not prove the sketch compiles for the real chip. The real compiler is stricter. See What the simulator covers.

Next steps ​