Install Libraries

The following text is copied from, we will update this guide in the future.

Once you are comfortable with the Arduino software and using the built-in functions, you may want to extend the ability of your Arduino with additional libraries.

What are Libraries?

Libraries are a collection of code that makes it easy for you to connect to a sensor, display, module, etc. For example, the built-in LiquidCrystal library makes it easy to talk to character LCD displays. There are hundreds of additional libraries available on the Internet for download. The built-in libraries and some of these additional libraries are listed in the reference. To use the additional libraries, you will need to install them.

How to Install a Library

Libraries are often distributed as a ZIP file or folder. The name of the folder is the name of the library. Inside the folder will be a .cpp file, a .h file and often a keywords.txt file, examples folder, and other files required by the library.

Automatic installation

Starting with version 1.0.5, you can install 3rd party libraries in the IDE.

Do not unzip the downloaded library, leave it as is.

In the Arduino IDE, navigate to Sketch > Import Library. At the top of the drop down list, select the option to "Add Library''.



This library allows you to create a touch sensor using the Lithne. It is an alternative for the HardwareTouch library that had its shortcomings, and this version is based on the CapacitiveSensorDue library by Marco Lipparini.


Information from Arduino website:


Capacitive sensing may be used in any place where low to no force human touch sensing is desirable. An Arduino and the library may be used to sense human touch through more than a quarter of an inch of plastic, wood, ceramic or other insulating material (not any kind of metal though), enabling the sensor to be completely visually concealed.

A capacitive sensor covered with paper or other insulator also acts as fairly good (human touch) pressure sensor with an approximately logarithmic response. In this regard it may surpass force sensing resistors in some applications.

How it works

The capacitiveSensor method toggles a microcontroller send pin to a new state and then waits for the receive pin to change to the same state as the send pin. A variable is incremented inside a while loop to time the receive pin's state change. The method then reports the variable's value, which is in arbitrary units.

Watch a short video demonstration (YouTube)

The physical setup includes a medium to high value (100 kilohm - 50 megohm) resistor between the send pin and the receive (sensor) pin. The receive pin is the sensor terminal. A wire connected to this pin with a piece of foil at the end makes a good sensor. For many applications, a more useful range of values is obtained if the sensor is covered with paper, plastic, or another insulating material, so that users do not actually touch the metal foil. Research has shown that a small capacitor (100 pF) or so from sensor pin to ground improves stability and repeatability.

When the send pin changes state, it will eventually change the state of the receive pin. The delay between the send pin changing and the receive pin changing is determined by an RC time constant, defined by R * C, where R is the value of the resistor and C is the capacitance at the receive pin, plus any other capacitance (e.g. human body interaction) present at the sensor (receive) pin. Adding small capacitor (20 - 400 pF) in parallel with the body capacitance, is highly desirable too, as it stabilizes the sensed readings.

Library Methods

The library contains three main methods and some utility methods:

CapacitiveSensor CapacitiveSensor(byte sendPin, byte receivePin)

CapacitiveSensor creates an instance of the library (please note the capital letters, this is not the same method as below)

long capacitiveSensorRaw(byte samples)

capacitiveSensorRaw requires one parameter, samples, and returns a long integer containing the absolute capacitance, in arbitrary units. The samples parameter can be used to increase the returned resolution, at the expense of slower performance. The returned value is not averaged over the number of samples, and the total value is reported.

capacitiveSensorRaw will return -2 if the capacitance value exceeds the value of CS_Timeout_Millis (in milliseconds). The default value for CS_Timeout_Millis 2000 milliseconds (2 seconds).

long capacitiveSensor(byte samples)

capacitiveSensor requires one parameter, samples, and returns a long containing the added (sensed) capacitance, in arbitrary units. capacitiveSensor keeps track of the lowest baseline (unsensed) capacitance, and subtracts that from the sensed capacitance, so it should report a low value in the unsensed condition.

The baseline is value is re-calibrated at intervals determined by CS_Autocal_Millis. The default value is 200000 milliseconds (20 seconds). This re-calibration may be turned off by setting CS_Autocal_Millis to a high value with the set_CS_AutocaL_Millis() method.

void set_CS_Timeout_Millis(unsigned long timeout_millis);

The set_CS_Timeout_Millis method may be used to set the CS_Timeout_Millis value, which determines how long the method will take to timeout, if the receive (sense) pin fails to toggle in the same direction as the send pin. A timeout is neccessary because a whileloop will lock-up a sketch unless a timeout is provided. CS_Timeout_Millis' default value is 2000 milliseconds (2 seconds).

void reset_CS_AutoCal()

reset_CS_AutoCal may be used to force an immediate calibration of capacitiveSensor function.

void set_CS_AutocaL_Millis(unsigned long autoCal_millis)

The method set_CS_AutocaL_Millis(unsigned long autoCal_millis) may be used to set the timeout interval of the capacitiveSensor function. Re-calibration may be turned off by using set_CS_AutocaL_Millis to set CS_AutocaL_Millis to "0xFFFFFFFF".

Resistor Choice

Here are some guidelines for resistors but be sure to experiment for a desired response.

  • Use a 1 megohm resistor (or less maybe) for absolute touch to activate.
  • With a 10 megohm resistor the sensor will start to respond 4-6 inches away.
  • With a 40 megohm resistor the sensor will start to respond 12-24 inches away (dependent on the foil size). Common resistor sizes usually end at 10 megohm so you may have to solder four 10 megohm resistors end to end.
  • One tradeoff with larger resistors is that the sensor's increased sensitivity means that it is slower. Also if the sensor is exposed metal, it is possible that the send pin will never be able to force a change in the receive (sensor) pin, and the sensor will timeout.
  • Also experiment with small capacitors (100 pF - .01 uF) to ground, on the sense pin. They improve stability of the sensor.

Note that the hardware can be set up with one sPin and several resistors and rPin's for calls to various capacitive sensors. See the example sketch.

Grounding and other known issues

The grounding of the Arduino board is very important in capacitive sensing. The board needs to have some connection to ground, even if this is not a low-impedance path such as a wire attached to a water pipe.

Capacitive sensing has some quirks with laptops unconnected to mains power. The laptop itself tends to become sensitive and bringing a hand near the laptop will change the returned values.

Connecting the charging cord to the laptop will usually be enough to get things working correctly. Connecting the Arduino ground to an earth ground (for example, a water pipe) could be another solution.

Another solution that seems to have worked well on at least one installation, is to run a foil ground plane under the sensor foil (insulated by plastic, paper, etc.), and connected by a wire to ground. This worked really well to stabilize sensor values and also seemed to dramatically increase sensor sensitivity."


Lithne DMX Simple Library

This is an adapted version of the original DmxSimple library that works with the Lithne boards.

You can download the library here. It also comes with some examples of how to use it.

The Lithne DMX Shield has the dmxPin connected to D11, so call DmxSimple.usePin(D11); in your setup().

nb: This library is compatible both with Lithne and regular Arduino's, however when using a regular Arduino, you can use only up to channel 80. 

nb2 - if you have problems: The timing with this library appears to be rather critical, so critical that it may be different for different Lithne boards. In case of weird behaviour (flickering) you can alter the number of cycles that the processor idles to create the 4us delay that is used to create a DMX bit. This is found in the library and is currently 36, but used to be 35. Additionally, you may want to alter the 40 or 41 cycles used to create the frame's start bit.


This is a library that allows you to use all the pins on your Lithne (or Arduino) board as capacitive touch sensors.

Download HardwareTouch Library

See the examples for further information on how to use it.


Known Issue

Pins A11, A13, A14 and A15 do not work (native IDE pin 12-15); most likely due to the badly configured pulldown / pullup functions


As of version Lithne v0.3 SPI works out of the box! Please update to make use of SPI.