Spooklichten met relaisbord en arduino Yun

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;
}

Kun je aangeven wat je geprobeerd hebt?

Het is mogelijk dat je storing oppikt uit the omgeving op het moment dat je buitenverlichting wordt geschakeld.

Kun je aub je post bewerken, alle code selecteren en op de </> knop drukken om zogenaamde code-tags toe te voegen en vervolgens je post weer opslaan. Het maakt het gemakkelijker om te lezen, gemakkelijker om te kopieren en het voorkomt dat de forum software delen van de code als instructies ziet.

Ik mis een hoop haken rond de ifs en de juiste inspringeingen erbij, de tijd zoals time1 moet je doen als de voorwaarden true zijn dus haakjes en plaats is belangrijk.
probeer het eerst even zelf te doen, dan leer je ervan. voor een start heb je goed programma hoor ga zo door.
even op papier zetten wat je wilt dan zie je ook snel wat verkeerd gaat (als je iets aanzet moet er ook een uitzetten zijn want niks gaat vanzelf.

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;
}

Beste sterretje,
heb de code ingegeven zoals jij gevraagd hebt.

Wat heb ik geprobeerd:

  • Bedrading arduino uitgewisseld.
  • De fase van de lampen verwisseld.
  • De signaalkabels van de drukknoppen en de stroomkabels naar de lampen uit elkaar gelegd in de kabelgoot.

Deze week heb ik de arduino zonder spanning gezet, maar het relaisbord niet.
Nu komen de spooklichten niet meer voor. Het schakelen met de drukknoppen lukt dan ook niet.
Ik vermoed dat het iets met de ingangen te maken heeft.
Het lijkt erop dat af en toe een ingang een puls krijgt, als de externe bewegingssensor zijn relais schakelt.
Het circuit van de bewegingssensor is volledig gescheiden van het circuit van de arduino.

mvg,

Roeland

Ik ben niet meer veel van een electronica ingenieur. Ik zou eerst proberen om de lampen (inclusief de buitenverlichting) los te koppelen en te kijken of het probleem dan verdwijnt.

Wat is de afstand van de knoppen tot de Yun? Paar centimeter of een (paar) meter?

Hoewel het niet de oorzaak is van je probleem zouden alle variabelen die gerelateerd zijn aan je timing van het type unsigned long moet zijn.

Wat wel een probleem kan zijn is dat je timeX iedere keer ge-update moet worden als als er een verandering op een ingang is; nu gebeurt dat alleen na een 'time out' dus je ontdenderen werkt niet helemaal zoals je verwacht; bestudeer het 'debounce' voorbeeld in de IDE (nog een keer?).

De afstand van de knoppen tot de Yun is 40 cm.

Ik heb de lampen + beweginssensor al losgekoppeld (was ik vergeten schrijven), en dan verdwijnt het probleem. Dan is een normale bediening mogelijk.
Het probleem zit dus in de beweginssensor + bijhorende relais. Die veroorzaakt af en toe een puls op een ingang van de arduino. De ingang die dan hoog gezet wordt varieert telkens tussen 1 van de 4.

Als je alleen de lampen loskoppelt en de rest houdt zoals het is, verdwijnt het probleem dan?

Kun je een schema tekenen hoe alles is aangesloten (zowel Arduino + relais en bewegings sensor en relais)? Een foto van een handgetekend schema is OK. Belangrijk is ook hoe alles wordt gevoed; het moet duidelijk wordt de bewegings sensor/relais gevoed van dezelfde voeding als de Arduino plus relais?

Wat voor lampen gebruik je?

Zoals gezegd, ik ben niet meer veel van een electronica ingenieur dus ik ben waarschijnlijk niet in de positie om je veel verder te helpen.

Ik zie dat je pull up doet, maar dat is een hoge weerstand, zet er een weerstand van 10 kiloohm naast dat zal helpen om de stoorpieken weg te krijgen, net zoals zoek een manier om de voeding te ontkoppelen dus een voeding voor de ingangen en een voeding voor de relais en de rest.

Een schema van de opstelling

Schematic_arduino yun met relaissturing_2021-09-22.pdf (731.9 KB)

drukknoppen_stal_Wim.ino (2.5 KB)
Dit is de laatste stand van het programma. Het is anders geprogrammeerd nu. Spijtig genoeg is het probleem nog niet opgelost.

@shooter, zal ik dan een pulldown weerstand gebruiken, en geen pull-up?
Kan het mogelijks aan de voeding liggen? Als de beweginssensor de relais schakelt, kan die dan een storingspiek naar beneden voorzaken op de arduino.
Zodat het lijkt alsof er op een knop gedrukt wordt.
Alle tips zijn welkom.

Als je twijfels over de voeding hebt, geef dan beide kaarten hun eigen voedinglijn naar de voeding en eventueel kan je vlak bij de aansluiting van de Arduino een elco van ca 1000uf plaatsen, dat moet eventuele dips in de voeding wel opvangen.

Kees

Zet de arduino op zijn eigen onafhanelijke voeding en met een optocoupler 4n35 kun je dan doen wat je zelf wil, en ja een relais is een flinke bron van storing door de hoge pieken als het relais stopt.

Hallo, nog bedankt voor het meedenken allemaal. Mijn excuses voor de late reactie.
Het is opgelost. Ik heb een vertraging op mijn drukknoppen gezet van 50 ms.
Nu komt de storing er niet meer door.

Zie code:

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


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()
{
  static bool state1 = HIGH;      // the current state of the output lamp1
  static bool state2 = HIGH;      // the current state of the output lamp2
  static bool state3 = HIGH;      // the current state of the output lamp3
  static bool state4 = HIGH;      // the current state of the output lamp4

  static bool previous1 = LOW;    // the previous reading from the input drukknop1
  static bool previous2 = LOW;    // the previous reading from the input drukknop2
  static bool previous3 = LOW;    // the previous reading from the input drukknop3
  static bool previous4 = LOW;    // the previous reading from the input drukknop4

  bool reading1;           // the current reading from the input drukknop1
  bool reading2;           // the current reading from the input drukknop2
  bool reading3;           // the current reading from the input drukknop3
  bool reading4;

  reading1 = digitalRead(drukknop1);
  delay(50);
  if (reading1 != previous1) {

    previous1 =  reading1;
    if (reading1 == 0) {
      state1 = not state1;
      digitalWrite(lamp1, state1);
    }

    delay(50);

  }


  reading2 = digitalRead(drukknop2);
  delay(50);
  if (reading2 != previous2) {

    previous2 =  reading2;
    if (reading2 == 0) {
      state2 = not state2;
      digitalWrite(lamp2, state2);
    }

    delay(50);

  }

  reading3 = digitalRead(drukknop3);
  delay(50);
  if (reading3 != previous3) {

    previous3 =  reading3;
    if (reading3 == 0) {
      state3 = not state3;
      digitalWrite(lamp3, state3);
    }

    delay(50);

  }

  reading4 = digitalRead(drukknop4);
  delay(50);
  if (reading4 != previous4) {

    previous4 =  reading4;
    if (reading4 == 0) {
      state4 = not state4;
      digitalWrite(lamp4, state4);
    }

    delay(50);

  }
}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.