Serial monitor shows NUL or binary instead of intended output.

I’m trying to use the Button library, and I’m having problems with using the serial print at the same time for debugging. At setup, it shows “Ready to receive colors” just fine. However there’s usually a binary (?) character in front of it.

The loop gives me three very different outcomes:
press and release button = NUL NUL button release
press and hold = It creates an infinite loop of binary (?) characters, I suspect it’s that pressedFor() gets triggered continuosly.

But why isn’t the serial.println() command working? Is there a conflict between it and the button library?

Thank you in advance!

#include <Button.h>        //

#define BUTTON1_PIN 1       
#define PULLUP true        //To keep things simple, we use the Arduino's internal pullup resistor.
#define INVERT true        //Since the pullup resistor will keep the pin high unless the
                           //switch is closed, this is negative logic, i.e. a high state
                           //means the button is NOT pressed. (Assuming a normally open switch.)
#define DEBOUNCE_MS 20     //A debounce time of 20 milliseconds usually works well for tactile button switches.

Button button1(BUTTON1_PIN, PULLUP, INVERT, DEBOUNCE_MS);    //Declare the button

void setup(void)
	Serial.println("Ready to receive colors.");

void loop(void)
{;                    //Read the button

    if (button1.wasPressed()) {    
		Serial.println("button 1"); // This shows NUL NUL

    if (button1.pressedFor(1000)) {
		Serial.println("button 1 held"); // This works ok
    if (button1.wasReleased()) {       
  		Serial.println("button released"); // This outputs a lot of binary


You are using pin 1 which is also TX.

Have you accounted for the fact that you are using pin one which is also a serial pin?

What Arduino are you using?

Ah, thanks a lot that makes sense! Now i understand why most examples used pin 2 :slight_smile:

Pins A0 through A5 should be safe for general purpose I/O.
Pins 2 through 12 should be safe for general purpose I/O.

Pins 0 and 1 take special care.
Pin 13 needs special care on some Arduinos.

Most pins have multiple uses. If you are using a pin for one of these uses, you should not use it for general purpose I/O.

Good Luck!

Thanks again for the extra info!