PDA

View Full Version : Need a cheap touch sensor idea.. here it is



mister_e
- 28th October 2005, 17:09
Hi all! Even if there's some built-in solution and dedicated IC to do the job, here's my few cents solution. Not that it is the only one and safest solution but it's working for me on few home-dedicated application.

The touch sensor itself:
almost everything you have on hand and conductive.

The only thing you have to do is to touch the XYZ conductive material and TADA! No mechanical switch or push button... only one floating piece of conductive material.

Maybe not suitable in harsh environement, but working great in home application.

The schematic:
<img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=570&stc=1&d=1130515579">

The code:


' Few cents touch sensor
' ======================
' Using : PIC12F629
'
' Circuit is quite simple. One pin(GP4) is used as a signal generator.
' This pin send signal to all "virtual push button" (GPIO<2:0>)
' via 3 X 22K resistor. The touch sensor could be almost everything
' conductive.
'
' Once a sensor is touched, the program will blink a LED as follow
' GPIO.0 => 1 Blink
' GPIO.1 => 2 Blink
' GPIO.2 => 3 Blink


' PIC config and programming mode
' ===============================
'
@ DEVICE PIC12F629,INTRC_OSC_NOCLKOUT ' internal RC osc
@ DEVICE PIC12F629,MCLR_OFF ' Disable external MCLR
@ DEVICE PIC12F629,WDT_OFF ' Disable WatchDog timer
@ DEVICE PIC12F629,PROTECT_OFF ' Disable device protect
@ DEVICE PIC12F629,CPD_OFF ' Disable Code-Protect
@ DEVICE PIC12F629,PWRT_ON ' Enable Power-up timer
@ DEVICE PIC12F629,BOD_ON ' Enable Brown-out detect

' I/O Alias definition
' ====================
'
LED VAR GPIO.5
Generator var GPIO.4

' Hardware definition
' ===================
'
TRISIO = $0F ' GPIO<3:0> as input
' GPIO<5:4> as output
'
CMCON = 7 ' Disable internal comparator

' Variable definition
' ===================
'
Sensor var byte
Loop var byte

' EEPROM assignement
' ==================
'
data @3,3,0,2,1 ' table to convert 'Sensor' variable result to according
' LED blink. See Result list bellow

' Software/hardware initialisation
' ================================
'
led = 0
generator = 0


Start:
' /////////////////////////////////|\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
' / Start \
' /////////////////////////////////|\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
'
' Short explanation of the whole thing.
' 1. Send a high level to all sensor input => GPIO<2:0>
' 2. Read GPIO port
' 3. Send a low level to all sensor input
' 4. Keep only GPIO<2:0> bits
' 5. Test result
'
' If no sensor has been touched, the result will be 7 => 0000 0111, case
' else, the body capacitance will introduce sufficient delay between
' step 1 and 2 wich will keep the according bit to 0.
'
' Results will be as follow
' NoSensor => 0000 0111 => 7
' GPIO.0 => 0000 0110 => 6
' GPIO.1 => 0000 0101 => 5
' GPIO.2 => 0000 0011 => 3
'
repeat
Generator = 1 ' enable sensor power
Sensor = GPIO ' read sensor
Generator = 0 ' disable sensor power
Sensor = Sensor & 7 ' keep only Sensor bits
'
until Sensor != 7 ' redo the test untill one sensor is touch
'
' Now we will flash an LED to confirm wich sensor has been touch
' GPIO.0 => 1 Blink
' GPIO.1 => 2 Blink
' GPIO.2 => 3 Blink
'
read sensor,loop ' convert result to blink
repeat
LED = 1
PAUSE 200
lED = 0
PAUSE 200
loop = loop - 1
until loop = 0

goto start ' do it again...

Have fun!

rsocor01
- 16th March 2009, 20:21
Hi all,
Currently, I'm working on a project where it would be nice to have a cheap touch sensitive switch. So, I looked at mister_e's entry about a touch sensor. I think it's a very clever idea, but there is a problem I can't make it work. I'm using a pic16f84 at 4 MHz, the same frequency that uses mister_e's pic. I have tried different combinations of resistors and I have added some capacitors but still it doesn't work.
When using an oscilloscope I can see the input signal at the input ports goes lower when touched by a finger but apparently not low enough to read a zero.
Does anybody have any ideas on how to make this work? Probably adding an op-amp would do the job. Thanks.

Robert.

Archangel
- 17th March 2009, 07:05
Hello Robert,
Well we know it will not work without changing a few things for the 16F84, so post what you have and let's look and see. Open a new thread in PBP so as not to hijack this example thread.

Ioannis
- 17th March 2009, 08:39
Do NOT put extra capacitance at the inputs beside the sensor itself.

Even the Osc. probe will load inputs.

Maybe play with the 22k resistors. Also good idea would be to compare spcs of the two PIC's.

Ioannis

P.S. If necessary, admins move this message to keep thread clean. No problem.

George
- 8th September 2009, 22:17
What a great idea, is it working reliably - I have a device I need this sort of thing for, pref very cheap with little extra in the way of components, did rsocor01 ever get it running? He didnt mention it on his other thread. Just wondering. would higher value resistors and a longer charge period help with the sensitivity?

I need this unit to be fairly reliable, is it likely to do this if set up right? Hopefully will be mass produced. Most commercial capacitive systems take a running average and are constantly resetting their zero point to allow for atmospheric conditions etc dont they?

rsocor01
- 9th September 2009, 01:21
George,

No, I never got it to work the way it's explained in this threat. The way to go is with the series PIC16F72x. They work great. Refer to the threats started by byte_butcher about his project. That should help you.

Robert

George
- 10th September 2009, 01:01
Hey I tried it and got it going really well, i changed some values to make it more sensitive (I don't have much space available for the pad) ie - changed the resistor to 100K and put a 1ms delay in on the charge, through a 3mm sheet of glass a sensor pad size of down to 6mm x 6mm worked reliably. This was using a 16F676 @ 4MHz. Why is rsocor using a 16F84? I cant even understand why they are still being made and so popular, they are just junk along side the more modern chips.

Thanks Mister E for such a great idea, I think as long as I tune the sensor pad size/resistor it should be pretty reliable as I've had no issues with it yet and it worked first time.

Archangel
- 10th September 2009, 04:48
Why is rsocor using a 16F84? I cant even understand why they are still being made and so popular, they are just junk along side the more modern chips.


There are dozens of books, hundreds of instructors who recommend them. They work out of the box with default configs, no A/Ds, No Comparators, perfect choice for that first PIC. Remember George, newbies often know absolutely nothing about PICs, and these chips offer the easiest way to get started without getting tripped. Move up to 16F628A / 648A, adds comparators and memory and timers, same footprint, 1 brick at a time, is how a wall gets built. But yeah, for the experienced programmer, to much money too little chip.

rsocor01
- 10th September 2009, 20:30
Currently, I am using the PIC16F72x series that have a built in Capacitive Sensing Module (CSM) that are designed for touch sensor applications. These chips work great. You don't need any tunning and they are 100% reliable.

The reason I first tryed Mister_E's circuit with a 16F84 is because that's one chip that I had handy at that moment. I could see a small change in voltage amplitude at the input ports when the sensors were touched, but they weren't reliable enough in the circuit I built. Maybe I needed to do some adjustments and tunning. Any ways, I think it's a great idea Mister E came out with.

I just love it to see all the smart a** comments you can find in here that do not contribute to resolve any issues and that do not provide any technical guidance at all.

Robert

Sharky
- 6th July 2010, 12:49
I know that it is some years ago now that you have postet this great simple way of making a capacitive touch-sensor.
But still I would like to thank you for it, it just helped me on making a capacitive water level sensor, I added a few things, like a trim-pot to set the sensitivity.

So thank you for this great construction!! :)

Sharky

mrelectric
- 3rd April 2011, 22:06
helo

I have tried to edit that code on Micro baisc pro but it doesn't understand it.

replay this error message "@ is not a valid Identifier"

Please help me what app to use to edit this code and convert it to hex file..

Thanks and Regards

mrelectric

ScaleRobotics
- 3rd April 2011, 22:13
helo

I have tried to edit that code on Micro baisc pro but it doesn't understand it.

replay this error message "@ is not a valid Identifier"

Please help me what app to use to edit this code and convert it to hex file..

Thanks and Regards

mrelectric

You need the PicBasic Pro applicaton. You can get it here http:\\www.melabs.com

mrelectric
- 3rd April 2011, 23:29
Thanks alot it is now works properly ...




First Question:

what I need to change in code to use PIC16F84A instead of current one ...






Second Question:

what the code needed to make each touch of a sensor run a different device for example I

have 3 electric devices.

like Television and recorder and wash machine.

Touch Sensor1 = Run First Device if it OFF or OFF the first device if it ON.

Touch Sensor2 = Run Second Device if it OFF or OFF the Second device if it ON.

Touch Sensor3 = Run Third Device if it OFF or OFF the Third device if it ON.


and make the default condition for all devices is OFF.





Third Question:


Does I Need a Relay for Each Device Or can figure out a way without using it .. take in consideration these devices use AC 220 VOLT







Fourth Question:

Does the 3 copper plate sens the touch if I Cover them by one plate of Glass

or that will make a disruption so the touch will affect all of three sensors.

That mean it should be a different 3 plates of glass I Mean 1 Plate for each Copper Sensor for

avoiding disruption but this way will be very bad looking.


I am very glad for helping me.

God bless you...


Thanks and regards..

mrelectric
- 4th April 2011, 02:49
Mr. scalerobotics Please Help

Ioannis
- 4th April 2011, 07:59
Since you may live in a different time zone and the service here is free, you can't expect a person to give you support 24/7, right?

Then I see you are asking question about 220Vac wiring. I feel that you are not experienced on such circuits, so to save your life, STAY AWAY from Mains Line. It is very dangerous.

And to answer you question, yes you need seperate relays for each load.

But i repeat, have someone that knows what is doing to help you out. Do not do it alone.

Ioannis

ScaleRobotics
- 4th April 2011, 15:24
First Question:

what I need to change in code to use PIC16F84A instead of current one ...

The 12F's have a GPIO port, most other chips have PORTA,PORTB etc. So that would have to be changed. Also your configs would have to be changed for the chip you are using. This is pretty much a topic of its own. Normally, one would look at the data sheet for the chip you are using, and see what settings would need to be applied to that chip. There is also no comparator on the 84, so you can comment that out.



Second Question:

what the code needed to make each touch of a sensor run a different device for example I

have 3 electric devices.

like Television and recorder and wash machine.

Touch Sensor1 = Run First Device if it OFF or OFF the first device if it ON.

Touch Sensor2 = Run Second Device if it OFF or OFF the Second device if it ON.

Touch Sensor3 = Run Third Device if it OFF or OFF the Third device if it ON.


and make the default condition for all devices is OFF.
Why don't you play with the code with some LED's and try for yourself?



Third Question:


Does I Need a Relay for Each Device Or can figure out a way without using it .. take in consideration these devices use AC 220 VOLT
I would like to take some time to point at some great advice Ioannis gave you above. Your work on 220 could kill you, or the equipment you make, could kill others.

Yes, you would need some large (pretty expensive) relays to run this kind of equipment.



Fourth Question:

Does the 3 copper plate sens the touch if I Cover them by one plate of Glass

or that will make a disruption so the touch will affect all of three sensors.

That mean it should be a different 3 plates of glass I Mean 1 Plate for each Copper Sensor for

avoiding disruption but this way will be very bad looking.

I know the capacitive touch sensors that are built into the newer chips (the 16F84 is one of the oldest most outdated chips around) does have the ability to sense over vinly, or through plexiglass. I am not sure Steve's cheap sensor idea has this capability, as I have never tried it. You could test it and see. If not, you may want to splurge, and spend $1.25 for one of the newer PIC chips with capacitive touch built in

As we always recommend, start out small. Blink an led. Then see if you can get Steve's code working on a chip to your liking. Once you figure out how to make it blink and LED, then think about how you might modify it to better fit your ideas.

But once again, working with 220 is very dangerous, and can kill your equipment, you, and others using your home made equipment.

And if you were looking for a cheap project, all the equipment you need to turn on and off these large amperage devices, will be rather expensive.

Here is his code edited for your chip. You will have to work on the configuration part though.



' Few cents touch sensor
' ======================
' Using : Untested for PIC16F84A
'
' Circuit is quite simple. One pin(GP4) is used as a signal generator.
' This pin send signal to all "virtual push button" (GPIO<2:0>)
' via 3 X 22K resistor. The touch sensor could be almost everything
' conductive.
'
' Once a sensor is touched, the program will blink a LED as follow
' PORTB.0 => 1 Blink
' PORTB.1 => 2 Blink
' PORTB.2 => 3 Blink


' PIC config and programming mode
' ===============================
'
; @ DEVICE PIC12F629,INTRC_OSC_NOCLKOUT ' internal RC osc
; @ DEVICE PIC12F629,MCLR_OFF ' Disable external MCLR
; @ DEVICE PIC12F629,WDT_OFF ' Disable WatchDog timer
; @ DEVICE PIC12F629,PROTECT_OFF ' Disable device protect
; @ DEVICE PIC12F629,CPD_OFF ' Disable Code-Protect
; @ DEVICE PIC12F629,PWRT_ON ' Enable Power-up timer
; @ DEVICE PIC12F629,BOD_ON ' Enable Brown-out detect

' I/O Alias definition
' ====================
'
LED VAR PORTB.5
Generator var PORTB.4

' Hardware definition
' ===================
'
TRISB = $0F ' PORTB<3:0> as input
' PORTB<5:4> as output
'
; CMCON = 7 ' Disable internal comparator

' Variable definition
' ===================
'
Sensor var byte
LOOP1 var byte

' EEPROM assignement
' ==================
'
data @3,3,0,2,1 ' table to convert 'Sensor' variable result to according
' LED blink. See Result list bellow

' Software/hardware initialisation
' ================================
'
led = 0
generator = 0


Start:
' /////////////////////////////////|\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
' / Start \
' /////////////////////////////////|\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
'
' Short explanation of the whole thing.
' 1. Send a high level to all sensor input => PORTB<2:0>
' 2. Read PORTB port
' 3. Send a low level to all sensor input
' 4. Keep only PORTB<2:0> bits
' 5. Test result
'
' If no sensor has been touched, the result will be 7 => 0000 0111, case
' else, the body capacitance will introduce sufficient delay between
' step 1 and 2 wich will keep the according bit to 0.
'
' Results will be as follow
' NoSensor => 0000 0111 => 7
' PORTB.0 => 0000 0110 => 6
' PORTB.1 => 0000 0101 => 5
' PORTB.2 => 0000 0011 => 3
'
repeat
Generator = 1 ' enable sensor power
Sensor = PORTB ' read sensor
Generator = 0 ' disable sensor power
Sensor = Sensor & 7 ' keep only Sensor bits
'
until Sensor != 7 ' redo the test untill one sensor is touch
'
' Now we will flash an LED to confirm wich sensor has been touch
' PORTB.0 => 1 Blink
' PORTB.1 => 2 Blink
' PORTB.2 => 3 Blink
'
read sensor,LOOP1 ' convert result to blink
repeat
LED = 1
PAUSE 200
lED = 0
PAUSE 200
LOOP1 = LOOP1 - 1
until LOOP1 = 0

goto start ' do it again...

mrelectric
- 8th April 2011, 07:18
Thanks alot for your's precious advices .....

I have good experience to avoid such accidents but thanks for yours attention.

I will apply all the steps and re tell you about my result ...

Thanks and regards...

AvionicsMaster1
- 28th June 2011, 15:01
Mister_e
Just curious why you chose 22k resistors for R1, R2 and R3? Was there any math involved or was it experience?

mister_e
- 28th June 2011, 15:39
trial/error, not much.

Shazin
- 3rd February 2016, 08:22
Hi, I want to use a 12F675 for this project. I replaced 12F629 with 12F675 in the code, since 675 chip is almost identical to 629 chip. It compiled without any errors. But the LED just keeps bilinking. doesn't respond to touch. Can someone tell me, what else do I have to change in the code to make it work. Thanks in advance... :)

Demon
- 16th April 2016, 22:42
Start a new thread in General forum and post your code, all of it, easier for people to help you.

Robert