E-textiles & Wearables II
Class nine - 21 November 2017
Tap-Tap-Glove
I have some experience with simple arduino projects, and even if I taught myself electronics I still struggle a lot with programming. I still rely largely on the "Arduino Starter Kit" book for anything I want to make, because I can always find an example that I can modify and use for what I need to to.
This time I started from the Touch Sensor Lamp example by Scott Fitzgerald that uses the CapacitiveSensor library by Paul Badger. The sketch reads the value from an "antenna" that sense the variation of capacitance from close or touching objects and if the value goes over a specified threshold an LED turns on.
I tested it with a piece of conductive fabric that can be used as an antenna. I made some tests with bright LEDs, but turning on and off a light seemed a little boring, so I tried to mix the program with the one called Light Theremin, that uses the Tone function to generate sound over a piezo. The program I wrote maps the capacitance values to different frequencies so that you can play different tones.
I think it is quite fun, it is basically a glove that plays a sound everytime you tap on the table. In the video it works onlky by touching metal (aluminum) but if I tweak the code I can decide the exact range of values and threshold.
The code (WIP)
/* This code was created by Saverio Silli for Textile Academy 2017 www.textileacademy.org, based on the: Arduino Starter Kit example Project 13 - Touch Sensor Lamp Created 18 September 2012 by Scott Fitzgerald http://www.arduino.cc/starterKit Software required : CapacitiveSensor library by Paul Badger http://www.arduino.cc/playground/Main/CapacitiveSensor This example code is part of the public domain */ // import the library (must be located in the // Arduino/libraries directory) #include <CapacitiveSensor.h> // create an instance of the library // pin 4 sends electrical energy // pin 2 senses senses a change CapacitiveSensor capSensor = CapacitiveSensor(4, 2); // threshold for turning the piezo on int threshold = 10000; void setup() { // open a serial connection Serial.begin(9600); } void loop() { // store the value reported by the sensor in a variable long sensorValue = capSensor.capacitiveSensor(30); // print out the sensor value Serial.println(sensorValue); // if the value is greater than the threshold if (sensorValue > threshold) { // map the sensor values to a wide range of pitches int pitch = map(sensorValue, 300, 25000, 50, 4000); // play the tone for 100 ms on pin 8 tone(8, pitch, 100); // wait for a moment delay(100); } // if it's lower than the threshold else { // turn the piezo off noTone(8); } }
Files Storage
This website by Saverio Silli (based on Twitter Bootstrap) and all its content is licensed under the following license: CC Attribution-Share Alike 4.0 International.