Beste,
ik heb al heel lang het probleem van spooklichten in mijn tuin.
In mijn tuinhuis zijn er 2 manieren waarop lichten geschakeld worden.
- een bewegingssensor die via een relais buitenverlichting schakelt.
- een arduino Yun die tuinverlichting en verlichting van het tuinhuis schakelt via een 4-kanaals relaisbord. (er zijn 4 drukknoppen aanwezig om deze manueel te bedienen)
Nu gebeurt het regelmatig dat tijdens het schakelen van de bewegingssensor 1 of meerdere relais meegeschakeld worden van het arduino - relaisbord.
Het lijkt of de ingangen van de arduino bediend worden, en zo de verlichting meeschakeld wordt. Zijn dit dan storingen op de ingangen?
Ik heb al vanalles geprobeerd, maar het probleem blijft steeds terugkomen.
Kunnen jullie eens meedenken?
Dit is de programmatie:
int drukknop1 = 4; // the number of the input drukknop1
int drukknop2 = 5; // the number of the input drukknop2
int drukknop3 = 6; // the number of the input drukknop3
int drukknop4 = 7; // the number of the input drukknop4
int Lamp1 = 8; // the number of the output Lamp1
int Lamp2 = 9; // the number of the output Lamp2
int Lamp3 = 10; // the number of the output Lamp3
int Lamp4 = 11; // the number of the output Lamp4
int state1 = HIGH; // the current state of the output Lamp1
int state2 = HIGH; // the current state of the output Lamp2
int state3 = HIGH; // the current state of the output Lamp3
int state4 = HIGH; // the current state of the output Lamp4
int reading1; // the current reading from the input drukknop1
int reading2; // the current reading from the input drukknop2
int reading3; // the current reading from the input drukknop3
int reading4; // the current reading from the input drukknop4
int previous1 = LOW; // the previous reading from the input drukknop1
int previous2 = LOW; // the previous reading from the input drukknop2
int previous3 = LOW; // the previous reading from the input drukknop3
int previous4 = LOW; // the previous reading from the input drukknop4
// the follow variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long time1 = 0; // the last time the output Lamp1 was toggled
long debounce1 = 1500; // the debounce time Lamp1, increase if the output flickers
long time2 = 0; // the last time the output Lamp2 was toggled
long debounce2 = 1500; // the debounce time Lamp 2, increase if the output flickers
long time3 = 0; // the last time the output Lamp3 was toggled
long debounce3 = 1500; // the debounce time Lamp3, increase if the output flickers
long time4 = 0; // the last time the output Lamp4 was toggled
long debounce4 = 1500; // the debounce time Lamp4, increase if the output flickers
void setup()
{
pinMode(drukknop1,INPUT_PULLUP);
pinMode(drukknop2,INPUT_PULLUP);
pinMode(drukknop3,INPUT_PULLUP);
pinMode(drukknop4,INPUT_PULLUP);
pinMode(Lamp1,OUTPUT);
pinMode(Lamp2,OUTPUT);
pinMode(Lamp3,OUTPUT);
pinMode(Lamp4,OUTPUT);
}
void loop()
{
reading1 = ! digitalRead(drukknop1);
// if the input just went from LOW and HIGH and we've waited long enough
// to ignore any noise on the circuit, toggle the output pin and remember
// the time
if (reading1 == HIGH && previous1 == LOW && millis() - time1 > debounce1) {
if (state1 == HIGH)
state1 = LOW;
else
state1 = HIGH;
time1 = millis();
}
digitalWrite(Lamp1, state1);
previous1 = reading1;
reading2 = ! digitalRead(drukknop2);
// if the input just went from LOW and HIGH and we've waited long enough
// to ignore any noise on the circuit, toggle the output pin and remember
// the time
if (reading2 == HIGH && previous2 == LOW && millis() - time2 > debounce2) {
if (state2 == HIGH)
state2 = LOW;
else
state2 = HIGH;
time2 = millis();
}
digitalWrite(Lamp2, state2);
previous2 = reading2;
reading3 = ! digitalRead(drukknop3);
// if the input just went from LOW and HIGH and we've waited long enough
// to ignore any noise on the circuit, toggle the output pin and remember
// the time
if (reading3 == HIGH && previous3 == LOW && millis() - time3 > debounce3) {
if (state3 == HIGH)
state3 = LOW;
else
state3 = HIGH;
time3 = millis();
}
digitalWrite(Lamp3, state3);
previous3 = reading3;
reading4 = ! digitalRead(drukknop4);
// if the input just went from LOW and HIGH and we've waited long enough
// to ignore any noise on the circuit, toggle the output pin and remember
// the time
if (reading4 == HIGH && previous4 == LOW && millis() - time4 > debounce4) {
if (state4 == HIGH)
state4 = LOW;
else
state4 = HIGH;
time4 = millis();
}
digitalWrite(Lamp4, state4);
previous4 = reading4;
}