Touch Sensor Interfacing with PIC16F877A (TTP223B)

This article is a continuation of the series of tutorials on the PIC16F877A Microcontroller. The aim of this series is to provide easy and practical examples that anyone can understand. In the previous tutorial, we have interfaced the Sound detection sensor with PIC16F877A. In this tutorial, we are going to discuss Touch Sensor Interfacing with PIC16F877A (TTP223B).

Prerequisites

Before starting this tutorial we should know the below topics. If you know already, please go further.

Components Required

Introduction

The TTP223B is a Digital touchpad detector IC that offers 1 touch key. The touching detection IC is designed for replacing traditional direct button keys with diverse pad sizes. This device uses your body as part of the circuit.

When you touch the sensor pad, the capacitance of the circuit is changed and is detected.  That detected change in capacitance results in the output changing states. In the normal state, the module output low, low power consumption; When a finger touches the corresponding position,  the module output high, if not touched for 12 seconds, switch to low-power mode.

Specification

  • Operating voltage 2.0V~5.5V
  • ƒOperating current @VDD=3V, no-load, SLRFTB=1, At low power mode typical 1.5uA, maximum 3.0uA and At fast mode typical 3.5uA, maximum 7.0uA
  • Operating current @VDD=3V, no-load, SLRFTB=0, At low power mode typical 2.0uA, maximum 4.0uA and At fast mode typical 6.5uA, maximum 13.0uA
  • The response time max about 60mS at fast mode, 220mS at low power mode @VDD=3V
  • Provides Fast mode and Low Power mode selection by pad option(LPMB pin)
  • Operating Temperature:-20 ~ +70 ℃

Touch Sensor Pin Outs

Like a lot of the sensors out there, this is three pin sensor.  You provide power, ground, and monitor the output.

  • SIG – Output (If it detects touch, this will be HIGH otherwise LOW)
  • VCC – 2v to 5.5v
  • GND – Ground

Touch Sensor Interfacing with PIC16F877A

Connection

Touch Sensor

  • Vcc – 5v
  • GND – Ground
  • Sig – RD0 (PORTD.0)

LCD

  • RS – RC0
  • RW – RC1
  • EN –RC2
  • Data Lines – PORTB

Touch Sensor Interfacing with PIC16F877A

Source Code

If this sensor detects any touch, LCD will display “Touch Detected”.

#include<htc.h>
 
__CONFIG( FOSC_HS & WDTE_OFF & PWRTE_OFF & CP_OFF & BOREN_ON & LVP_OFF & CPD_OFF & WRT_OFF & DEBUG_OFF);
 
#define TOUCH RD0                  //TOUCH sensor Output is connected at PORTD.0
 
#define rs RC0
#define rw RC1
#define en RC2
#define delay for(i=0;i<1000;i++)
 
int i;
 
void lcd_init();
void cmd(unsigned char a);
void dat(unsigned char b);
void show(unsigned char *s);
 
 
void main()
{
    TRISB=TRISC0=TRISC1=TRISC2=0;
    TRISD=0xff;                         //Port D act as Input
    lcd_init();
    cmd(0x80);
    show("   EmbeTronicX  ");
    while(1) {
        if(TOUCH) {
            cmd(0xc0);
            show("Touch Detected");
            delay;delay;
        } else {
            cmd(0xc0);
            show("                ");
        }
    }
}
 
void lcd_init()
{
    cmd(0x38);
    cmd(0x0c);
    cmd(0x06);
    cmd(0x80);
}
 
void cmd(unsigned char a)
{
    PORTB=a;
    rs=0;
    rw=0;
    en=1;
    delay;
    en=0;
}
 
void dat(unsigned char b)
{
    PORTB=b;
    rs=1;
    rw=0;
    en=1;
    delay;
    en=0;
}
 
void show(unsigned char *s)
{
    while(*s)
    {
        dat(*s++);
    }
}

References

  • Catalex TTP223B Arduino Capacitive Touch Sensor Tutorial

In our next tutorial, we will see how to interface the DC motor with PIC16F877A.

You can also read the below tutorials.

Linux Device Driver TutorialsC Programming Tutorials
FreeRTOS TutorialsNuttX RTOS Tutorials
RTX RTOS TutorialsInterrupts Basics
I2C Protocol – Part 1 (Basics)I2C Protocol – Part 2 (Advanced Topics)
STM32 TutorialsLPC2148 (ARM7) Tutorials
PIC16F877A Tutorials8051 Tutorials
Unit Testing in C TutorialsESP32-IDF Tutorials
Raspberry Pi TutorialsEmbedded Interview Topics
Reset Sequence in ARM Cortex-M4BLE Basics
VIC and NVIC in ARMSPI – Serial Peripheral Interface Protocol
Bootloader Tutorials
0 0 votes
Article Rating
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x