# How to easily turn on/off all debug message on Arduino IDE

**URL:** https://forum.amebaiot.com/t/how-to-easily-turn-on-off-all-debug-message-on-arduino-ide/165
**Category:** Arduino
**Created:** [January 22, 2021, 9:09am UTC](https://forum.amebaiot.com/t/how-to-easily-turn-on-off-all-debug-message-on-arduino-ide/165 "2021-01-22T09:09:41Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![xidameng](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.amebaiot.com/xidameng/32/18_2.png) [@xidameng](https://forum.amebaiot.com/u/xidameng)
#### Post date: [January 22, 2021, 9:09am UTC](https://forum.amebaiot.com/t/how-to-easily-turn-on-off-all-debug-message-on-arduino-ide/165/1 "2021-01-22T09:09:41Z")

</div>

# Introduction

**Arduino IDE** is a convenient tool to write your code and upload to microcontrollers. However, it doesn’t come with debugger function, which means the only way to debug our program is through using debug message through standard output, in this case, **Serial Monitor**.

Debug message is handy and it helps to print out the information the registers holds at a specific time, but once you have done debugging and your program is ready to go, we often have to delete/comment out those debug message code manually, in a big project, this could be problematic as there are just too manny of them.

Today, I am going to show you an easy method to **turn on / off** debug message with only a few lines of code.

# Method

> The method here is to use a macro function

Take a look of the following C code,

```C
//#define __DEBUG__

#ifdef __DEBUG__
#define DEBUG(...) printf( __VA_ARGS__ )
#else
#define DEBUG(...)
#endif

```

Since all Ameba microcontroller supports `printf()`, we can re-define `printf()` to a preprocessor function, in this case, I name it `DEBUG()`. Whenever you want to print out the debug message, instead of `Serial.print()` or `printf()`, you should try using `DEBUG()` instead, it works just like the previous two, but can be easily enabled or disabled by **uncomment** `//#define __DEBUG__ ` or just leave the comment syntax there.

Let’s look at an example

## Example code 1

This is a simple code that only print out _“Debug msg 1”_ and _“Debug msg 2”_ alternatively with a 1 second delay in between.

 ![Screenshot 2021-01-22 163944](https://us1.discourse-cdn.com/flex016/uploads/ameba/original/1X/76ea47a25c9c837131a2a7e5375e86de08f56590.jpeg)

**Note** that the first line of the code is **uncommented** , and we are seeing the debug messages actually got printed out using the `DEBUG()` function.

## Example code 2

 ![Screenshot 2021-01-22 164117](https://us1.discourse-cdn.com/flex016/uploads/ameba/original/1X/ddc6f4bbe9ae6d6395c1fb99234efef26fe98920.jpeg)

**Note** that this is the same code except I keep the first line **commented out** , and as a result, no debug messages got print out at all.

It works! 🕶

* * *

# Conclusion

All you need to do is to **copy** the few lines of code from above into the top of your arduino sketch and you may name your custom debug function anything you like and it will work like a charm.

Turn on / off is just to keep / remove the `//` at the first line, very convenient.

Hope you like this content, stay healthy and happy coding~ 🕶
