In this project I made a touch controlled light that works based on Arduino Capacitive Sensing Library.
In this project I made a touch controlled light that works based on Arduino Capacitive Sensing Library. You can make a touch sensor by using a aluminium foil(any metallic object will work). you can turn on or turn off light by touching on a aluminium foil.
I would like to give a brief introduction on how capacitive library works:
The capacitiveSensor library turns two or more Arduino pins into a capacitive sensor, which can sense the electrical capacitance of the human body. All the sensor setup requires is a medium to high value resistor and a piece of wire and a small (to large) piece of aluminum foil on the end. At its most sensitive, the sensor will start to sense a hand or body inches away from the sensor. he capacitiveSensor method toggles a microcontroller send pin to a new state and then waits for the receive pin to change to the same state as the send pin.
So with high resistor this act likes proximity sensor.
To get clear idea about Arduino Capacitive Sensing Library please follow the this link
Basic Software(Arduino IDE) Requirements:-
- You must install Capacitive Sensing Library
- You can download Capacitive Sensing Library from here
If you dont know how to install new library to the Arduino Software
Please follow the link to know how to install a library in Arduino IDE
Making Touch Sensor :
The touch sensor can be made from any metallic objects.I have used aluminium foil to make this.
For many applications, a more useful range of values is obtained if the sensor is covered with paper, plastic, or another insulating material, so that users do not actually touch the metal foil.
So I have covered it with a insulation tape ,and it works well :)
//arduino code for touch controlled light based on capacitive sensing library
#include <CapacitiveSensor.h>
CapacitiveSensor cs_2_4 = CapacitiveSensor(2,4); // 1M resistor between pins 2 & 4, pin 4 is sensor pin, add a wire and or foil
int in = 2;
int out = 4;
int state = HIGH;
int r;
int p = LOW;
long time = 0;
long debounce = 200;
void setup()
{
pinMode(4, INPUT);
pinMode(8, OUTPUT);
}
void loop()
{
r = digitalRead(4);
if (r == HIGH && p == LOW && millis() - time > debounce) {
if (state == HIGH)
state = LOW;
else
state = HIGH;
time = millis();
}
digitalWrite(8, state);
p = r;
}