SainSmart USB Host shield for Arduino

What is this article all about?

This article explains how to run one of the example applications on the SainSmart USB Host shield on a Arduino Mega.

Another good article is

The steps to get an example running are

1. Plug in the shield to the Arduino Mega 2560
2. Git clone the Library
3. Add the library to the Arduino IDE, then restart the IDE.
4. Open an example sketch, compile and upload the sketch.
5. Plugin a keyboard, restart the Arduino, inspect the example’s output via the Serial Monitor

Detailed Explanation

The SainSmart USB Host shield contains a MAX3421E chip which allows the Arduino to act as a USB host into which you can plug in USB client devices. The shield can be plugged in to a Arduino Mega 2560. I tested it without modifying the hardware and my Arduino Mega 2560 and the SainSmart USB Host shield still work.

On the software side, the github repository conains the library including examples for the SainSmart USB host shield. To run an example, it is necessary to install the library into your Arduino IDE. First use git to checkout the library.

git clone

Open the Arduino IDE and select Sketch > Include Library > Add . Zip Library. A file/folder selector dialog opens. Point the dialog to the folder into which the repository got cloned and finish the import. Restart the Arduino IDE.

After starting the Arduino IDE, select File > Examples > USB Host Shield Library 2.0 > HID > USBHIDBootKbd. Plug a Keyboard into the USB shield, upload the sketch. Open a serial monitor from within the Arduino IDE: Tools > Serial Monitor. Reset the Arduino Mega 2560.

The serial monitor should now output some text whenever you hit a key on the keyboard.


If you get the error:¬†‘Keyboard’ not found. Does your sketch include the line ‘#include <Keyboard.h>’? you have accidently opened up an example for a board that supports USB natively. Those examples are contained under File > Examples > 09.USB. The examples under 09.USB are not the examples that work with the SainSmart USB Host shield! The working examples are located under¬†File > Examples > USB Host Shield Library 2.0.

Leave a Reply