Presence and pressure sensor


Contents

Introduction

Resistive pressure sensors are very popular in e-textiles as they are easy make and use. However, with some very small modifications, many resistive pressure sensors can also be used as capacitive distance sensor, allowing not only to react when the user touches the fabric but also sense that the user is about to touch.

A small demo can be seen at https://www.youtube.com/watch?v=3W4-QxlnX-U.

A presentation of this post is available here: pressure_and_presence_sensors_in_textile_2017-2018.

Theory of resistive pressure sensors

Resistive pressure sensors usually consist of 3 layers: one layer of pressure resistive (piezo-resistive) material sandwiched between two layers of conductive material.

You can think of the pressure sensitive material as a material with lots of resistors in parallel. If the material is compressed, some of the resistors get local short-circuits, which lowers the overall resistance.

Note that the actual structure is usually more foam like:

Using resistive pressure sensors

To measure the resistance of such a sensor, the sensor is usually used together with a fixed resistor to make a resistive voltage divider. Image below shows the equivalent circuit when not pressed (left) and when pressed (right).

Many microcontrollers these days (including ATmegas in Arduino and Freescale Kinetis MK20 in Teensy 3.2) have built in pull-up resistors of about 35 kOhm on the analog inputs. By default these are off but they can be switched on in Arduino with pinMode(A0, INPUT_PULLUP). The circuit above then becomes similar to the one below, where the grey parts are actually inside the Arduino / Teensy.

From pressure sensor to distance sensor

If we modify the circuit above a little by connecting the bottom part of the sensor not to ground but to a digital I/O pin, we can not only use the sensor as resistive pressure sensor, but also as capacitive distance sensor. The circuit then becomes like this (left: circuit in resistive pressure sensing mode, right: circuit in capacitive distance sensing mode):

The code in the video at the beginning of this post does just that: it rapidly switches back and forth between resistive sensing to get pressure information and capacitive sensing to get distance information.

Note that the capacitive sensing here is working differently than the often used CapacitiveSensor library from Arduino. The CapacitiveSensor library requires an external resistor and uses a very different method to measure capacitance. Take care not to mess these two up, since hardware for CapacitiveSensor library does not work with the software for this blog post and vice-versa.

Making a pressure sensor

Materials

To make a textile pressure sensor you need the following materials:

Note that Arduino boards are much slower and touch sensing is more noisy on these boards compared to Teensy.

In the video above I’ve used Multicomp ESD foam, Ripstop fabric from Sparkfun and a Teensy 3.2. If your using different pressure sensitive material, first check the resistance in not pressed form (should be between 20 kOhm and 100 kOhm) and in pressed form (should be between 0 Ohm and 10 kOhm).

See http://etextile-summercamp.org/2017/summercamp/hardsoft-connections/ for tips on how to connect conductive fabric / conductive thread to electronic components.

Sewing

Place the stripped copper wire on top of the conductive fabric and fixate it with a few stitches. These will be used as electrodes.

Sew electrodes to the non-conductive fabric:

Put the pressure sensitive material between the two layers of conductive fabric and sew them together. Make sure not to apply much pressure as that will reduce the sensitivity of the pressure sensor (so no machine sewing!). Also be careful to stitch only on the outside as the ripstop conductive fabric easily frays when pierced and can make a short from one side to the other.

Connecting to your Arduino board

Solder pin headers to the ends of the copper wire. Alternatively, you can use an alligator clip to connect the copper wire to a jumper wire.

For Arduino boards: connect one wire to an analog input (for example A0) and the other wire to a digital pin (for example pin 2).

For Teensy boards: connect one wire to pin 15 (must have touch input) and the other wire to another digital pin (for example pin 16).

Software

  • Download TouchLib (https://github.com/admarschoonen/TouchLib)
  • Install as a library (Sketch -> Include Library -> Add .ZIP Library…)
  • Open example 00 (File -> Examples -> TouchLib -> Example00SemiAutoTuning)
  • Upload the code
  • Open Serial Monitor (Tools -> Serial Monitor)
  • Set baudrate to 115200 baud (pull down button at lower right of window)
  • Select “no line ending” (pull down button at lower right of window)

You should now see the following text:

Welcome to the TouchLib tuning program.

How is your system powered:
a. Battery only
b. Power supply WITH earth connection CONNECTED TO GND.
c. Power supply WITHOUT earth connection (floating ground).
d. Mixed: sometimes system is powered by battery, sometimes by a suppy with floating ground.

Options a and b allow to use capacitive distance sensing. Options c and d use extra filtering for more robust touch / no touch
detection but will not work well for distance sensing.

Enter your choice (a, b, c or d):

Answer a by typing ‘a’ (without the quotes) in the input bar at the top and press Send.

How many sensors do you want to tune? (1 – 6)

For Arduino: answer 3 (1 resistive sensor + 2 capacitive sensors; for technical reasons we need at least 2 capacitive sensors here so we’ll just add a dummy sensor).
For Teensy: answer 2 (1 resistive sensor + 1 capacitive sensor; no dummy sensor required).

First we need to know what type of sensors the system has and to which pins they are connected.

Is sensor 0 a capacitive sensor using CVD method or a resistive sensor using analogRead() method? Enter c for capacitive using CVD or r for resistive:

For Arduino: answer ‘c’ for capacitive sensor using CVD.
For Teensy: answer ‘t’ for capacitive sensor using touchRead().

Which analog pin is sensor 0 connected to?

For Arduino: answer ‘A0′.
For Teensy: answer ’15’.

Is sensor 1 a capacitive sensor using CVD method or a resistive sensor using analogRead() method? Enter c for capacitive using CVD or r for resistive:

Answer ‘r’ for resistive.

Which analog pin is sensor 1 connected to?

For Arduino: answer ‘A0′.
For Teensy: answer ’15’.

Which digital pin is the resistive  sensor also connected to (used as ground pin)?

For Arduino: answer ‘2’.
For Teensy: anwer ’16’.

The following questions are only asked for Arduino:

Is sensor 2 a capacitive sensor using CVD method or a resistive sensor using analogRead() method? Enter c for capacitive using CVD or r for resistive:

Answer ‘c’.

Which analog pin is sensor 2 connected to?

Answer ‘A1’

Next the software needs to tune the sensors. For that, first disconnect the power adapter of your laptop as (ungrounded) adapters are known to be very noisy for capacitive sensors.

Next step is to tune the sensors.
Performing noise measurement for all sensors. Make sure to not touch any sensor. Enter y to start the noise measurement.

Answer ‘y’.

It then prints out the thresholds it found for noise measurement. Next step is to tune the capacitive touch sensor:

Performing touch measurement for capacitive (CVD method) sensor 0. Make sure to touch and hold the sensor, then press y to start the touch
measurement.

Lightly touch the sensor (for example with only 1 finger, or hoover over the sensor with your whole hand) and answer ‘y’ while doing that.

It then prints out the thresholds it found for a light touch. Next step is to tune the capacitive touch sensor for full scale:

Performing maximum range measurement for capacitive (CVD method) sensor 0. Make sure to cover and hold the sensor with as many fingers as will
fit or with your whole hand, then press y to start the touch measurement.

Touch the sensor with your whole hand and answer ‘y’ while doing that.

It then prints out the thresholds it found for a full touch. Next step is to tune the resistive sensor via a similar procedure. Press the sensor lightly and answer ‘y’, followed by pressing the sensor as hard as you can and answering ‘y’.

After that, for Arduino one more tuning step is required, which is to tune the dummy sensor. For that, stick a copper wire in analog input A1 and answer the questions by pressing 2 x ‘y’.

Tuning is now finished. By pressing ‘y’, the software will print out a new Arduino program that is tuned for your sensor. Copy / paste that code as a new sketch and upload it to your board. Next, open Serial Monitor again and play with your sensor. You should see a bar with dashes (‘-‘) for the capacitive distance sensor and a bar with equal signs (‘=’) for the resistive pressure sensor.

Making the sensor sensitive to only one side

Since capacitive sensors don’t know from which sides they are approached, it is often difficult to use them in clothing. A way to improve that is to add an extra layer of conductive fabric to function as a guard underneath the sensor and connect it an opamp with 1 x gain. The total stack-up will then be like this:

The circuit should be modified like this:

The board view should be like this:

Note that the wires from the sensor are also functioning as capacitive sensor. Therefore these wires should be replaced with 2 coax cables, where the outside of both cables is connected to the guard and the inside is used to connect the Arduino to the sensor.

Leave a comment