{"id":47,"date":"2005-05-29T08:55:51","date_gmt":"2005-05-29T13:55:51","guid":{"rendered":"http:\/\/www.tigoe.com\/pcomp\/code2\/category\/arduinowiring\/47"},"modified":"2008-02-18T07:22:21","modified_gmt":"2008-02-18T12:22:21","slug":"qprox-capacitive-touch-sensors","status":"publish","type":"post","link":"https:\/\/www.tigoe.com\/pcomp\/code\/arduinowiring\/47\/","title":{"rendered":"Qprox Capacitive Touch Sensors"},"content":{"rendered":"<p>For those applications where you want to sense a person touching an object, but can&#8217;t use a switch or a force-sensitive resistor, charge-transfer touch sensors can often be very useful.  The one used in this example is made by <a href=\"http:\/\/www.qprox.com\">Quantum<\/a>, and it&#8217;s very simple to use.<br \/>\n<!--more--><\/p>\n<p>These sensors take advantage of the fact that objects and people always carry an electric charge, and that every object or person has a slightly different charge.  When two objects or people touch, they exchange electric charge, so that they end up with an equal charge.  Charge-transfer sensors detect that charge as we touch an object to which they&#8217;re attached. A conductor is attached to the object or embedded in it, and when a person comes close to the sensor, charge is transferred, and the sensor reads it.<br \/>\nThese sensors work best as touch sensors, with the conductor embedded just below the surface of the object &#8212; for example, with the sensor underneath a cloth covering, cardboard covering, etc.  The closer you can put the conductor to the chip that reads it, the better.<br \/>\nThe  <a href=\"http:\/\/www.qprox.com\/products\/touch.php\">QT11x family<\/a> of sensors are all similar in that they require little external circuitry, and put out a digital signal when they detect the presence of a person or object. For this example, I used a QT113, but you can use the QT113H with the same circuit.<br \/>\nNote: Digikey carries these sensors in the US, so there is no need to order directly from England.<br \/>\nThe wiring for the QT sensors is as follows:<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/tigoe.net\/pcomp\/img\/qprox.jpg\" alt=\"QT113 schematic\" \/><\/p>\n<p>The connecting wire between the sensor and the pin is sensitive to touch as well.  To prevent the wire from triggering a reading, a wire with a shield. Coaxial cable or any shielded speaker or video cable will do.  Ground the shield to your circuit ground.<\/p>\n<p>The sensor can be attached to pin 6 or 7 of the QT113, it makes no difference.<\/p>\n<p>The option pins (pins 3 and 4) allow you to set the sensor to behave differently, depending on whether they are tied to power or ground. In the configuration above, the QT113H will output high when it detects an object, indefinitely.  The QT113 will do the opposite, going low when there&#8217;s contact, and high when there&#8217;s no contact.  For details on other modes of operation, see the data sheet.<\/p>\n<p>The gain pin (pin 5) controls the sensitivity of the sensor.  Attach it to power (as above) for high sensitivity, to ground for low sensitivity.<\/p>\n<p>I have had greatest success using a copper mesh screen as a sensor, but many other metal forms could be used.  See the data sheet for notes on electrode geometry for more tips on this.<br \/>\nBecause the QT sensors put out a digital signal, reading them is just a matter of reading an input pin.  On the BX-24, the code would look like this (sensor attached to pin 12):<\/p>\n<pre>Sub Main()\r\n   dim qproxVar as byte\r\n\r\n   call delay(0.5)\r\n   do\r\n      qproxVar = NOT getPin(12)\r\n      ' use the line below instead of the line above if you're using a QT113H:\r\n      ' qproxVar = getPin(12)\r\n      debug.print \"Qprox = \"; cstr(qproxVar)\r\n   loop\r\nend sub<\/pre>\n<p>On a PIC using PICBasic Pro, the following will work (sensor attached to portb, pin 0):<\/p>\n<pre>input portb.0\r\nqproxVar var byte\r\n\r\nMain:\r\n  qproxVar = NOT portb.0\r\n  ' use the line below instead of the line above if you're using a QT113H:\r\n  ' qproxVar = portb.0\r\n  serout2 portc.6, 16468, [\"qprox = \", DEC qproxVar, 10, 13]\r\ngoto main<\/pre>\n<p>Here&#8217;s an example in the Wiring syntax, tested on an Arduino board:<\/p>\n<pre>\r\nint QTouchPin = 9;    \/\/ connected to the output of the QT113\r\nint LEDPin = 8; \r\n\r\n\/\/Function prototype:\r\nvoid blink(int howManyTimes);\r\n\r\nvoid setup() {\r\n  pinMode(QTouchPin, INPUT);\r\n  pinMode (LEDPin, OUTPUT);\r\n  blink(3);\r\n}\r\n\r\nvoid loop() {\r\n  \/\/ read the Qtouch pin, and set the LED pin to the opposite value:\r\n  digitalWrite(LEDPin, !digitalRead(QTouchPin));\r\n  \/\/ for a QT113H, use the following line instead:\r\n  \/\/digitalWrite(LEDPin, digitalRead(QTouchPin));  \r\n\r\n} \r\n\r\n\/\/ Blink the reset LED:\r\nvoid blink(int howManyTimes) {\r\n  int i;\r\n  for (i=0; i&lt; howManyTimes; i++) {\r\n    digitalWrite(13, HIGH);\r\n    delay(200);\r\n    digitalWrite(13, LOW);\r\n    delay(200);\r\n  }\r\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>These sensors work best as touch sensors, with the conductor embedded just below the surface of the object &#8212; for example, with the sensor underneath a cloth covering, cardboard covering, etc. The closer you can put the conductor to the chip that reads it, the better&#8230;.  For this example, I used a QT113, but you can use the QT113H with the same circuit.Note: Digikey carries these sensors in the US, so there is no need to order directly from England.The wiring for the QT sensors is as follows: The connecting wire between the sensor and the pin is sensitive to touch as well.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9,11,10],"tags":[],"class_list":["post-47","post","type-post","status-publish","format-standard","hentry","category-arduinowiring","category-BX-24","category-picbasic-pro"],"_links":{"self":[{"href":"https:\/\/www.tigoe.com\/pcomp\/code\/wp-json\/wp\/v2\/posts\/47","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tigoe.com\/pcomp\/code\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tigoe.com\/pcomp\/code\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tigoe.com\/pcomp\/code\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tigoe.com\/pcomp\/code\/wp-json\/wp\/v2\/comments?post=47"}],"version-history":[{"count":0,"href":"https:\/\/www.tigoe.com\/pcomp\/code\/wp-json\/wp\/v2\/posts\/47\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tigoe.com\/pcomp\/code\/wp-json\/wp\/v2\/media?parent=47"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tigoe.com\/pcomp\/code\/wp-json\/wp\/v2\/categories?post=47"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tigoe.com\/pcomp\/code\/wp-json\/wp\/v2\/tags?post=47"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}