Use of PD0 and PD1 for bumper switches?

Planning to add 1 (maybe 2) bumper switches (ie whiskers) to the 3pi.

Docs show that PD0 and PD1 are ‘free’ digital ports. At first I figured PD0 would be the best place to add a switch since it totally unused but now I’m wondering if using PD1 with the optional LED installed would be a better circuit for that purpose.

Do both PD0/1 have internal pull-ups so my mechanical switch would just go from being wide open or connected to ground - without adding a resistor or anything?

Would the PD1 with the LED be ‘cleaner’ or preferred in some way for an on/off switch like this? (As a side bonus it would give some visual feedback with the LED I suppose.)

Thanks for the help.


All of the digital I/O lines on the ATmega328 have optional internal pull-ups, so the best way to use your bumper switch is to connect it to a free digital I/O line (such as PD0) with the internal pull-up enabled so that the switch shorts to ground when pressed. You won’t need any additional components beyond the switch.

Things are a little more complicated if you want to use PD1. Because of the LED, PD1 has a fairly strong pull-down to ground that would overwhelm the pin’s internal pull-up, so you would need to use the bumper switch to connect the pin to VCC when it is closed. Further complicating things is the fact that the pin isn’t necessarily pulled all the way to ground; rather it is pulled down to the LED’s diode drop voltage, which can be around 1.8 V and puts the pin in an undefined digital state. Unfortunately, 1.8V is slightly over the guaranteed-low threshold for a digital I/O pin (the threshold is 1.5 V when VCC is 5 V), so when the switch is open you’d have the pin in an undefined state that could produce false positives. I think it would probably work ok if you used PD1, but you might consider removing the PC5 jumper and using that pin, or you can use a large resistor (100 K to 1 M) to pull PD1 all the way to ground.

- Ben