Friday, December 9, 2011

Touch sensor on Arduino

With a task to build a table lamp under way I decided that I needed a touch sensor. Well four of them really, to control the individual place lighting. Low and behold the next day hackaday has a post on a touch sensor using the capsense library. So I hook up the circuit used with the library and write a bit of code to control and measure the sensor. But I wasn't convince by how it behaved. The circuit used tries to measures the charge rate of the capacitance provided by human touch. However I found that leakage currents in my cobbled together circuit stopped the capacitance charging even to half the supply voltage driven out an Arduino IO pin. The set up still sensed a definite and repeatable change upon touching the sensor plate but this was due to the fact that I was applying ~10V of mains pick-up to the circuit. Whilst I expect there is a way to build this circuit with less leakage and susceptibility to electrical pick up from the human user I wanted something less picky for my solution. Mainly because I only want to build it once. So back to the web.


Further research showed that most methods measure discharge of the capacitance or voltage drop of a charge capacitor switch to the sense plate. The second method gets into more low level micro controller coding than I want to. So the discharge method looked best bet.

I rigged up the circuit shown above which uses an output pin on the Arduino to charge the capacitance of the circuit through a diode, which avoids having to switch the pin to high impedance. This drive pin is set as a PWM output which provides a 490Hz drive to the circuit. The sense point of the circuit is connected to an interrupt pin on the Arduino has a resistor, ~3Mohm, connected to ground to discharge the circuit's capacitance once the supply pin is switched off. The sense plate for the test set up was a piece of painted aluminium alloy sheet with a screw holding the connection wire to it. The sense plate is connected to the circuit's sense point via a 12KOhm resistor to provide protection from ESD. It should be noted that diodes have a parasitic capacitance which can be anything from .5pF to 200nF or so depending on the type. If a diode with very low capacitance is used then an extra capacitor of a few pF connected between sense point and ground may be required. The diode I used is a 1n4148 which is a small high frequency signal diode which I would expect to have a 5 to 15pF capacitance. If a diode with large capacitance is used then the circuit changes little with the addition of the human touch capacitance.

The Arduino needs to be set up to have a change interrupt on the input sensing pin. I simply used the Arduino standard pin interrupt commands for test. The final 4 channel touch sensor for the lamp will require a port interrupt to be configured as a pro mini will be used. For more info, a code example and the circuit diagram go to Arduino Touch .

No comments:

Post a Comment