Introduction
Capacitive sensor deals with capacitance or in simple words capacitor. A capacitance is built between the sensor and the human body when we bring a human body near the sensor. A charge is induced and this charge is picked by the sensor and is translated as a button press. As we move our finger back from the sensor plate the capacitance is lost and circuit breaks.
Video
This video will show you How to control A Chocolate Box with Touch Sensor and Arduino.
Hardware Preparation
This is the hardware connection and the components needed.


Sample Code
#include <Servo.h> | |
Servo myservo1; | |
Servo myservo2; | |
int touchSensorPin = 2; | |
int touchSensorState = 0; | |
void setup() { | |
myservo1.attach(9); | |
myservo2.attach(10); | |
pinMode(touchSensorPin, INPUT); | |
} | |
void loop() { | |
if (digitalRead(touchSensorPin) == 1) { | |
myservo1.write(180); | |
delay(15); | |
while (1) { | |
myservo2.write(0); | |
delay(1000); | |
myservo2.write(180); | |
delay(1000); | |
if (digitalRead(touchSensorPin) == 1) { | |
myservo1.write(0); | |
delay(1000); | |
break; | |
} | |
} | |
} | |
else { | |
myservo1.write(0); | |
delay(15); | |
myservo2.write(180); | |
delay(1000); | |
} | |
} | |
References :
Thank you
Thank you for reading this tutorial and we hope it helps your project development. If you have any technical inquiry, please post at Cytron Technical Forum.