How to create your own Arduino Library

David Such
CodeX
Published in
18 min readAug 8, 2021

--

At some stage you are going to write some code that you want to package up as a library. This makes it easy for you and others to use the software, hides complexity and is a way to participate in the global maker community. There are a few exisiting guides about how to do this, we have focussed on material not covered by these beginner tutorials. A library is a collection of header (.h) and optional program (.cpp) files located in a single directory.

Sketch First

Start with a working sketch, don’t write the library until you know that your code works. Using a library can make things harder to debug, and nobody wants that! As an example to work through, we are going to create an Arduino library for the Reefwing Motor Shield (Figure 2) that connects to an UNO.

The Reefwing motor shield uses the L293B h-bridge chip and includes a voltage divider circuit to monitor the battery voltage. With LiPo batteries you don’t want to over discharge them as it can wreck the battery, or worse they can catch fire and explode!

Figure 1. Bidirectional DC Motor Control (credit).

--

--

David Such
CodeX
Writer for

Reefwing Software · Embedded Systems Engineer · iOS & AI Development · Robotics · Drones · Arduino · Raspberry Pi · Flight Control