Bonjour,
Je veux créer 3 "interrupteurs capacitifs" pour ma salle de bain, un pour allumer ou éteindre la lumière général, un pour la lumière de la douche, et un pour le miroir LED, j'ai mon code etc que je mettrais après cette description, quand je fais ça en phase d'essai sur mon bureau pas de soucis tout est ok, la détection c'est bon, une fois que je passe en réel plus moyen de quoi que ce soit.
Mon schéma électrique/électronique est tel que :
- Une résistance de 1kOhm sur chaque Receive Pin
- Une résistance de 33 MOhm sur chaque Send Pin
- Les deux autres pattes des résistances ensemble avec mon antenne de détection
Je me demande si la distance des câbles entre mon arduino et l'endroit où je détecte vraiment n'est pas problématique ? J'ai essayé de mettre les résistance au plus proche de mon arduino, mon antenne est du coup d'un longueur de 4M environ, et j'ai aussi essayé en mettant 2 longueurs d'environ 4M, entre mon arduino et mes deux résistances pour avoir une antenne très petite, mais rien n'y fait, je ne comprends pas.
Voici le code :
#include <CapTouch.h>
/* CapTouch - an example for the CapTouch class
from the v.04 - Capacitive Sensing Library for 'duino / Wiring
by Paul Badger 2-3-2012
<paul@moderndevice.com> http://opensource.org/licenses/mit-license.php
This capacitive sensing method requires two microcontroller pins (send pin, receive pin)
with a high value resistor between them (1M is a starting point)
a small capacitor (20-40 pf) from the receive pin (the sensor is connected to this pin)
to ground will result in more stable readings. Sensor is any wire or conductive foil
on the receive pin.
Also demonstrates a simple smoothing filter which is not required in any way
by the sketch
*/
// CapTouch(sendPin, receivePin) - recieve pin is the sensor to touch
CapTouch touch_2_3 = CapTouch(2, 3);
CapTouch touch_4_5 = CapTouch(4, 5);
CapTouch touch_6_7 = CapTouch(6, 7);
float light;
float shower_light;
float mirror_light;
void setup()
{
pinMode(10, OUTPUT);
digitalWrite(10, 1);
pinMode(11, OUTPUT);
digitalWrite(11, 1);
pinMode(13, OUTPUT);
digitalWrite(13, 1);
}
void loop()
{
long start = millis(); // scheme to time performance, delete at will
long light_sensor = touch_2_3.readTouch(90); // read the sensor
long shower_light_sensor = touch_4_5.readTouch(90);
long mirror_light_sensor = touch_6_7.readTouch(90);
long elapsedTime = millis() - start; // scheme to time performance, delete at will
// simple lowpass filter to take out some of the jitter
// change parameter (0 is min, .99 is max) or eliminate to suit
// you need a different "smoothed" variable for each sensor is using more than one
light = smooth(light_sensor, .95, light);
shower_light = smooth(shower_light_sensor, .95, shower_light);
mirror_light = smooth(mirror_light_sensor, .95, mirror_light);
if (light >= 2000 || shower_light >= 2000 || mirror_light >= 2000)
{
if (light >= 2000) {
digitalWrite(11, 0);
delay(50);
digitalWrite(11, 1);
}
else if (shower_light >= 2000) {
digitalWrite(10, 0);
delay(50);
digitalWrite(10, 1);
}
else if (mirror_light >= 2000) {
digitalWrite(13, 0);
delay(50);
digitalWrite(13, 1);
}
delay(500);
}
delay(10);
}
// simple lowpass filter
// requires recycling the output in the "smoothedVal" param
float smooth(float data, float filterVal, float smoothedVal) {
if (filterVal > 1) { // check to make sure param's are within range
filterVal = .99;
}
else if (filterVal <= 0) {
filterVal = 0;
}
smoothedVal = (data * (1 - filterVal)) + (smoothedVal * filterVal);
return smoothedVal;
}



