Introduction: Arduino Capacitive Sensor (Touche)

Picture of Arduino Capacitive Sensor (Touche)

The Sensor is a exact copy of the amazing Touche Sensor . Thanks a lot for sharing this tutorial!

The reason I did this instructable is that I felt it is quite complicated to change the interaction of the Touche Sensor, because the code has some dependencies and its output is directly sent to Processing (which is great and looks pretty nice, but it is difficult to change the output to do something different).

So here is my solution of the sensor which works with the bare minimum of code. I hope that you can easily add some fancy things to your capacity sensor.

Step 1: The Parts

Picture of The Parts

The Sensor is pretty cheap to build and has only 7 parts (if you don't count the Arduino).

The parts:

- 10mh Coil

- 10nf Condensator

- 100pf Condensator

- Resistor: 10k, 3.3k and 1M

- Diode 1N4148

- Arduino (which ever you like the most)

Step 2: Putting It Together & Test It

Picture of Putting It Together & Test It

For testing purpose I always use a Arduino Uno. If I solder everything up, Id like to keep it quite small. So I usually use a Arduino Mini Pro.

It is probably a bit hard to see, but the orange cable is the sensing cable.

Step 3: The Coding

Picture of The Coding

Plug the Arduino with the sensor to your computer and upload the following code:

const int STEPS = 128;
const int OUTPUTPIN = 2; // define OutputPin const int SENSORPIN_ANALOG = 0; // define Analog SensorPin const int SENSORPIN_DIGITAL = 9; // define Digital SensorPin const int TRIGGERVALUE = 400; // at what sensor value should OutputPin be triggered?

float values[STEPS]; float alpha;

int sensorValue;

void setup () { pinMode(SENSORPIN_DIGITAL, OUTPUT); pinMode(OUTPUTPIN, OUTPUT);

// initialize Timer1 with 0 (as we don't know the initial values) TCCR1A = 0; // set Timer TCCR1A register to 0 TCCR1B = 0; // set Timer TCCR1B register to 0 TCCR1A |= (1 << COM1A0); // Toggle OC1A on Compare Match. TCCR1B |= (1 << WGM12); // CTC mode Serial.begin(115200); // start Serial communication }

void loop () { getSensorValue(); }

void getSensorValue(){ sensorValue = 0;

for (int i = 0; i < STEPS; i++) { TCCR1B &= 0xFE; // turns off timer TCNT1 = 0; // resets timer counter register OCR1A = i; // sets new frequency step TCCR1B |= 0x01; // turns on timer

values[i] = values[i] * alpha + analogRead(SENSORPIN_ANALOG) * (1 - alpha); // exponential moving avg if (values[i] > sensorValue) { // finds the signal peak sensorValue = values[i]; } }

Serial.println(sensorValue); // check on the Serialmonitor your values

if(sensorValue < TRIGGERVALUE) { digitalWrite(OUTPUTPIN, LOW); } else { digitalWrite(OUTPUTPIN, HIGH); }

delay(50); // don't run too fast. Otherwise the sensor is too sensitive }


Note that you may need to adjust the 'TRIGGERVALUE' (which is defined at the top of the code) to a value which fits best for your setup. Open up the Serial Monitor, set the baudrate to ´115200´ and take a closer look at the running values while you are touching the sensor. Now you will get a feeling for the numbers and you are able to adjust the 'TRIGGERVALUE' to a nice value.


If the 'sensorValue' (coming from the analogRead from A0 = the Sensor) drops below the given TRIGGERVALUE, turn on something on digital pin 2. Otherwise just turn it off. In my case, I connected a small LED, to see the output in the real world.

Step 4: Add a Relais and a Lamp

Picture of Add a Relais and a Lamp

I connected the sensor to a Arduino Mini Pro (5V) and soldered all connection, to make it more reliable. I also connected a 9V battery to it, so that I can run the sensor without having a computer connected.

The last part is to connect something different than just the LED. I wanted to trigger a lamp. So I took a Relais and connected the Digital 2 output.

Note a Relais has 3 outputs, but you only connect two of them. Either NO & COM or NC & COM :

- NO: Normally Open >> if the Relais receives no signal, it will power the lamp

- NC: Normally Closed >> if the Relais receives no signal, it will keep the lamp off

Now we can put the sensor where ever we want to create some nice interactive projects ?

Comments

About This Instructable

683views

22favorites

License:

Bio: I am a interaction design student based in Berlin. I like to share my ideas and work on projects with other people.
More by dSteinel:Arduino Capacitive Sensor (Touche)Japanese Bed Style
Add instructable to: