Arduino Yun, ingangen schakelen vanzelf verlichting aan.

Hardware geleverd door Arduino
Berichten: 2
Geregistreerd: 12 Nov 2021, 20:29

Arduino Yun, ingangen schakelen vanzelf verlichting aan.

Berichtdoor Roeland » 19 Nov 2021, 20:34

Beste,

ik heb tuinverlichting + verlichting in mijn tuinhuis geïnstalleerd.(4 kringen)
Nu is het de bedoeling om deze verlichting vanop afstand te schakelen dmv een arduino Yun + 4-relais board.
De arduino Yun bevindt zich op een DIN-rail en wordt gevoed door een aparte 5V-voeding.

De schakeling werkt meestal goed.
Nu is er af een toe een probleem met een externe relais (eltako), geschakeld door een bewegingssensor.

Als de bewegingssensor de relais laat schakelen wordt er af en toe een puls veroorzaakt op de ingangen van de arduino.
Dit is een externe relais die enkel door de bewegingssensor bediend wordt, deze wordt niet gestuurd door de arduino.

Dan lijkt het of er iemand op de drukknoppen drukt, maar dit is niet het geval, waardoor mijn tuin -of tuinhuisverlichting automatisch aan schakelt.

Heeft al iemand zo'n probleem gehad, het lijkt dat de ingangen van de arduino geactiveerd worden door de bewegingssensor?
(maar alles is gescheiden van elkaar)

Kunnen jullie meekijken a.u.b.?

Dit is het programma:

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


Kan er i

Advertisement

Berichten: 4064
Geregistreerd: 16 Okt 2013, 14:31
Woonplaats: s hertogenbosch

Re: Arduino Yun, ingangen schakelen vanzelf verlichting aan.

Berichtdoor shooter » 20 Nov 2021, 09:35

millis() - time1 > debounce1 dit lijkt ook fout., en is het wellicht dat pullup niet voldoende is dus een weerstand om de ingangen hoog te houden. Is de Gnd goed aangesloten en is het een beetje goed aanelkaar gezet want 230 en V kunnen storen
paul deelen
shooter@home.nl

Berichten: 45
Geregistreerd: 08 Jan 2020, 17:23

Re: Arduino Yun, ingangen schakelen vanzelf verlichting aan.

Berichtdoor RonalT » 26 Dec 2021, 14:27

Een relaisspoel kan een spanningspiek genereren, daarom worden er in de betere relais vrijloop- of blusdiode gebouwd. Deze diode kan de piek grotendeels wegleiden.

Zie het eerste schemaatje in de volgende link. http://www.knutselaar.eu/WP/relais-tips-en-weetjes/

Berichten: 4064
Geregistreerd: 16 Okt 2013, 14:31
Woonplaats: s hertogenbosch

Re: Arduino Yun, ingangen schakelen vanzelf verlichting aan.

Berichtdoor shooter » 27 Dec 2021, 09:15

ik denk dat het inderdaad debounce is die jou af en toe nekt. en ook mis ik een groot aantal haakjes.
ik weet zelf ook wel dat dit soort toevallige fouten heel erg moeilijk is te vinden, maar een debounce van 1,5 seconde is wel erg overdreven.
verder zorg voor een goede scheiding tussen de 5 Volt en de 230 Volt want een relais geeft bij uitschakelen een piek van zeker 1000 volt en moet dus goed geblust worden met een diode of een snubber.
paul deelen
shooter@home.nl

Berichten: 2
Geregistreerd: 12 Nov 2021, 20:29

Re: Arduino Yun, ingangen schakelen vanzelf verlichting aan.

Berichtdoor Roeland » 27 Jan 2022, 22:03

Beste,

het probleem is opgelost. Ik heb een vertraging (delay) van 50 ms toegevoegd na het indrukken van de knop.
Storingen heb ik sindsdien niet meer gehad.
Code: Alles selecteren

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

  }
}


Terug naar Arduino hardware

Wie is er online?

Gebruikers in dit forum: Geen geregistreerde gebruikers en 12 gasten