To avoid infection from storage devices, don't execute any files from them, and configure your operating system to not do so automatically. But storage devices aren't the only threat in form of USB. For example, take a look at this USB keyboard:

"But that's not a keyboard! That's a USB thumb drive!" Are you sure? "Of course! I can tell a keyboard apart from a thumb drive when I see them!" Really? It might look like a thumb drive to you, but when you connect it to a PC, it says it's a keyboard, and the PC has no reason to believe that it is anything else.
As soon as this device is recognized as a keyboard by the operating system, it will automatically start typing. What's it typing? That's up to the one who programmed it. Common payloads are the keyboard shortcut to open a text editor, type a malicious script, save it, perform the shortcut to open a command shell and execute what it just wrote. Others are to open a web browser, enter the URL of an executable on a FTP server, download it and execute it.
The only software-method to protect you from this is to disable plug&play of USB devices. You will then have to enable any new USB device manually. When you plug in a thumb drive and it appears as a HID device, you have reason to be suspicious and can choose to not enable it.
But there are also hardware-solutions. There are USB adapter plugs which only allow certain types of USB devices to pass through. Unfortunately I have never used such a device, so I don't feel comfortable to give any specific product recommendations.