# Switch a custom Arduino between wired and wireless connection

I have custom 5V 16MHz Arduino that runs grbl and I was hoping to use one of the HC-05 bluetooth modules to control it wirelessly. This Arduino can be connected to a USB port through a FTDI chip. I'd like this to work with either of them and not both of them. This works for the most part and here is the 'truth table' I've experienced:

USB  Bluetooth  Works over  Works over
ON   ON         USB?        Bluetooth?
---  ---------  ----------  ----------
Y    Y          N           Y
Y    N          Y           N
N    Y          N           Y


I'm guessing when both are ON the USB does not work because they both share the same RX and TX lines of the Arduino and it seems priority is being given to the bluetooth connection. Is there a way such that when the USB cable is plugged in to the host PC the bluetooth module cannot be used and priority is given to the wired connection?

• So you have a "custom arduino", and we should guess for you how it was built and what features it has and how to access them? Sep 9 '16 at 11:54
• Its an Arduino Uno R3 clone essentially except that that USB to UART is done via a FT232 FTDI chip rather than the atmega16u2 (I guess its more like the Arduino Nano than the Uno). The board can be programmed via the RX, TX and DTR lines running out of the FTDI chip and using the Arduino IDE with Uno selected as the programmer. The digital outputs are connected as per the grbl's connectivity guide has mentioned in their wiki. Sep 9 '16 at 12:13
• The Arduino designs typically have a resistor between the USB serial and the MCU to allow something else to drive data in; you seem to want the opposite behavior, which will be difficult - you cannot just move the resistor to the bluetooth unless you can get the USB serial to tristate its TX line when there is no host - you may well end up having to add a multiplexer and logic to control it. Sep 9 '16 at 13:17
• Thanks @Chris! I'm thinking I could use a MOSFET switch such that when the USB is plugged in supply to the Bluetooth module gets cut off. There is another 5V on board anyway that powers the atmega and the motor driver chips. Possibly something like this- i.imgur.com/DdaJqfo.png Sep 10 '16 at 14:38
• De-powering devices is not usually a proper way of de-selecting them - most modern ICs have protection diodes that are stressed if an I/O pin is raised above the supply pin. If you are going to pursue that path anyway, at least place a resistor to limit the current. It's probably better to use an actual multiplexer though. Sep 10 '16 at 17:16

## 3 Answers

Following Chris' suggestions, here is a multiplexer solution that I intend to try out. When the USB is unplugged, the select lines are low and the Y0 lines are selected which is the BT module. When the USB cable is plugged in, the select lines go high and the FTDI chip gets selected. VBUS and 5V are two separate 5V sources. Only the FTDI gets powered from the USB bus.

ADDED: While I was at it, I thought I could turn off and isolate the BT module entirely when the USB is plugged in. Used a p-mosfet which can handle about 130mA which is sufficient since the BT module itself does not consume more than 50mA.

• You may not need to switch the Arduino's transmit line if having both interfaces receive its transmissions is acceptable. Also, since the DTR is coupled to reset with a capacitor, you may be able to just use a capacitor for each, if you can be sure that the unused one will not cause spurious reset-inducing transitions. But those are optional simplifications - you can design the board with switches and provide optional bypass paths around them to experiment with. Sep 11 '16 at 15:24
• Let me experiment with this setup for now. Good point about the DTR being connected to Arduino's RESET via a capacitor. I missed mentioning that the capacitor is present on the Arduino side and the outputs from the FTDI-DTR or the BT-STATE multiplexers eventually connect to one side of that 01.u cap. Thanks again for the idea! Sep 11 '16 at 15:48
• @electrophile please could you reupload the image? Dec 11 '17 at 10:34

When USB cable is plugged into host PC, your port will see VBUS=5V. If no cable, VBUS=0V. You can feed this signal into one of GPIO (with proper voltage translation, resistor divider should be OK), and use the logic signal to switch between USB and BT (turn BT off).

• And how do your propose to "turn BT off"? Sep 10 '16 at 2:07
• I don't know. The OP presented a table making an impression that he has apparently independent control for both interfaces as ON or OFF. Maybe using another GPIO to disable the BT module? Sep 10 '16 at 2:38
• What OP presented is a table of their experience, which seems to be caused by the resistor in the stock Arduino design, and is contrary to their wishes. Sep 10 '16 at 3:17

There is one option also if you want to use two UART in Arduino there are support of Softwareserial() which library help to create you second uart. then you can use both USB and Blutooth in single time and easy way without changes in hardware. please read how o use Softwareserial() library and which pins are supported.

• I think I've mentioned that the board runs grbl which connects via the Arduino RX and RX. Also both the FT232 and Bluetooth eventually talk to one program which is grbl. Having two open serial communication methods that can be operated at the same time would be disastrous. This also means that I'll need to tweak the grbl code itself which is not what I want at all. Sep 12 '16 at 11:25