Guides · 9 min read

Arduino IDE 2 Debugger: Breakpoints, Stepping and Boards

Arduino IDE 2 debugger guide: breakpoints, stepping and watching variables; setup for Uno R4, Zero, ESP32-S3/C3 USB JTAG and Pico Debug Probe, plus fixes.

The Arduino IDE debugger is a tool that lets you stop your code on any line, look at the current value of your variables and run the program line by line. Since Arduino IDE 2 it is built into the IDE: you start it with the bug-shaped Start Debugging button next to Upload, and a panel opens on the left showing variables, the call stack and breakpoints. It doesn't work on every board, though; the board needs a debug interface (SWD or JTAG) and a probe connected to it.

In this guide you'll see how the debugger differs from debugging with Serial.print, which boards are supported (Uno R4, Zero, the built-in USB JTAG of the ESP32-S3 and ESP32-C3, Raspberry Pi Pico with a Debug Probe), how to set up your first debug session step by step, and how to use breakpoints, stepping and variable watching on an exercise sketch with a deliberate bug. At the end you'll find the most common setup problems and Serial macros that make life easier on boards without a debugger, such as the Uno R3.

What is a debugger and how is it different from Serial.print?

Most of us start debugging with Serial.print: we add a line where we suspect a problem, upload the code, look at the Serial Monitor, and if something is missing we add another line and upload again. This works on every board, but every attempt means waiting for a compile and upload, and you can't see any variable you didn't print. A debugger talks to the debug unit inside the microcontroller. It halts the board at a breakpoint and shows you every local and global variable at that moment, the processor registers and the order in which functions were called. You can watch any variable without changing the code, step into a function and go through it line by line. In the background OpenOCD (the probe driver) and GDB (the GNU debugger) are running; IDE 2 presents them in an interface that will feel familiar from VS Code.

FeatureSerial.printIDE 2 debugger
Board supportAny board with a serial portOnly boards with an SWD/JTAG interface and a probe
Extra hardwareNoneBuilt in on some boards, external probe on others
Seeing variablesOnly what you printAll local and global variables at that moment, plus registers
Looking at something newEdit the code, compile, uploadCode stays the same; add it to the Watch list
TimingThe program keeps runningThe program halts; interrupts, PWM and Wi-Fi can be affected
Long-term monitoringVery good (data logging, plots)Not suitable; inspects a moment in time
Best forSensor values, following the flowCrashing code, wrong calculations, array overruns, logic bugs

Which boards are supported? Board and debug method table

Debugger support depends on the board's processor and its board package. Boards with ARM Cortex-M processors (Uno R4, Zero, MKR, GIGA, Portenta, Raspberry Pi Pico) offer an SWD interface; the ESP32 family uses JTAG. On some boards the probe is on the board itself: the EDBG chip on the Zero, the ESP32-S3 that works as the USB bridge on the Uno R4 WiFi, and on the ESP32-S3 and ESP32-C3 the USB JTAG unit inside the processor does the job. On the others you connect an external probe to the SWD or JTAG pins. The debugWIRE interface of the AVR processors on the classic Uno R3, Nano and Mega is not supported by the official IDE 2 debugger.

BoardDebug methodExtra hardwareIDE setting
Uno R3, Nano, Mega (AVR)No official support-Debug with Serial
Uno R4 WiFiBuilt-in CMSIS-DAP (ESP32-S3 bridge)None, a USB cable is enoughProgrammer: ARM CMSIS-DAP compatible
Uno R4 MinimaSWD headerJ-Link or 5 V compatible CMSIS-DAP probeProgrammer: depends on the probe
Arduino ZeroBuilt-in EDBGNone, Programming portProgrammer: Atmel EDBG
MKR series, Nano 33 IoTSWD padsJ-Link or Atmel-ICE (soldering needed)Programmer: depends on the probe
Nano ESP32Built-in USB JTAGNoneUSB Mode: Debug mode (Hardware CDC), Programmer: Esptool
ESP32-S3 DevKitBuilt-in USB JTAGNone, the port labeled "USB"USB Mode: Hardware CDC and JTAG, JTAG Adapter: Integrated USB JTAG
ESP32-C3 (DevKitM, Super Mini)Built-in USB Serial/JTAGNoneJTAG Adapter: Integrated USB JTAG
Classic ESP32 (WROOM DevKit)JTAG pins (GPIO 12–15)ESP-Prog or FT2232H probeJTAG Adapter: FTDI Adapter
Raspberry Pi Pico / Pico WSWD (SWCLK, SWDIO)Raspberry Pi Debug Probe or a second PicoUpload Method: Picoprobe/Debugprobe (CMSIS-DAP)
If all you have is an Uno R3 or a Nano, the debug button stays grey and you'll see a message like "debugging is not supported"; that's not a fault. On these boards debugging with Serial is the right approach. If you want to learn the debugger, the easiest start is an Uno R4 WiFi, a Zero or an ESP32-S3 / ESP32-C3 board with built-in USB JTAG, none of which need extra hardware.

Setup: your first debug session step by step

  1. Install Arduino IDE 2.3 or newer; since 2.3 the debugger is no longer experimental. For installation, see the Arduino IDE installation article.
  2. Install or update your board's package in the Boards Manager (Arduino UNO R4 Boards for the Uno R4, esp32 for ESP32, Raspberry Pi Pico/RP2040 for the Pico).
  3. Select the board and port. On an ESP32-S3 DevKit connect to the port labeled "USB", on the Zero use the Programming port.
  4. In the Tools menu, set the Programmer, USB Mode or JTAG Adapter option from the table.
  5. In the Sketch menu, tick Optimize for Debugging so the code is compiled in a debug-friendly way.
  6. Upload the code as usual. The debug button doesn't upload the code itself; whenever you change the code, upload it again first.
  7. Click to the left of the line number where you want to stop; a red dot, the breakpoint, appears.
  8. Press Start Debugging. When the program reaches the breakpoint it halts and the line is highlighted in yellow.
If Optimize for Debugging is not selected, the compiler squeezes the code for size and speed: variables vanish into registers, lines get merged and the panel shows "optimized out" instead of a value. This option makes the code a little bigger and slower; switch it off and upload again when you're done debugging.

Exercise sketch: find the bug with the debugger

The code below looks like it takes five readings from a potentiometer or LDR on A0 and prints the average, but it contains a deliberate bug. In the Serial Monitor the average grows over time and takes strange values even without turning the potentiometer. We'll upload it to an Uno R4, Zero, ESP32-S3, ESP32-C3 or Pico and find the bug with the debugger. The compiler may also warn about this line with something like "iteration 5 invokes undefined behavior"; warnings get lost in the build output, so they are often missed.

C++ (Arduino IDE)
1// Hata ayıklama alıştırması: son 5 okumanın ortalaması (kodda bilerek bir hata var)
2// Debugging exercise: average of the last 5 readings (the code has a deliberate bug)
3const int SENSOR = A0;        // potansiyometre ya da LDR / potentiometer or LDR
4const int N = 5;
5
6int samples[N];               // son 5 okuma / last 5 readings
7int counter = 0;              // toplam okuma sayısı / total number of readings
8
9int average() {
10  long sum = 0;
11  for (int i = 0; i <= N; i++) {    // HATA: <= yerine < olmalı / BUG: should be < instead of <=
12    sum += samples[i];              // i = 5 dizinin dışını okur / i = 5 reads outside the array
13  }
14  return sum / N;
15}
16
17void setup() {
18  Serial.begin(115200);
19}
20
21void loop() {
22  samples[counter % N] = analogRead(SENSOR);
23  counter++;
24  int avg = average();              // kesme noktasını bu satıra koy / put the breakpoint on this line
25  Serial.println(avg);
26  delay(500);
27}

Put a breakpoint on the line int avg = average(); and press Start Debugging. When the program halts on that line, use Step Into to enter the average() function. In the Local section of the Variables panel you'll see sum and i, and in the Global section the samples array and counter. Use Step Over to go through the loop line by line: i adds up the array elements from 0 to 4, then i becomes 5 and the loop runs one more time. There is no element samples[5]; that address falls on a variable right after the array in memory, and most of the time the value of counter gets mixed into the sum. That's why the average grows over time. Once you've found the bug, change the condition to i < N, upload again and verify with the same steps.

Getting to know the debug panel

Panel sectionWhat does it show?
Threads / Call StackWhich function the program stopped in and which calls led there (loop → average)
VariablesLocal, Global and Static variables plus the processor registers (Registers); you can expand arrays and structs to look at each element
WatchExpressions you add yourself, such as counter % N or samples[2] * 2; refreshed at every stop
BreakpointsA list of all breakpoints; you can disable and enable them one by one
Cortex PeripheralsPeripheral registers on ARM boards (GPIO, timers, ADC); shown when the board package includes an SVD file
Debug ConsoleGDB output; type a variable name or an expression to have it evaluated
ButtonWhat does it do?
ContinueRuns the program until the next breakpoint
PauseHalts the running program right away; ideal for seeing where it is stuck
Step OverRuns the current line and moves to the next one; doesn't enter functions
Step IntoIf the line contains a function call, enters that function
Step OutRuns the rest of the current function and returns to where it was called
Restart / StopRestarts or ends the session

Conditional breakpoints and logpoints

If loop() runs thousands of times per second, stopping on every pass is no use. Right-click a breakpoint and choose Edit Breakpoint to enter a condition, for example counter == 20 or avg > 900. The program then stops only when the condition is true. With Hit Count you make the breakpoint stop only after a certain number of passes. A logpoint is a breakpoint that prints a message without stopping: right-click next to the line number, choose Add Logpoint and type a text such as "average {avg}"; you get the effect of Serial.print without changing the code. Keep in mind that breakpoints mostly use the processor's limited number of hardware breakpoint units; the Cortex-M0+ in the Pico and Zero, for example, has 4 of them. If you set many breakpoints, some may not trigger or the session may report an error; disable the ones you no longer need.

ESP32-S3 and ESP32-C3: debugging over built-in USB JTAG

The ESP32-S3 and ESP32-C3 contain a unit that provides both a serial port and JTAG over USB, so no extra probe is needed. The ESP32-S3 DevKitC has two USB ports: the one labeled "UART" goes to a USB-to-serial converter and can't be used for debugging, while the one labeled "USB" connects directly to the processor's built-in USB JTAG unit. On single-port boards such as the ESP32-C3 Super Mini the USB already goes straight to the processor. The classic ESP32 (WROOM-32 DevKit) has no built-in USB JTAG; you need to connect a probe such as the ESP-Prog to GPIO 12 (TDI), 13 (TCK), 14 (TMS) and 15 (TDO), and you can't use those pins for anything else while debugging. For board details, see the ESP32-S3 DevKit and ESP32-C3 Super Mini articles.

Setting (Tools menu)ESP32-S3ESP32-C3Classic ESP32
ConnectionPort labeled "USB"The board's USB portESP-Prog, GPIO 12–15
USB ModeHardware CDC and JTAGNo menu (USB Serial/JTAG only)No menu
JTAG AdapterIntegrated USB JTAGIntegrated USB JTAGFTDI Adapter
Sketch menuOptimize for DebuggingOptimize for DebuggingOptimize for Debugging
Windows driverEspressif USB JTAG driver (WinUSB via Zadig if needed)SameFTDI driver
On the ESP32, when a debug session starts the program sometimes halts first in startup code or at the beginning of setup(); you may need to press Continue a few times to reach your own breakpoint. While the program is halted, Wi-Fi and Bluetooth connections can drop because they can't respond in time. If you're hunting a bug in network code, put the breakpoint on a line after the connection is established and don't stay halted for long. On Linux, if you see "LIBUSB_ERROR_ACCESS", copy Espressif's 60-openocd.rules file into /etc/udev/rules.d/.

Debugging the Uno R4 WiFi, Zero and Uno R4 Minima

The Uno R4 WiFi is one of the easiest Arduino boards to debug: its ESP32-S3 works not only as a USB-to-serial bridge but also as a CMSIS-DAP probe, connected to the main RA4M1 processor over SWD. Connect the board via USB, choose Tools > Programmer > ARM CMSIS-DAP compatible, tick Optimize for Debugging, upload and press Start Debugging. The Uno R4 Minima has no bridge processor, so you plug an external probe into the SWD header on the board; since the RA4M1 runs at 5 V there, make sure your probe supports a 5 V target. On the Arduino Zero the EDBG chip is the built-in probe; just connect the board via the USB port labeled "Programming" and select Atmel EDBG as the Programmer. To get to know the Uno R4 family better, see the Arduino Uno R4 article.

Raspberry Pi Pico and the Debug Probe

On the Raspberry Pi Pico the USB port is only for uploading and serial communication; debugging uses the three-pin SWD header on the edge of the board (SWCLK, GND, SWDIO). As a probe you can use the official Raspberry Pi Debug Probe or a second Pico running the debugprobe firmware (debugprobe_on_pico.uf2). In the Arduino IDE install Earle Philhower's Raspberry Pi Pico/RP2040 package and choose Picoprobe/Debugprobe (CMSIS-DAP) from Tools > Upload Method; the code is now uploaded through the probe and the Start Debugging button becomes active. Because the probe can also carry the target Pico's serial port, if you wire the UART you get the Serial output over the same cable.

Probe Pico pinTarget PicoFunction
GP2SWCLKSWD clock
GP3SWDIOSWD data
GNDGND (on the SWD header)Common ground
GP4 (UART TX)GP1 (UART0 RX)Optional serial port
GP5 (UART RX)GP0 (UART0 TX)Optional serial port
VSYSVSYSIf you want to power the target from the probe

Debugging with Serial on boards without a debugger

Even without a debugger on the Uno R3, Nano and Mega, using Serial in a more organized way saves you a lot of time. The macros below switch all debug output on and off with a single DEBUG constant; when you set it to 0 these lines aren't compiled and use no flash or RAM. The DVAR macro prints a variable together with its name, and with micros() you measure how many microseconds a piece of code takes. Wrapping strings in F() keeps constant text in flash instead of RAM. For detailed use of the Serial Monitor and Serial Plotter, see the Arduino Serial Monitor article.

C++ (Arduino IDE)
1// Debugger olmayan kartlar için Serial ile hata ayıklama makroları
2// Serial debugging macros for boards without a debugger
3#define DEBUG 1               // 0 yaparsan tüm çıktılar derlenmez / set to 0 to compile all output away
4
5#if DEBUG
6  #define DPRINT(x)    Serial.print(x)
7  #define DPRINTLN(x)  Serial.println(x)
8  #define DVAR(x)      do { Serial.print(F(#x " = ")); Serial.println(x); } while (0)
9#else
10  #define DPRINT(x)
11  #define DPRINTLN(x)
12  #define DVAR(x)
13#endif
14
15const int SENSOR = A0;
16const int N = 5;
17int samples[N];
18int counter = 0;
19
20int average() {
21  long sum = 0;
22  for (int i = 0; i < N; i++) {     // düzeltilmiş döngü / fixed loop
23    sum += samples[i];
24  }
25  return sum / N;
26}
27
28void setup() {
29  Serial.begin(115200);
30  DPRINTLN(F("Basladi / Started"));
31}
32
33void loop() {
34  unsigned long t0 = micros();      // süre ölçümü / timing measurement
35  samples[counter % N] = analogRead(SENSOR);
36  counter++;
37  int avg = average();
38  unsigned long dt = micros() - t0;
39
40  DVAR(counter);                    // "counter = 12" gibi yazar / prints like "counter = 12"
41  DVAR(avg);
42  DPRINT(F("Sure (us) / Time (us): "));
43  DPRINTLN(dt);
44  delay(500);
45}

Setup problems and fixes

ProblemLikely causeFix
Debug button is grey, says "not supported"The board doesn't support it or Programmer / JTAG Adapter not selectedApply the setting from the table; on boards like the Uno R3 use Serial
Variables show "optimized out"Optimize for Debugging is offTurn the option on and upload again
Breakpoint never triggersCode changed but not uploaded again, or breakpoint limit exceededUpload again, disable unnecessary breakpoints
"could not find or open device" on the ESP32-S3Wrong port (UART) or no USB JTAG driverSwitch to the "USB" port, install the driver on Windows or assign WinUSB with Zadig
"unable to open CMSIS-DAP device" on the Uno R4 WiFiWrong programmer or driver problemSelect ARM CMSIS-DAP compatible, replug the board, update the IDE
Nano ESP32 won't debug another boardAn old debug_custom.json is left in the sketch folderDelete the file and restart the session
Step Into got me lost inside delay()You entered the core libraryLeave with Step Out; use Step Over in your own code
Serial or Wi-Fi drops when haltedTiming breaks because the processor is haltedMove the breakpoint out of the critical section, use a logpoint

A debugger lets you answer "why does my code behave like this?" by looking rather than guessing, while Serial.print remains the most practical tool for watching sensor data and long-term logging; learning to use both together speeds you up a lot. If you want to try debugging on small, familiar projects, check the wiring diagrams and code of the "LED with a Push Button", "Reading Light Intensity with an LDR" and "ESP32 LED Blink" projects in the BlueGrays app and step through them with your own breakpoints.

Frequently asked questions

Can you use a debugger on an Arduino Uno?

The official Arduino IDE 2 debugger doesn't support the classic Uno R3 (ATmega328P); the debug button stays grey. On the Uno R3, debugging with Serial is the most practical approach. The Uno R4 WiFi, on the other hand, can be debugged with just a USB cable thanks to its built-in CMSIS-DAP probe.

How do I open the debugger in Arduino IDE 2?

Select a supported board, set the Programmer or JTAG Adapter option in the Tools menu and tick Sketch > Optimize for Debugging. After uploading the code, click left of a line number to set a breakpoint and press the Start Debugging button next to Upload.

What does Optimize for Debugging do?

It compiles the code with debug-friendly compiler settings, so variables and lines map one-to-one to the machine code. If it isn't selected, variables show as "optimized out" in the panel and lines get skipped while stepping. Turning it off when you're done makes the code smaller and faster again.

Can an ESP32 be debugged with the Arduino IDE?

Yes. The ESP32-S3 and ESP32-C3 need no extra hardware thanks to their built-in USB JTAG; just choose Integrated USB JTAG as the JTAG Adapter in the Tools menu. The classic ESP32 has no built-in USB JTAG, so you need an external JTAG probe such as the ESP-Prog on GPIO 12–15.

How do I debug a Raspberry Pi Pico in the Arduino IDE?

Connect a Raspberry Pi Debug Probe, or a second Pico running the debugprobe firmware, to the Pico's SWD header. In Earle Philhower's Pico package choose Picoprobe/Debugprobe (CMSIS-DAP) from Tools > Upload Method, upload the code and press Start Debugging.

Why isn't my breakpoint working?

The most common reason is that the code wasn't uploaded again after a change; the debug button doesn't upload. The line may also have been removed by the compiler if Optimize for Debugging is off, or the processor's hardware breakpoint limit may have been exceeded. Upload again and disable extra breakpoints.

See all projects
LED Blink
AR-1Beginner

LED Blink

The very first hello of electronics: switching a single LED on and off. The Arduino keeps the LED on for one second and off for one second, so you can easily follow every blink.

4.6(203)
1396
LED Control with a Push Button (Push)
AR-9Beginner

LED Control with a Push Button (Push)

Just like a doorbell: the light stays on as long as you press, and goes off when you let go.

4.8(120)
288
Measuring Light Intensity with an LDR
AR-11Beginner

Measuring Light Intensity with an LDR

Want to see how bright your room is as a number? The LDR, a small part that reacts to light, measures the light around it, and the Arduino writes the value to your computer screen every half second.

4.5(86)
154
HC-SR04 Distance Measurement (Serial Display)
AR-27Beginner

HC-SR04 Distance Measurement (Serial Display)

The HC-SR04 sensor works just like a bat finding its way in the dark: it sends out a sound you cannot hear, listens for the echo and measures how far away the object in front of it is.

4.6(52)
94
Temperature and Humidity with DHT11
AR-55Intermediate

Temperature and Humidity with DHT11

How warm is your room, and is the air humid or dry? The DHT11 sensor measures temperature and humidity, and the Arduino writes the values on a two-line LCD screen, refreshing every couple of seconds.

4.7(47)
96
LED Blink with ESP32
ES-1Beginner

LED Blink with ESP32

Teaches basic GPIO output usage with ESP32. We achieve a blinking effect by turning an LED on and off from a digital pin. ESP32 version of the classic blink project on Arduino UNO; the basic blink commands in the Arduino environment are the same, but the ESP32's pin layout and 3.3 V GPIO levels differ from those of the Arduino UNO.

4.7(38)
114
ESP32 LED Control with Push Button (Push)
ES-2Beginner

ESP32 LED Control with Push Button (Push)

The LED lights up when the button is pressed and turns off when released. Shows how the ESP32's digital input pin and internal pull-up resistor are used. The INPUT_PULLUP mode eliminates the need for an external resistor.

4.6(36)
57
Raspberry Pi Pico Onboard LED Blink (Pico and Pico W)
PI-1Beginner

Raspberry Pi Pico Onboard LED Blink (Pico and Pico W)

The opening project of the Raspberry Pi Pico series! We blink the Pico's green built-in LED to confirm the board works, the classic "Hello World" first experiment. No external parts needed, just the Pico and a USB cable. The code is written in MicroPython, the language officially supported by the Raspberry Pi Foundation.

5.0(1)
11