Exercise 19 - Connecting a capacitive touch sensor
1. INTRODUCTION
In this exercise, capacitive sensor works as a button it only can has two states on Signal pin (HIGH or LOW). However, this type of sensor can be used in different environments, like Smartphone, tablets, track pads…
How it works? Capacitive sensor can detects any external object, which has a different dielectric value from air.
2. HOW TO CONNECT?
Materials:
· Arduino UNO board
· Protoboard
· Capacitive touch sensor
To connect this sensor, you have to power it, connecting GND and Vcc pins on sensor to GND and 5V pins on Arduino respectively. Furthermore, you have to connect Signal sensor pin to pin 12 on Arduino. On the other hand, on this example the internal LED of the Arduino UNO board is going to be used.
EXERCISE_A |
3. PROGRAMMING
EXERCISE_A
On this exercise sensor pin is read and its values is stored on value variable, then the value is compared on a condition and depending if it is HIGH or LOW a different message is printed on Serial monitor.
In this case, only one example is showed but if you want, you can do the examples from CONNECTING A BUTTON but with this sensor.
int sensorPin = 12;
int ledPin = 13;
int value;
void setup() {
pinMode(sensorPin, INPUT); //Set sensor pin as input
pinMode(ledPin, OUTPUT); //Set LED pin as OUTPUT
Serial.begin(9600);
}
void loop() {
value = digitalRead(sensorPin);
// If the value read is HIGH internal led on pin 13 is turned on
// and "Don't touch me!!!!" message is printed on Serial monitor
if (value == HIGH) {
digitalWrite(ledPin, HIGH);
Serial.println("Don't touch me!!!!");
}
else {
digitalWrite(ledPin, LOW);
Serial.println("Nothing");
}
}