Sketches: Capacitive Touch Sensor Module

HCARDU0012_800
Capacitive Touch Sensor Module

Items you will need:

Arduino development board such as this one

Male to female dupont cables

Capacitive touch sensor module

What does it do?

The sensor has two outputs, an analogue output that is dependent on how strongly a touch is detected, or a digital output that will go high if touch is detected above a threshold set by the modules potentiometer. This example program reads the status of both sensor outputs and outputs the result to the serial port.

Pinout:

1 Analogue out
2 GND
3 VCC (+5V)
4 Digital out

Code:

[cpp]
/* FILE: ARD_Capacitive_Touch_Sensor_HCARDU0024_Example
DATE: 03/07/12
VERSION: 0.1

You may copy, alter and reuse this code in any way you like, but please leave
reference to HobbyComponents.com in your comments if you redistribute this code.
This software may not be used directly for the purpose of selling products that
directly compete with Hobby Components Ltd’s own range of products.

THIS SOFTWARE IS PROVIDED "AS IS". HOBBY COMPONENTS MAKES NO WARRANTIES, WHETHER
EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ACCURACY OR LACK OF NEGLIGENCE.
HOBBY COMPONENTS SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR ANY DAMAGES,
INCLUDING, BUT NOT LIMITED TO, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY
REASON WHATSOEVER.

*/

/* Select the input pin for the flame detectors analogue output. */
#define TOUCH_DETECT_ANA A0

/* Select the input pin for the flame detectors digital output. */
#define TOUCH_DETC_DIO 2

/* Initialise serial and DIO */
void setup()
{
/* Setup the serial port for displaying the status of the sensor */
Serial.begin(9600);

/* Configure the DIO pin which the sensors digital output will be connected to */
pinMode(TOUCH_DETC_DIO, INPUT);
}

/* Main program loop */
void loop()
{
/* Read the sensors analogue output and send it to the serial port */
Serial.print("Sensor Value: ");
Serial.print(analogRead(TOUCH_DETECT_ANA));

/* Read the status of the sensors digital output and if it is high
then send an alert to the serial port */
if (digitalRead(TOUCH_DETC_DIO))
{
Serial.println(" TOUCH DETECTED!");
}else
{
Serial.println();
}
}
[/cpp]

Leave a Reply

Your email address will not be published. Required fields are marked *