Arduino Tutorials

Let Your Terminal Agent Build Circuits in Sensbench

You probably already live in a terminal. Your firmware repo, your build scripts, maybe a code review or two. The Sensbench in-app agent is fine when you’re already in the browser, but it’s a separate island. What if the same agent you’re chatting with in your CLI could also place components, wire them, and write the sketch?

That’s what the Connect AI agent does. Sensbench exposes a Model Context Protocol (MCP) server. Your own Claude Code or Codex session connects to it with a token scoped to a single saved project. You ask for a circuit and firmware, and it appears on the canvas, live. No copy-pasting between windows.

Setting up the connection

Before you can point an agent at a project, you need three things: a saved Sensbench project, a token, and a one-line command.

  1. Save a project in Sensbench. The agent only talks to a project that already exists.
  2. Open File → Connect AI agent (Claude/Codex) from the editor menu. Pick your CLI (Claude Code or Codex) and click Generate connection token. The token will be shown exactly once, so copy it somewhere safe.
  3. Run the command the modal gives you. For Claude Code it looks like this:
claude mcp add --transport http sensbench https://sensbench.com/api/pro/mcp 
  --header "Authorization: Bearer vlxmcp_your_token_here"

Codex users get a ~/.codex/config.toml snippet instead. Both point your agent at the MCP server with the token as a bearer header.

The sketch

Once connected, just ask in natural language. For example:

“Using the sensbench tools, wire an HC-SR04 to the board and write the firmware that prints the distance over serial.”

Your agent will call Sensbench’s tools to add the ultrasonic sensor, wire it to the correct pins, write the sketch, and validate the circuit. Here’s the kind of sketch it might produce for an HC-SR04 on an Arduino Uno:

// HC-SR04 distance sensor on Arduino Uno
// Trigger: pin 9, Echo: pin 10

const int trigPin = 9;
const int echoPin = 10;

void setup() {
  Serial.begin(9600);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
}

void loop() {
  // Send a 10 microsecond pulse on the trigger
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);

  // Measure the echo pulse width
  long duration = pulseIn(echoPin, HIGH);

  // Convert to centimeters (speed of sound ~343 m/s)
  float distance = duration * 0.034 / 2;

  // Print to serial monitor
  Serial.print("Distance: ");
  Serial.print(distance);
  Serial.println(" cm");

  delay(500); // Wait half a second between readings
}

How it works

The MCP server exposes a full toolset: add and wire components, add boards, seat parts on a breadboard, write and edit the sketch, and validate the circuit. It also includes per-component skills, so the agent knows the exact pin names for an SSD1306 or a DHT22 without guessing.

When the agent calls a tool, the change is sent to your open Sensbench canvas over the websocket connection. Within a few seconds, you see the parts appear and the wires drawn. When it’s done, hit Run to simulate.

The token is the security boundary. It’s scoped to exactly one project, so the agent can’t touch your other projects or your account. Sensbench stores only a hash of the token, and it’s shown only once at generation. You can revoke any token from the modal at any time, individually or all at once. Tokens also expire after 90 days, so even a forgotten token eventually dies.

Honest notes on the simulator and the code

This is a browser simulator, not a physical bench. The HC-SR04 sketch above will run fine in the simulator, but real ultrasonic sensors have quirks the sim won’t show you: the echo pin can hang if the sensor is miswired, and the pulse width can be noisy in real environments. The simulator also won’t catch that you’ve connected the sensor to the wrong pins as long as the pins exist in the board definition.

The sketch itself has a known weak spot: pulseIn() blocks the entire loop until the echo arrives. If the sensor never gets a valid echo, the sketch hangs. In the simulator, that’s unlikely, but on real hardware it’s a classic failure mode. A better version would use a timeout or an interrupt.

Also, the agent’s wiring is only as good as its training data. It knows the standard pinouts, but if you have a custom board or a non-standard wiring scheme, double-check the connections before you trust it. The simulator will happily show you a circuit that looks right but is electrically wrong.

When it doesn’t work

  • Agent says “tool not found” → The MCP server isn’t added. Re-run the claude mcp add command and check the server name.
  • Token rejected → The token might be expired or revoked. Generate a new one from the modal.
  • Changes don’t appear on the canvas → Make sure you have the correct project open in Sensbench. The token is project-scoped, so if you’re looking at a different project, you won’t see anything.
  • Agent can’t find the board → The project may not have a board added yet. Add a board manually first, then let the agent wire components.
  • Serial output is blank → Check that the sketch’s baud rate matches the serial monitor in the simulator. Also verify the wiring for the sensor.

Next steps

Try asking the agent to add an OLED display and show the distance on it. Or have it write a calibration routine. The MCP toolset is the same one the in-app agent uses, so you can push it pretty far.

If you want to see it in action, open the Sensbench editor and try connecting your own agent.

Leave a Reply

Your email address will not be published. Required fields are marked *