Home     Contact     Projects     Experiments     Circuits     Theory     BLOG     PIC Tutorials     Time for Science     RSS     Terms of services     Privacy policy  
 Home      Projects     Experiments     Circuits     Theory     BLOG     PIC Tutorials     Time for Science   

16 June 2011
Author: Giorgos Lazaridis
10 Buttons PIC Touch-Pad with BCD Output

I prototyped the circuit on a PCB instead of a breadboard

I made this circuit, because i faced several problems with the touch-pad for my keycode doorlock project. I tried many different touch-pad designs, yet all had problems. Designing a touch-pad is not a simple thing after all. There are several considerations to take into account, and as i found out (the hard way) experience is mostly needed. So, here is one touch-pad that works and you can use it as-is for your designs.

The Circuit

The fundamental rule when designing a touch-pad is this: Keep the wires as close as possible. When i designed my keycode doorlock project, i had only one PIC to handle everything including the touchpad. But the PIC was hidden inside the door, so i had long wires (about 10-15cm) to connect the pads with the PIC. That was a bad idea. So, i came to the conclusion that the touchpad must have a dedicated PIC on-board to minimize the wire length. And here is the circuit: (as always, click to maximize the picture)

The circuit is straight-forward. The 16F1937 has 16 inputs for the capacitance module, so you can use whichever input you want. R1 is 10 KOhms and R2 is 330 Ohms.

The Code (updated at 5/8/2011)

It happens... I totally forgot to upload the code, until someone asked me. Luckily i had the same code already uploaded for my keycode lock hack, in which i use this very same circuit. So:

 10 Buttons PIC Touch-Pad with BCD Output - Assembly listing - V1.0

 10 Buttons PIC Touch-Pad with BCD Output - Hex file - V1.0


I could not prototype this circuit on a breadboard, so, i had to make a PCB to test it. I usually do not upload PCBs because i do not know how to design an error-free PCB. But this time, i am pretty much sure that this PCB has no significant errors.

 PCB Top Side

 PCB Bottom Side

As you will notice, the PCB is double-sided. The top side has the pads and the grounding layer, and the bottom side has the PIC along with the connection pads. And as you are also about to notice, is that the pads for the PIC are SMD. BUT, it happens that i did not have this PIC in SMD package. So, i did something that i use to do, when i come across such situations. I bend the pins in such way that i can solder the DIL package as if it was SMD. It is not a very good technique, but it is simple and it works. After all, this is just a prototype to see if the PCB works. I will order some SMDs for future works.

This is the top side of the PCB This is the bottom side of the PCB The package of the PIC is DIL
I bended the pins to solder it as SMD This is the PCB with the PIC soldered I plan to cut or bend the unused pins...

The top side with the pads has also a grounding layer. For technical reasons i have this region filled with hatch pattern instead of being solid. A solid area will also work. Notice that at the bottom left corner, there is one hole. This hole connects the top and bottom grounding layers together with a wire. The hole is larger than actually needed, because i also used this hole to hold the PCB during etching.

At the bottom side i connected the ground pad to the grounding layer. This way, the top and bottom grounding layers are both connected with the ground of the power supply. Omitting the top grounding layer or leaving it unconnected (floating) will result in malfunction. The bottom grounding layer is not that important, but it is good to exist.

The supply ground is connected with the bottom side grounding layer The top-side grounding layer is connected with he bottom side grounding layer via the bottom left hole

And here are the PAD I/Os

Insulating the touch-pads

I used thick tape to insulate and elevate the touch-pads. There are 3 reasons for this step: First, the idea of a touch keypad is that the touch-pad will be behind a cover with the buttons artwork. So, the pads must touch the artwork surface tightly, something that a double sided tape can do very good. Second, there must be a gap between the grounding layer and the artwork surface. The air has very small dielectric constant, and it will help to "separate" the touch buttons between each other, that is why the tape must be thick. And third, each touchpad on the top layer has a via to connect it with the bottom layer. This via has a thin layer of solder to hold the wire. So, the pads must be elevated a little bit otherwise they will not touch the artwork surface. Here is how i do it:

I use 1mm thick double-sided tape. I cut rectangular pieces same size as the pads. I did this for all 10 buttons. Notice the gap between the PCB and a piece of wood

The next step is to remove the cover of the double-sided tape and stick the PCB on the artwork surface. I will do this when i finally decide what this artwork will be. In the meanwhile, i will test it as-is. The artwork that i will use has 2 layers. The first layer is a 4mm semi-transparent acrylic glass, and the second layer is a thin transparent film laser printout with the actual artwork printed on it:

And here is the artwork in gif format and original format

 The artwork

Does it works?




  Email (shall not be published)


Notify me of new posts via email

Write your comments below:
BEFORE you post a comment:You are welcome to comment for corrections and suggestions on this page. But if you have questions please use the forum instead to post it. Thank you.


  • At 7 June 2015, 8:55:09 user lalitha wrote:   [reply @ lalitha]
    • place give me this circuit pcb

  • At 15 May 2014, 12:51:12 user Sanya wrote:   [reply @ Sanya]
    • Hi!

      It's a wonderful site.
      I'm working on a 8 button touch switch, and found this page. I started my project guided by microchip documents, but examined your code too. I have a question. I have seen you set the ADC clock in your code, but afaik there is no conversion happening. The input just serve as the rc ozcillator capacitance. Can u explain me the reason of the ADC clock set in your code?
      Thank you.

  • At 23 September 2013, 10:21:06 user Giorgos Lazaridis wrote:   [reply @ Giorgos Lazaridis]
    • @sri harshru If you read the first 15 words of this article you will find it out!

  • At 23 September 2013, 7:34:45 user sri harshru wrote:   [reply @ sri harshru]
    • Hi....
      Can i know the application of this project like for what purpose this is used.i need its application

  • At 29 January 2013, 7:13:15 user Giorgos Lazaridis wrote:   [reply @ Giorgos Lazaridis]
    • @Rogerio Francisco no this is the way it works. Higher-priority pads will block lower priority ones - this project does not have multitouch function. Always the highest priority pad will be sensed as a touch.

  • At 26 January 2013, 1:06:50 user Rogerio Francisco wrote:   [reply @ Rogerio Francisco]
    • Hello Mr. Lazarids. I have been following your project for a long time, I could see that there must be some error in your code, because there are some pads to being touched and block the others and there are some pads that do not block other pads, doing that more than one pad is touched, there is something wrong with your code or even the code that you posted is not the same as you used for testing, thanks for listening and once again congratulations for your job.

  • At 12 January 2013, 8:56:05 user Giorgos Lazaridis wrote:   [reply @ Giorgos Lazaridis]
    • @sri harsha you can upload them in a free image hosting site and post me the links

  • At 12 January 2013, 7:35:10 user sri harsha wrote:   [reply @ sri harsha]
    • sorry sir...pls i need the answers for all those questions especially for the MPLAB 8.8 version there is no case sensitive option for that thing.I have taken the screen shot for the proof so pls tell me how to send the image....

  • At 11 January 2013, 9:58:42 user Giorgos Lazaridis wrote:   [reply @ Giorgos Lazaridis]
    • @sri harsha Spamming the inbox will not offer me more free time to answer all comments and posts.

      To reduce sensitivity you need to change parameters PressThreshold_H an PressThreshold_L

  • At 7 January 2013, 11:37:18 user sri harsha wrote:   [reply @ sri harsha]
    • thank you sir,can i know how to reduce the sensitivity in your code it is sensing more than 10mm so i need to reduce it can u pls suggest me....

  • At 7 January 2013, 5:33:43 user Giorgos Lazaridis wrote:   [reply @ Giorgos Lazaridis]
    • @sri harsha Then maybe you should move to MPLAB 8.8? I have the 8.8 and there is definitely the case sensitive option:

  • At 7 January 2013, 5:04:04 user sri harsha wrote:   [reply @ sri harsha]
    • i saw your MPlab introduction.in 8.66 veersion i did not get the case sensitive option so please can you send me the compiler

  • At 6 January 2013, 12:54:22 user Giorgos Lazaridis wrote:   [reply @ Giorgos Lazaridis]
    • @sri harsha First you need to deactivate the case sensitive option. Google to find where you can locate it

  • At 2 January 2013, 9:41:00 user sri harsha wrote:   [reply @ sri harsha]
    • hi....
      i am using the MP lab 8.66 version i did not see any change for the case sensitive option i this can you now atleast help me now so sort the error in your own code.....i dont have any solution other than using your code so pls help me......:(

  • At 2 January 2013, 9:22:51 user Giorgos Lazaridis wrote:   [reply @ Giorgos Lazaridis]
    • @sri harsha you have to have one space for the include code, it cannot start from col 1. Check this first. Also, try to put your code not on the desktop, rather in a C:something directory, where the user name is not part of the directory

  • At 2 January 2013, 6:45:54 user sri harsha wrote:   [reply @ sri harsha]
    • hi....
      i am getting this error after compiling the code of yours..
      (Error [109] C:Documents and SettingsAdministratorDesktopsencode.asm; 2.17 #include syntax error)....
      what is the problem pls let ne know

  • At 20 December 2012, 15:23:05 user Giorgos Lazaridis wrote:   [reply @ Giorgos Lazaridis]
    • @sri harsha dude, you are in a need but you do not read. You can download it from this very page. Download it! The code is online

  • At 20 December 2012, 11:33:22 user sri harsha wrote:   [reply @ sri harsha]
    • hi,
      can you please send me the C code for this circuit i dont know how to fix the timer pls sir......i am in need ...:)

  • At 20 November 2012, 13:06:03 user Giorgos Lazaridis wrote:   [reply @ Giorgos Lazaridis]
    • @sandy this particular cannot do it. you need to change it

  • At 20 November 2012, 7:15:55 user sandy wrote:   [reply @ sandy]
    • can your circuit work for values 0 to 15 please let me know n also send me the tips to code your circuit as i am a fresher

  • At 23 July 2012, 19:35:59 user Giorgos Lazaridis wrote:   [reply @ Giorgos Lazaridis]
    • @Rogério Francisco sorry i cannot provide circuits on demand or code altering.

  • At 23 July 2012, 0:24:59 user Rogério Francisco wrote:   [reply @ Rogério Francisco]
    • Dear Giorgos, i´m trying to do a circuit with 16 buttons and bcd outuput like yors, but I could not understand his reasoning for the configuration of register CPSCON1 what values %u200B%u200Bshould I use to the other six capacitance inputs. Thanks.

  • At 16 July 2012, 17:33:22 user Rogério Francisco wrote:   [reply @ Rogério Francisco]
    • Dear Giorgos, Thanks for the tips, it worked nice, now i´m gonna play to your code.

  • At 16 July 2012, 16:49:47 user Giorgos Lazaridis wrote:   [reply @ Giorgos Lazaridis]
    • @Rogério Francisco remove the "case sensitive" from the MPLAB compiler. Check out this:

  • At 16 July 2012, 0:43:53 user Rogério Francisco wrote:   [reply @ Rogério Francisco]
    • Hi Giorgos! I tryed to rebuild your code but the MPLAB reported many erros i´d like to know if a could send to you the list of erros, becouse i would like to change your code to use the 16 buttons, how can i do to send you the list of errors?

  • At 13 July 2012, 18:27:59 user Giorgos Lazaridis wrote:   [reply @ Giorgos Lazaridis]
    • @vishal gudla yu may use the forum for your questions.

  • At 13 July 2012, 14:40:55 user vishal gudla wrote:   [reply @ vishal gudla]
    • @ Giorgos Lazaridis : i have few queries so can i have ur email so that i can discuss with u

  • At 26 June 2012, 5:14:49 user Giorgos Lazaridis wrote:   [reply @ Giorgos Lazaridis]
    • @Juan M. Nuncio i usually do non modify circuits or projects. But i'm preparing this one for a kit. Hopefully it will be ready before the end of the world this year. Along with the kit i will release the code and the PCB design. It might take longer though.

  • At 25 June 2012, 21:17:06 user Juan M. Nuncio wrote:   [reply @ Juan M. Nuncio]
    • This is exactly what I am looking for (somewhat). The two things I need that you don't address are:
      1) serial communications to minimize the number of pins being used by the receiving circuit (i.e. just one pin for the data instead of 4 pins when you use BCD.
      2) A "Data_Valid" signal on another pin to signal the using circuit that the data at the serial input to the circuit is ready to be read. This is useful in interrupt driven ISR instead of having to poll when data has changed from 0 to a valid BCD value.
      I am a C programmer and will try to modify your ASM code to do what I need but it would be safer to have the original author do this.

      Thanks so much for all your work and your excellent videos.


  • At 7 May 2012, 15:32:26 user Giorgos Lazaridis wrote:   [reply @ Giorgos Lazaridis]
    • @Rogério Francisco The first occurrence in software is recognized as touched. I have another software for multitouch

  • At 7 May 2012, 13:13:17 user Rogério Francisco wrote:   [reply @ Rogério Francisco]
    • Hi, Giorgos. what happens if I press two buttons at the same time.

  • At 7 May 2012, 4:55:24 user Giorgos Lazaridis wrote:   [reply @ Giorgos Lazaridis]
    • @Evanildo A Costa hello Evanildo, you can download the code from my site, click on the download link under the "The Code (updated at 5/8/2011)"

  • At 7 May 2012, 2:20:32 user Evanildo A Costa wrote:   [reply @ Evanildo A Costa]
    • Hello, I'm Brazilian. and living in Brazil.
      Their design and very interesting, is that you can send me your code.
      I like to do something similar.
      sorry I'm using an electronic translator.
      my email is digitalgames@hotmail.com

      thank you very much

      My name is Evanildo.

  • At 1 April 2012, 19:18:34 user Giorgos Lazaridis wrote:   [reply @ Giorgos Lazaridis]
    • @Rogério Francisco no sorry, i don't

  • At 1 April 2012, 18:21:50 user Rogério Francisco wrote:   [reply @ Rogério Francisco]
    • Hi!. First of all, i found you project fantastic, but do you have any example for 10 or 16 inputs to conect 10 or 16 leds.

  • At 17 March 2012, 22:15:13 user Giorgos Lazaridis wrote:   [reply @ Giorgos Lazaridis]
    • @Ion this has gone even further now... steps above challenge... now it is pure curiosity... i'm very curious to see what those people in microchip have done wrong. The cap sense module works like charm

  • At 17 March 2012, 8:48:51 user Ion wrote:   [reply @ Ion]
    • @Giorgos Lazaridis
      It will be a big one. Before you start, visit this and you will find out by your self http://www.microchip.com/forums/f227.aspx
      Also do a short Google on microchip pic18f mtouch projects
      You will find out that they are thousands of pages about Pic18f, pages about mtouch - mostly emphasizing the feature, but curious ... no projects, or failed projects with peoples asking for help.
      Good luck and let me know your achievements.
      Keep in mind that any body can make it working, BUT the challenge is the sensing distance. Never saw one done yet.Everybody wants to have 2-3 mm plastic in top or touch buttons, the plastic cover of the box. Nobody did it yet.

  • At 17 March 2012, 7:12:12 user Giorgos Lazaridis wrote:   [reply @ Giorgos Lazaridis]
    • @Ion i will try this for sure, since this has gone above the step of curiosity, it is rather a challenge. I hope i wont experience the same disappointment from microchip...

  • At 17 March 2012, 2:19:40 user Ion wrote:   [reply @ Ion]
    • @Giorgos Lazaridis
      Ctmu on Pic18F it is a big failure of Microchip
      Even their development board does not works if the hand does not touch the pad
      Microchip forum on CTMU it is full of complains and desperate peoples looking for solutions.
      They are some smart guy which said, read the App. notes, but NOBODY proved a working reliable example.
      Why do you believe Microchip released so many development software packages, but guess what, ONLY for pic16 and 24? 24 because has 12 bits A/D, and 16 for Cap sense.
      If you want to be rich and famous, develop an application for 18F with CTMU. Hey 18F87J90 is what I use :)
      Your site will be swamped by visitors to see it, a.k.a. tons of traffic and your You tube channel will go viral.
      If you want to beat the challenge, try to do it, and believe me you will be famous.
      Biggest problem that everybody complains is sensitivity. With yours I can keep the fingers 10 mm away and it will see it.
      With 18F, you put 0.5 gap between finger and button and is gone.
      Try it and you will see. Have fun and let me know if you can achieve something
      Best regards

  • At 16 March 2012, 20:41:18 user Giorgos Lazaridis wrote:   [reply @ Giorgos Lazaridis]
    • @Ion unfortunately i haven't tried the mtouch at all. i thought it was a good solution though. It is not working correct? hm...

  • At 15 March 2012, 21:37:17 user Ion wrote:   [reply @ Ion]
    • @Giorgos Lazaridis Hello Giorgio,
      did you have any luck to implement touch buttons with Pic18f series which have Mtouch module but not Cap sense like Pic16f ?
      I am very interested to know, because on mu application i use a PIC18F87J90 for driving the LCD and real time clock and i do not have room to add a pic16F.
      I build your examples for 4 and 10 buttons and works great, but for pic18f, following by book all the app notes, including the famous 1250, i just sens my finger when i touch or through thin piece of plastic. With 2 mm plastic it does not see it.
      On microchip forum everybody complain about sensitivity, which is not the case on your example. I had to lower the sensitivity on your example because was too high
      Please help if you have any piece of code or example
      Thank you

  • At 27 February 2012, 10:39:43 user Giorgos Lazaridis wrote:   [reply @ Giorgos Lazaridis]
    • @Ion since you have too many question, i opened a forum thread. Use this thread instead:

  • At 26 February 2012, 8:02:06 user Ion wrote:   [reply @ Ion]
    • One more question.
      I need in some conditions to press a combination of two buttons on the same time
      It will work if i press two buttons ?
      Lets, say i press I8 and I10 in the same time
      What will be the result ?
      If does not take two buttons in the same time, will be no problem because i can use an other one to represent the combination of the 2 PB simultaneous pressed
      But will be nice to have the opportunity to press two buttons and get the combined result

  • At 21 February 2012, 9:00:36 user Giorgos Lazaridis wrote:   [reply @ Giorgos Lazaridis]
    • @Rob Calala The chip that i use (PIC 16F1937) comes also in SMD. Check out here:
      It is exactly the same chip, i just got them later. Yet this need programming too. You must find someone to upload the code to the chip after having it mounted on the board. You only need to give them the HEX file that i provide.
      For other chips, i know that analog devices have some capacitance touch controllers but i have never use them.

  • At 20 February 2012, 19:44:25 user Rob Calala wrote:   [reply @ Rob Calala]
    • First of all I do love your site.
      I am working on designing a ON/Off Slider for various household automation control. Your design is exactly the same way I was going with mine, but alas I know nothing about software programing. So my system will be based on a PLC rather than a PC. The BCD output is exactly what I was looking for.
      My question is if there is a SMT chip that would work based off of your code?

  • At 23 November 2011, 23:00:05 user pinozo wrote:   [reply @ pinozo]
    • thanks, but I thought something simpler ...
      unfortunately they are an amateur, I have the knowledge required for this type of changes ...
      I successfully executed some of your wonderful projects, perhaps with minor changes, but this does not arrive.
      if I can get some more help would be nice ..

      thanks anyway for your fantastic projects

  • At 23 November 2011, 15:39:18 user Kammenos wrote:   [reply @ Kammenos]
    • @pinozo you will need to alter the schematic as well as the code a bit. Or you can connect a BCD to decimal decoder at the output, and then a D-ff on each of the 10 outputs.

  • At 22 November 2011, 0:08:11 user pinozo wrote:   [reply @ pinozo]
    • sorry for my ignorance
      is possible to turn on the switch button to turn on a relay at the touch of each key?
      10 keys ... 10 relays
      as in the project "PIC-Change Frequency Capacitance Touch Button," but with 10 or more switches on off

  • At 21 October 2011, 0:50:42 user ron wrote:   [reply @ ron]
    • Thank You! Artwork_1 is beautiful.


  • At 20 October 2011, 15:18:57 user ron wrote:   [reply @ ron]
    • OK, that would be appreciated. Dimensions help! To get the PCD I used
      Xnview and kept printing until I got the 40 pin dimension correct so in imperial the board is 4.69 by 3.78 inches, lol

      Will post in 'your projects' in a few days


  • At 20 October 2011, 5:23:12 user Kammenos wrote:   [reply @ Kammenos]
    • @ron Oh i see! This artwork :D. Ok, i was not going to upload it, because i supposed that people should make it better by themselves. But you are right: You may wanna design it yourself, but it will be better if you have the original artwork with the dimensions. So i will uploaded right now.
      As for the forum, you can start posting your work in the "Your projects" section.

  • At 19 October 2011, 21:18:35 user ron wrote:   [reply @ ron]
    • I am writing this under the "10 Buttons PIC Touch-Pad with BCD Output" comments section. Immediately above this is a picture of your hand holding the artwork... which you said you would post, "when you were ready"

      There is nothing wrong with the forums, just so many headings and none said anything about replications of the touch pad. I could post a picture of my start if I knew where it belonged


  • At 19 October 2011, 19:39:45 user Kammenos wrote:   [reply @ Kammenos]
    • @Ron which artwork are you talking about? And what's wrong with the forum??? :/

  • At 19 October 2011, 19:29:06 user Ron wrote:   [reply @ Ron]
    • 1)How about the artwork, is it ready yet?

      2) what heading in the forum would this come under?


  • At 10 October 2011, 15:38:04 user Kammenos wrote:   [reply @ Kammenos]
    • @Evanildo A Costa i'm sorry but i do not do circuits on demand.

  • At 10 October 2011, 5:02:46 user Evanildo A Costa wrote:   [reply @ Evanildo A Costa]
    • hello can you help me?
      I need to do a project that will utilizes the peripheral mtouch.
      I'm going on my project utilizes the pic 16f727.
      I need to send via the serial port of the PIC, the states of buttons (touch m). I'll utilizes two models of microcontrollers, a pic 16f727, this will take care of keys and serial communication to send the condition of the keys.
      I'll utilizing the pic, 16f876A, this will get your serial port on the conditions in which they are the keys, either open or closed sent through, pic 16f727.
      for serial communication between the two pics, I'll start using Zigbee.
      you can help me develop this code?

      Thank you.

  • At 5 August 2011, 18:24:55 user Kammenos wrote:   [reply @ Kammenos]
    • @Rafael Marquez Plascencia Damn, how did i forgot to upload the code! I upload it right away. You can also find the code for this here:

      I used this circuit for my keycode lock.

  • At 5 August 2011, 17:43:57 user Rafael Marquez Plascencia wrote:   [reply @ Rafael Marquez Plascencia]
    • hello

      congratulations its realy a very good proyec!!

      well the reason of this is ask to you, can you help me?
      im on the unaversity and im doing a similar proyec but i need 24 touch pads i think ill meke it on a matrix eny way.
      im new on this tecnology can you show me your code? asm or c?


  • At 24 June 2011, 4:09:43 user Kammenos wrote:   [reply @ Kammenos]
    • @dannyman3819 R1 is 10 KOhms and R2 is 330 Ohms.

  • At 23 June 2011, 22:07:36 user dannyman3819 wrote:   [reply @ dannyman3819]
    • what are the values of r1 and r2

  • At 18 June 2011, 7:07:26 user Brad wrote:   [reply @ Brad]
    • What programmer do you use with your ICSP?

  • At 18 June 2011, 7:00:08 user Kammenos wrote:   [reply @ Kammenos]
    • @Amos correct, it is encoded as decimal 10 (binary "1010"

  • At 18 June 2011, 2:41:17 user Amos wrote:   [reply @ Amos]
    • Excellent project and demo! One question, though: since the steady-state output seems to be zero, how is the zero button encoded? It's never pressed in the video... I'm assuming it's 1010b (10).

  • At 17 June 2011, 19:52:43 user Kammenos wrote:   [reply @ Kammenos]
    • @pcb something wrong happens with IE when trying to read large gif files. If you try it with firefox it works perfectly fine. I will upload a zip version for windows users hopefully within coming week.

  • At 17 June 2011, 18:47:18 user pcb wrote:   [reply @ pcb]
    • top and bottom pcb links dont appear to work for me

  • At 16 June 2011, 22:21:48 user _pike wrote:   [reply @ _pike]
    • YOU ARE AWESOME!!!!!!Keep going :-) (Video?)

    reddit this Reddit this

     HOT in heaven!

    NEW in heaven!

    New Theory: AC electric motor working principle

     Contact     Forum     Projects     Experiments     Circuits     Theory     BLOG     PIC Tutorials     Time for Science     RSS   

    Site design: Giorgos Lazaridis
    © Copyright 2008
    Please read the Terms of services and the Privacy policy