Use of Serial pins 0 & 1

If Serial.begin is not being called is it safe to use pins 0 & 1? I use an if statement to determine if it's hooked up to PC or not and only call serial.begin if PC.

Why not use other pins for Your needs?
How do You do detect whether the board is hooked up to a Pc?

Well the other pins are used. Hence I'm asking.

The other pins connect to things such as reed switches all around my back door. Since most of these are closed, some simple logic detects that the pins are not open, and hookedUp = 1. If (hookedUp == 0) Serial.begin

Okey. How is hookedUp found? I tried to use it myself for my own interest but got "undefined" from the compiler. Just trying to test Your theory.

Search for "port expander" or "multiplexer"

Or change to a different Arduino. A Leonardo or Micro does not use 0 and 1 to communicate with the PC. A Mega has lots of pins.

Pins 0,1 are hardwired to the output of the USB<>Serial chip (not the USB/PC side).
They are always pulled HIGH, independent of code.
Safer to leave them alone.

Well the other pins are used. Hence I’m asking.

So you just want more pins.

Did you already use the analogue pins.
They are just regular digital pins with the added functionality of analogue-in.
Can use pin number 14-19 for A0-A5 on an Uno.

As it's all switches, you can also matrix them to save lots of pins.

16 switches can be handled by 8 pins that way (4x4 matrix).

Wawa - Thank YOU! It's always HIGH so that answers my question. I need another board, perhaps one of the ESP11s I got hanging around and I'll have them communicate events on pins via serial. The ESP can do the thinking... I'm thinking aloud.

Don't add a second MCU just because you run out of pins. Add a port extender instead.

Are you using A0 to A5, analog pins as well?

Thanks.. Tom. :slight_smile: