Random trigger input 2

Hi, in my project the outputpin 8 and 9 are triggered by the program at a random (minutes between) moment. I suspect that pin 3 triggers both outputs but i have logged the inputvoltage and it is stable at 0,2V.
What am i doing wrong? Hardware? I use a pull down resistor with a switch. Software? The input reacts normal to the switch.

//  Pinnummers toewijzen aan IO
const int input1Pin = 3;      //  schakelaar bak voor
const int input2Pin = 5;      //  schakelaar pulsgever
const int input3Pin = 2;      //  schakelaar reset afstand
const int output1Pin =  9;    //  zwaailamp
const int output2Pin =  8;    //  toeter
const int output3Pin =  12;   //  reserve, lijken op de Arduino defect te zijn
const int output4Pin =  11;   //  reserve, lijken op de Arduino defect te zijn

#include <Ethernet.h>
#include <SPI.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 10, 0, 0, 100 };                        //  IP adres Arduino
byte server[] = { 10, 0, 0, 202 };                    //  IP adres lichtkrant

EthernetClient client;

//  Variabelen
int input1State = 0;                //  Actuele status input 1
int input2State = 0;                //  Actuele status input 2
int input3State = 0;                //  Actuele status input 3
int lastinput1State = 0;            //  Laatste status input 1
int lastinput2State = 0;            //  Laatste status input 2
int lastinput3State = 0;            //  Laatste status input 3
int input1StateOnes = 0;            //  Eenmalige status input 1
int sendstate = 0;                  //  Verzendstatus naar lichtkrant 0=geen tekst 1=tekst
unsigned long previousMillis = 0;   //  Vorige tijdseenheid waarbij wachttijd gestart is
const long interval = 3000;         //  Wachttijd (gebruikt om sirene beperkt af te laten gaan)

//  Opstartcyclus
void setup()
{
  // Initialiseren uitgangen
  pinMode(output1Pin, OUTPUT);
  pinMode(output2Pin, OUTPUT);  
  pinMode(output3Pin, OUTPUT);
  pinMode(output4Pin, OUTPUT);
  //  Initialiseren ingangen
  pinMode(input1Pin, INPUT);
  pinMode(input2Pin, INPUT);
  pinMode(input3Pin, INPUT);
  //  Uitgangen standaard uit zetten
  digitalWrite(output1Pin, HIGH);
  digitalWrite(output2Pin, HIGH);
  digitalWrite(output3Pin, HIGH);
  digitalWrite(output4Pin, HIGH);
  //  Ethernet en serieel (ivm monitoring code) activeren
  Ethernet.begin(mac, ip);
  Serial.begin(9600);
  //  Controle linksstatus Ethernet
  if (Ethernet.linkStatus() == LinkOFF) {
    Serial.println("Ethernet cable is not connected.");
  }
}

//  Hoofprogramma
void loop()
{
  //  Inlezen status input
  input1State = digitalRead(input1Pin);               //  ballastbak voor
  //  Status input 1 slechts 1 cyclus hoog (0=rust, 1=1 cyclus, 2=uitgevoerd)
  if (input1State == HIGH & input1StateOnes != 2) {
    input1StateOnes = 1;
  } else if (input1State == LOW) {
    input1StateOnes = 0;
  }
  input2State = digitalRead(input2Pin);               //  pulsgever as
  input3State = digitalRead(input3Pin);               //  reset afstand (nullen)

 // Sturen uitgangen
  if (input1State == HIGH) {
    digitalWrite(output1Pin, LOW);                    //  Zwaailicht AAN
  } else {
    digitalWrite(output1Pin, HIGH);                   //  Zwaailicht UIT
  }

  unsigned long currentMillis = millis();
  if (input1StateOnes == 1) {                         
    digitalWrite(output2Pin, LOW);                    //  Sirene AAN
    previousMillis = currentMillis;
    input1StateOnes = 2;
  } 
  if (digitalRead (output2Pin)== LOW) {               //  Sirene aan?
    if (currentMillis - previousMillis >= interval) { //  Na interval tijd weer uit zetten
      digitalWrite(output2Pin, HIGH);                 //  Sirene UIT
    }
  }
  
  //  TCP verbinding opzetten
  if (client.connect(server, 9100)) {
    Serial.println("Verbinding actief");
  } else {
    Serial.println("Verbinding verbroken");
  }
  //  Verzenden tekst naar lichtkrant ("FULL PULL")
  if (client.connected() & input1State == HIGH & sendstate == 0)
  {
    //  Verzenden bericht 1
    byte crapToSend1[] = {0xaa, 0xbb, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x20, 0x20};    //  Startbericht (vast)
    client.write(crapToSend1, 11);
    // Wachttijd
    delay (200);
    //  Verzenden bericht 2
    byte crapToSend2[] = {0xaa, 0xbb, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, 0x46, 0x02, 0x00, 0x01, 0x03, 0x00, 0x03, 0x00, 0x00, 0x00, 0x7e, 0x50, 0x31, 0x3b, 0x7e, 0x43, 0x31, 0x3b, 0x20, 0x20, 0x20, 0x46, 0x55, 0x4c, 0x4c, 0x20, 0x20, 0x20, 0x00, 0x03, 0x00, 0x03, 0x00, 0x00, 0x01, 0x7e, 0x50, 0x31, 0x3b, 0x7e, 0x43, 0x31, 0x3b, 0x20, 0x20, 0x20, 0x50, 0x55, 0x4c, 0x4c, 0x20, 0x20, 0x20, 0x00, 0x07, 0x00};  //  Te presenteren tekst
    client.write(crapToSend2, 64);
    //  Verzenden bericht 3
    byte crapToSend3[] = {0x00, 0x00, 0x01, 0x07, 0xe8, 0x03, 0x00, 0x09, 0x01, 0x07, 0x00, 0x00, 0x00, 0x01, 0x1f, 0xef};  //  Eindbericht met een vorm van Syntax oid (afhankelijk van inhoud bericht 2)
    client.write(crapToSend3, 16);
    Serial.println("Zenden bericht naar lichtkrant om tekst te tonen");

    sendstate = 1;
  }
  //  Verzenden geen tekst naar lichtkrant (beeld op zwart)
  if (client.connected() & input1State == LOW & sendstate == 1)
  {
    byte crapToSenduit1[] = {0xaa, 0xbb, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x20, 0x20};
    client.write(crapToSenduit1, 11);

    delay (200);

    byte crapToSenduit2[] = {0xaa, 0xbb, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, 0x46, 0x02, 0x00, 0x01, 0x03, 0x00, 0x03, 0x00, 0x00, 0x00, 0x7e, 0x50, 0x31, 0x3b, 0x7e, 0x43, 0x31, 0x3b, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, 0x03, 0x00, 0x03, 0x00, 0x00, 0x01, 0x7e, 0x50, 0x31, 0x3b, 0x7e, 0x43, 0x31, 0x3b, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, 0x07, 0x00};
    client.write(crapToSenduit2, 64);
    
    byte crapToSenduit3[] = {0x00, 0x00, 0x01, 0x07, 0xe8, 0x03, 0x00, 0x09, 0x01, 0x07, 0x00, 0x00, 0x00, 0x01, 0x1f, 0xf9};
    client.write(crapToSenduit3, 16);
    Serial.println("Zenden bericht naar lichtkrant om GEEN tekst te tonen");

    sendstate = 0;
  }

  //  Vertraging om de sturing niet onrustig te maken en de lichtkrant de tijd te geven
  delay (200);
}

this pins are used by SPI

little optimised. you should check marked line

//  Pinnummers toewijzen aan IO
const int input1Pin = 3;      //  schakelaar bak voor
const int input2Pin = 5;      //  schakelaar pulsgever
const int input3Pin = 2;      //  schakelaar reset afstand
const int output1Pin =  9;    //  zwaailamp
const int output2Pin =  8;    //  toeter
const int output3Pin =  12;   //  reserve, lijken op de Arduino defect te zijn
const int output4Pin =  11;   //  reserve, lijken op de Arduino defect te zijn

#include <Ethernet.h>
#include <SPI.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 10, 0, 0, 100 };                        //  IP adres Arduino
byte server[] = { 10, 0, 0, 202 };                    //  IP adres lichtkrant

EthernetClient client;

//  Variabelen
int input1State = 0;                //  Actuele status input 1
int input2State = 0;                //  Actuele status input 2
int input3State = 0;                //  Actuele status input 3
int lastinput1State = 0;            //  Laatste status input 1
int lastinput2State = 0;            //  Laatste status input 2
int lastinput3State = 0;            //  Laatste status input 3
int input1StateOnes = 0;            //  Eenmalige status input 1
int sendstate = 0;                  //  Verzendstatus naar lichtkrant 0=geen tekst 1=tekst
unsigned long previousMillis = 0;   //  Vorige tijdseenheid waarbij wachttijd gestart is
const long interval = 3000;         //  Wachttijd (gebruikt om sirene beperkt af te laten gaan)

//  Opstartcyclus
void setup()
{
  // Initialiseren uitgangen
  pinMode(output1Pin, OUTPUT);
  pinMode(output2Pin, OUTPUT);  
  pinMode(output3Pin, OUTPUT);
  pinMode(output4Pin, OUTPUT);
  //  Initialiseren ingangen
  pinMode(input1Pin, INPUT);
  pinMode(input2Pin, INPUT);
  pinMode(input3Pin, INPUT);
  //  Uitgangen standaard uit zetten
  digitalWrite(output1Pin, HIGH);
  digitalWrite(output2Pin, HIGH);
  digitalWrite(output3Pin, HIGH);
  digitalWrite(output4Pin, HIGH);
  //  Ethernet en serieel (ivm monitoring code) activeren
  Ethernet.begin(mac, ip);
  Serial.begin(9600);
  //  Controle linksstatus Ethernet
  if (Ethernet.linkStatus() == LinkOFF) {
    Serial.println("Ethernet cable is not connected.");
  }
}

//  Hoofprogramma
void loop(){
  //  Inlezen status input
  input1State = digitalRead(input1Pin);               //  ballastbak voor
  input2State = digitalRead(input2Pin);               //  pulsgever as
  input3State = digitalRead(input3Pin);               //  reset afstand (nullen)
  //  Status input 1 slechts 1 cyclus hoog (0=rust, 1=1 cyclus, 2=uitgevoerd)
  if (input1State == HIGH & input1StateOnes != 2) { //        << ----------------------------------------<< "&" OR "&&" ???
    input1StateOnes = 1;
  } else if (input1State == LOW) {
    input1StateOnes = 0;
  }

 // Sturen uitgangen
    digitalWrite(output1Pin, !input1State);                    //  Zwaailicht AAN
  
  unsigned long currentMillis = millis();
  if (input1StateOnes == 1) {                         
    digitalWrite(output2Pin, LOW);                    //  Sirene AAN
    previousMillis = currentMillis;
    input1StateOnes = 2;
  } 
  if (digitalRead (output2Pin)== LOW) {               //  Sirene aan?
    if (currentMillis - previousMillis >= interval) { //  Na interval tijd weer uit zetten
      digitalWrite(output2Pin, HIGH);                 //  Sirene UIT
    }
  }
  
  //  TCP verbinding opzetten
  if (client.connect(server, 9100))Serial.println("Verbinding actief");
   else     Serial.println("Verbinding verbroken");
  
  //  Verzenden tekst naar lichtkrant ("FULL PULL")
  if (client.connected() & input1State == HIGH & sendstate == 0)
  {
    //  Verzenden bericht 1
    byte crapToSend1[] = {0xaa, 0xbb, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x20, 0x20};    //  Startbericht (vast)
    client.write(crapToSend1, 11);
    // Wachttijd
    delay (200);
    //  Verzenden bericht 2
    byte crapToSend2[] = {0xaa, 0xbb, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, 0x46, 0x02, 0x00, 0x01, 0x03, 0x00, 0x03, 0x00, 0x00, 0x00, 0x7e, 0x50, 0x31, 0x3b, 0x7e, 0x43, 0x31, 0x3b, 0x20, 0x20, 0x20, 0x46, 0x55, 0x4c, 0x4c, 0x20, 0x20, 0x20, 0x00, 0x03, 0x00, 0x03, 0x00, 0x00, 0x01, 0x7e, 0x50, 0x31, 0x3b, 0x7e, 0x43, 0x31, 0x3b, 0x20, 0x20, 0x20, 0x50, 0x55, 0x4c, 0x4c, 0x20, 0x20, 0x20, 0x00, 0x07, 0x00};  //  Te presenteren tekst
    client.write(crapToSend2, 64);
    //  Verzenden bericht 3
    byte crapToSend3[] = {0x00, 0x00, 0x01, 0x07, 0xe8, 0x03, 0x00, 0x09, 0x01, 0x07, 0x00, 0x00, 0x00, 0x01, 0x1f, 0xef};  //  Eindbericht met een vorm van Syntax oid (afhankelijk van inhoud bericht 2)
    client.write(crapToSend3, 16);
    Serial.println("Zenden bericht naar lichtkrant om tekst te tonen");

    sendstate = 1;
  }
  //  Verzenden geen tekst naar lichtkrant (beeld op zwart)
  if (client.connected() & input1State == LOW & sendstate == 1)
  {
    byte crapToSenduit1[] = {0xaa, 0xbb, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x20, 0x20};
    client.write(crapToSenduit1, 11);

    delay (200);

    byte crapToSenduit2[] = {0xaa, 0xbb, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, 0x46, 0x02, 0x00, 0x01, 0x03, 0x00, 0x03, 0x00, 0x00, 0x00, 0x7e, 0x50, 0x31, 0x3b, 0x7e, 0x43, 0x31, 0x3b, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, 0x03, 0x00, 0x03, 0x00, 0x00, 0x01, 0x7e, 0x50, 0x31, 0x3b, 0x7e, 0x43, 0x31, 0x3b, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, 0x07, 0x00};
    client.write(crapToSenduit2, 64);
    
    byte crapToSenduit3[] = {0x00, 0x00, 0x01, 0x07, 0xe8, 0x03, 0x00, 0x09, 0x01, 0x07, 0x00, 0x00, 0x00, 0x01, 0x1f, 0xf9};
    client.write(crapToSenduit3, 16);
    Serial.println("Zenden bericht naar lichtkrant om GEEN tekst te tonen");

    sendstate = 0;
  }

  //  Vertraging om de sturing niet onrustig te maken en de lichtkrant de tijd te geven
  delay (200);
}

Thanks for the tip.

I think i solved the problem. I used a 10k pull down resistor but when i touch the input with my finger the input reacts. Very sensitive! I swapt the 10k to a 4,7k and for now the problem seems solved.

Schermafbeelding 2024-07-18 125717