Mturk Jobs

Mturk Jobs
Mturk Jobs

Tank

Friday, December 1, 2017

PIC 16F84A Capacitive touch Sensor using minimum hardware

I've previously thought of making a capacitive touch sensor that works as touch switch using the PIC 16F84A Microcontroller.

I had a lamp that works using capacitive touch as a switch and it gave me the idea.

When I worked with the microcontroller and there was some error or bad connection in hardware circuit I noticed that the microcontroller showed irregular behavior during touching it when reading zeros and ones inputs to the GPIOs.

Here's how I got the idea of using the microcontroller as a touch sensor.

I've tried to make the circuit and code it myself but I had unreliable results. I thought that the idea was wrong and would never work.

When I searched for it online I found a video showing how it worked so good. I wanted to share it with you.

I found it on this blog:

http://diytronics.blogspot.com.eg/2011/05/capacitive-touch-sensor-for-pic16f84a.html

I'll try it and will make some modification to it.
I'll also add a photo of my own circuit.






Here is the basic C code that does the job

int freqcapsense(){
    unsigned int avg;
    unsigned int current=0; 
    unsigned int thresh=29;

    unsigned int trials=10;

    while(trials>0){
        TRISA=0b0;
        RA0=1;
        delay();
        TRISA=0b1;
        while(RA0==1){current++;}
        trials--;
        avg=(avg+current)/2;
    }


    if((current-avg)>thresh){return 1;}
    else{return 0;}


    //return current;
}

Here is a video from the maker




The idea is very simple and straight forward.

The code can be applied to any microcontroller with this C language code.

Thank you for reading.


No comments:

Tank