5. E-Textiles and Wearables I#

This week I made two soft sensors out of different types of conductive thread. Both are activated by pulling or tightening strings.

What I made#

pleated digital switch

Digital sensor: pleat switch#

For my digital sensor, I made a switch that closes when fabric pleats are pinched or pulled together. It’s a momentary switch if pinched together with fingers, or a toggle switch if a thread is pulled through the pleats, keeping them closed. There are three breaks in the circuit, and a row of 3 leds lights up when all three breaks are closed. Here’s an overview of the steps:

infographic of construction steps

Materials#

To make this you need:

Pressing pleats into fabric#

I folded the fabric back and forth into a mountain fold pattern, then pressed down on it with an iron, and let it cool in the folded shape. Then I threaded an embroidery needle with red embroiery floss, knotted it at one end, and passed it through the top of the fabric. folded and pleated fabric

Sewing the switch#

I sewed squares of conductive thread on the parts of the pleats that come into contact when the pleat is pinched together. This is how the switch works: - when the pleats are pinched together, the conductive squares touch each other, and current can flow through them!

On the back side of the fabric, some of the fabric squares are connected by a conductive thread - this shouldn’t be strictly necessary to allow current to flow then the pleats are pinched together, as the conductive thread is stitched through both sides of the fabric, but it reduced the amount of times I needed to cut and knot the conductive thread :)

sewing with conductive thread

Sewing the leds#

Using a needle-nose pliers, I twisted the legs of three 3mm white leds into coils. Then I sewed them onto the fabric in parallel, by sewing all the + legs together, and then sewing all the - legs together. sewing leds

When this was finished, I stitched from one side of the switch to the negative side of the leds, as both of these would be connecting to the ground pin on the Arduino.

Finishing the circuit#

Right at the end I remembered that I’d need to add a resistor in series with the leds, to limit the amount of current flowing through them, and make sure they didn’t burn out. For this I ideally wanted a resistor of a few hundred Ohms (around 200), but I was doing this part at home and the smallest value resistor I had on hand was 1000 Ohms. This still worked, although it reduced the brightness of the leds a bit - I added it to the end of the ground trace for the leds.

circuit with resistor added

I also painted over any conductive thread knots on the reverse side of the fabric with clear nail polish, to prevent the threads from fraying and coming undone. I connected alligator clips to the knots at the end of my conductive thraed traces, to interface with that Flora. adding nail polish to knots

Controlling the leds using Arduino#

This switch can be used to control the leds without an Arduino, but let’s use an Arduino anyway! For this project I decided to use an Adafruit Flora, rather than an Arduino Uno, as I had a couple of them at home, and I find them easier for e-textile prototyping, as the pins have large pads that alligator clips and clip on to easily. I used pin 6 on the Flora to control my leds, and pin 9 to control my switch. In this sketch we’re only dealing with digital data - 1s and 0s / on and off - so we just need two ‘digital’ pins. You can see a pinout diagram of the Adafruit Flora, showing which pins are which, here.

Arduino Code#

//A simple sketch to turn on and off leds, based on the example sketch DigitalReadSerial
//and adapted for use with an Adafruit Flora

int sw_pin = 9; //connect one end of the switch to pin 9
int sw_value = 0; //initialise the value of the switch - whether it's on or off - to 0
int led_pin = 6; //connect the + side of the leds to pin 6

void setup() {
  pinMode(sw_pin,INPUT_PULLUP); //On the switch pin, activate the pullup resistor! This gets rid of any noise in the system
  pinMode(led_pin,OUTPUT);
}

void loop() {
 sw_value = digitalRead(sw_pin); //read the value of the switch

 if(sw_value==1){ //when we're using a pullup resistor, the switch is 'off' when digitalread returns 1
  digitalWrite(led_pin,LOW);
  }
  else{
    digitalWrite(led_pin,HIGH); //otherwise, the switch is on. Turn the leds on!
    }
}

Uploading to the Flora#

The Flora connects to your computer with a usb to micro-usb cable. If using Windows, you’ll also need to install drivers, and add the Flora to the list of boards the Arduino software knows how to upload to. Here is a great guide to doing all of that!. when you’ve done that, go back to the Arduino IDE, and in the Tools menu, go to Board, and select ‘Adafruit Flora’. In Tools -> Port, make sure you have selected the port that your board is connected to.

When I had compiled and uploaded the sketch to the Flora, I disconnected it from my laptop and used a 2 coin cell battery holder to power it. I connected alligator clips to my conductive thread traces, and the switch works!

pleated switch steps

Analog sensor: lace-up / corset resistor#

For my analog sensor I made a variable resistor based on a corset-style laced up design.

analog sensor diagram

Tabletop prototyping#

different conductive threads and prototype sensors I started out by going through the conductive threads we had at TextileLab Amsterdam. I wanted to find out which threads were the most resistive, and so would work well in a variable resistor / potentiometer kind of sensor. I spent a few minutes taping the threads to the table, and using a multimeter to measure the resistance of each thread over a 10cm length of thread.

I then learned that someone had already measured and charted all of this already, so I stopped ಠ‿ಠ

The next step was to make a rough prototype of my design, to see if it worked before sewing anything (because nobody likes doing a bunch of sewing and then finding out that the whole design is flawed). I found some paperclips, taped them to the table, bent one end of them upwards so they would stick up from the table surface, and then tried lacing it with a couple of different threads. I was looking for a thread that would:

different ways to lace the sensor

I decided to use a stretch yarn that’s partly composed or regular yarn, but has conductive threads running through it. It’s more conductive when stretched, which is great for this project, because it meant I could adjust the resistance by tightening the lacing.

conductive yarn and sensor prototype

First fabric prototype#

Next, I moved on to a fabric prototype. I picked a shiny (and relatively stiff) black fabric to build the sensor onto, and experimented with different types of fabric loops to lace the yarn through. I liked the idea of having every component of the sensor be soft, rather than having metal loops. And it was important that these loops be conductive, as I wanted to keep the yarn completely detachable, and have other parts of the circuit connect directly to the loops.

So, I tried sewing loops out of a linen/steel thread, but that was both a bit tedious to sew, and also didn’t make a great electrical connection with the conductive yarn. Next I tried cutting small rectangles of conductive fabric and sewing them into loops, and at this point I thought I was on to a winner, as it was easy to pass the yarn through the loops, and it made a good electrical connection.

fabric loop tests

However, when I sewed a whole bunch of these fabric loops and then tested it, I found that yes, it worked as a variable resistor, but unlike with my prototype with paperclips, I couldn’t pull the thread through the loops easily to tighten it. This being a key (and fun) feature of my sensor, I decided to abandon the fabric loops, and figure out a way to make metal ones.

I did do a couple of measurements with my reject prototype, showing the variation in resistance you can get when tightening the yarn. From left to right, I tightened the yarn in stages, and on the multimeter you can see the number - resistance in Ohms - dropping, which means that conductivity is increasing, and more electricity can flow through the yarn.

testing the sensor's resistance range

Second fabric prototype#

For the final version of my sensor, I altered an element of my first rough prototype: I got more paperclips, and used a pliers and a wire snips to turn them into d-rings.

paperclip to d-ring

I put my fabric into an embroidery hoop, used two strips of masking tape to mark out the middle part of the sensor where the yarn would go. I stitched the d-rings onto the fabric, using grey embroidery floss. then I laced it up with the yarn, and it worked! Using my multimeter, I measured the rough maximum (loose yarn) and minimum (tight yarn) resistance values, as I’d need these for later (add these in!).

making of the analog sensor

Then I connected the bottom two loops on each side, by stiching a line of conductive thread between them on the back side of the fabric. Because the conductive yarn is actually a mix of conductive and non-conductive fibers, sometimes it happens that only the non-conductive fibers come into contact with the d-rings. Having the yarn connect to two loops on both the + and - sides of the sensor helps with this.

back of the sensor

How to use the sensor#

This sensor is basically a variable resistor: as the yarn tightens, or depending on how the yarn is laced, the resistance between the bottom point and the top point is different. I used my sensor to control the colour of an Adafruit Neopixel (an addressable RGB LED, but more on that later), and to do that we need to do a couple of extra things with Arduino and resistors.

Voltage Divider#

Arduino can’t measure differences is resistance. It can only measure differences in voltage. So to read data from our sensor, we use a trick called a voltage divider. This involves placing an extra resistor in the circuit.

The value of the resistor is important! My variable resistor ranges from roughly 200 Ohms to roughly 600 Ohms, depending on how tight the yarn is laced. I used a 500 Ohm resistor as my voltage divider resistor, as 500 Ohms is close-ish to the average resistance of my sensor. If one resistor is much higher than the other, e.g. I used a 10k resistor instead of a 0.5k one, then the voltage divider doesn’t work well for reading sensor data.

Want to know more about how voltage dividers work? Sparkfun have an explanation here.

Reading the sensor data with Arduino#

Arduino has an example sketch called ‘AnalogRead’ which formed the basis for my sketch. The code below is adapted from that sketch, and just reads data from the sensor, and prints it to the serial monitor every 200 ms.

//simple sketch for reading data from the soft sensor

int lace_pin = A0; // this is the pin the 'laced' sensor is connected to, an analog pin so we can read analog data
int lace_value = 0; // initialise the sensor value to 0

void setup() {
  pinMode(lace_pin,INPUT); //set the sensor pin to be an input pin, as we will read data from it
  Serial.begin(9600); //this part lets us write the sensor data to the serial monitor, so we can see what it's doing
}

void loop() {
  // put your main code here, to run repeatedly:
 lace_value = analogRead(lace_pin);

 Serial.println("the lace sensor value is: ");
 Serial.println(lace_value);

 delay(200);
}

When this is uploaded to the Arduino, click the magnifying glass icon in the top right hand corner of the Arduino IDE, or go to Tools -> Serial Monitor. Here you’ll see a stream of numbers - these are the voltages that the Arduino is reading from your sensor. What I did then was:

These values become important when we add the code for the LED!

Adding the Neopixel#

Next I added an LED to control with the sensor. For this I chose to use an Adafruit Neopixel. Neopixels are addressable rgb leds, which is a technical way of saying a) you can chain a bunch of them together but still control them individually from one Arduino pin, and b)they each have a red, green and blue led in them, each of which can be controlled separately, to create the full range of rgb colours. They’re more expensive than regular leds, and a little bit more work to use, but for some applications, they’re definitely worth it!

The Adafruit neopixel uber guide is a good place to start learning about Neopixels, but for our purposes, what’s needed is a couple of extra lines of code, and a library that you can get and install here

To control a Neopixel it needs to be connected to power, ground, and an additional Arduino pin that tells it what to do (be on or off, what colour to show, etc). I stitched the neopixel onto the fabric above the sensor, and stitched three conductive thread traces:

Here’s a kind-of-circuit-diagram to make all that a bit clearer:

kind of circuit diagram

the finished circuit

Here’s the code I used to control the Neopixel with my sensor:

//Simple sketch for controlling the colour of a NeoPixel with a soft sensor
//Contains bits from the examples AnalogRead, Smoothing, and Adafruit Neopixel Simple

//include libraries for the NeoPixel
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
  #include <avr/power.h>
#endif

//Set up a matrix for smoothing out the sensor data
const int numReadings = 5;
int readings[numReadings];      // the readings from the analog input
int readIndex = 0;              // the index of the current reading
int total = 0;                  // the running total
int average = 0;                // the average

int lace_pin = A0; //the sensor pin
int lace_value = 0;
int led_value = 0; //the colour of the neopixel (partly!)

#define neo_pin 8 //the neopixel pin

#define NUMPIXELS 1
// When we setup the NeoPixel library, we tell it how many pixels, and which pin to use to send signals.
// Note that for older NeoPixel strips you might need to change the third parameter--see the strandtest
// example for more information on possible values.
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, neo_pin, NEO_GRB + NEO_KHZ800);


void setup() {
  pinMode(lace_pin,INPUT);
//  Serial.begin(9600); //uncomment this if debugging using serial!

   pixels.begin(); // This initializes the NeoPixel library.
   for(int thisReading = 0;thisReading < numReadings; thisReading++){
    readings[thisReading]=0; //initialise the matrix for holding average values
   }
}

void loop() {
 lace_value = analogRead(lace_pin); //read the sensor value
 led_value = map(lace_value,300,500,0,255); // map the sensor value onto the brightness range of the neopixel

 //Do the averaging!
 // subtract the last reading:
  total = total - readings[readIndex];
  // read from the sensor:
  readings[readIndex] = led_value;
  // add the reading to the total:
  total = total + readings[readIndex];
  // advance to the next position in the array:
  readIndex = readIndex + 1;

  // if we're at the end of the array...
  if (readIndex >= numReadings) {
    // ...wrap around to the beginning:
    readIndex = 0;
  }

  // calculate the average:
  average = total / numReadings;
  average = constrain(average,0,255); //make sure that only values within the led's allowed range are used!

//This part is mainly for debugging, but you can uncomment it if you need! 
// Serial.print("the lace sensor value is: ");
// Serial.println(lace_value);
// Serial.print("the neo value is: ");
// Serial.println(led_value);
// Serial.print("the average value is ");
// Serial.println(average);

//This part controls the colour of the Neopixel. The function
//setPixelColor(<number_of_pixel,(red_value,green_value,blue_value))
//allows you to address different pixels, if you have more than one, 
//and to change the colour by setting separate red, green and blue values.
//Here I've set the red value to 0. The green and blue values are set so that
//the colour cycles between blue and green depending on how tight the lacing is
 pixels.setPixelColor(0,pixels.Color(0,255-average,average));
 pixels.show(); // This sends the updated pixel color to the hardware.

 //delay(300);//uncomment if debugging using serial data!
}

There’s a lot happening here! What it’s doing is:

This means that when the sensor is laced tighter, the led looks more green. When it’s looser, it looks more blue! Here it is in action:

Bonus version#

I had some conductive rubber at home, so I made a small extra version of my sensor, using conductive rubber for the lace, and metal washers as the loops. I sewed the washers onto the fabric using purple cotton thread. Ultimately I liked the look of this version of the sensor, but the conductive rubber had to be pulled very tight in order to make a good electrical connection with the washers. This could work pretty well in a tight garment, but on a standalone swatch it wasn’t so successful!

conductive rubber sensor

Drivers for Arduino clones#

For part of this week I used a Dccele Arduino clone - this is a board that closely resembles an Arduino, and uses the same software and a lot of the same electronic components. BUT using a clone, rather than an original Arduino, sometimes means you need to jump through a couple of extra hoops to get it to work. In this case, you need to download and install drivers - I got them from here. When installing the drivers, it’s important that the device (your Arduino clone) is plugged in to your computer, otherwise the driver installation will fail!