This library and much of this README is based on Takuto Yamana's FastCapacitiveSensor that enable you to use capacitive sensors, but respectely to original this subtract the offset values when it is initialized with begin(). Added booltouch() method that returns only HIGH and LOW boolean values. The example script turns on the LED_BUILTIN. It is recommended to modify the hardware by adding an electrostatic discharge (ESD) protection resistor of at least 4.7Kohm
Antonio de Vincentiis
This library uses math.h.
The resistor decide the time of charging. receeivePin must be analog input pin.
Capacitive sensors are pseudo capacitors. Your Arduino will measure the time of charging them, and if the time is long, it decides that a conductor touching on the sensor.
The equation of the sensed voltage will be:
$$
V = V_0(1-e^{\frac{1}{RC}t})
$$
In this library, the time when
Actually, we do not have to measure the time until
The expected returning time
See also example program.
#include <ADVcapacitiveSensor.h>
ADVcapacitiveSensor sensor1;
sensor1.begin(A0, A1, 5.0, 10, 10, 0.2);
arguments:
void begin(sendPin, receivePin, maxVoltage, frequency, breakThreshold, excludeRatio);
maxVoltage is the voltage of the sendPin. It is
frequency is how many times the touch function tries sensing.
breakThreshold is the threshold of breaking sensing. The unit is micro seconds. the touch function finish sensing on the breakThreshold time, and after that, calculate the expected time of sensing. It is
excludeRatio is the ratio of exclusion of sensed values. Must be larger than or the same as 0 and smaller than 0.5.
sensor1.touch()
The return value is the sensed (or calculated) time in units of micro seconds. The type is double.
sensor1.booltouch()
The return value is bool type (HIGH or LOW), internally the touch() method is called 6 times to make an average.
MIT License
Copyright (c) 2019 to presente - Nyanyan Copyright (c) 2024 to present - Antonio De Vincentiis
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.