Digital Input tester for plc

Hi all experts .. i work in a power plant .. new to arduino ..
we have some black box as we call it ,, sometimes we need to monitor the the digital outputs state if high to low or low to high .. after going through some examples and videos , i was able to write a code for monitoring output status ..

The problem is , its only for status change from low to high .. it would display which input has gone to high first ..

but most of the cases some inputs are high and some low is it possible to monitor // write a code for for monitoring both ..

what i wanted to is to install some dip switches and configure them as selection so that Arduino would read is as initial state high //low,, this way we don't have to program it every time

and keep a track .. let us know which input changed states ..

hear is what i was able to do .. this is only from low to high ..

#include <LiquidCrystal_I2C.h> / include LCD libraries

LiquidCrystal_I2C lcd(0x27, 20, 4); // initialize the LCD library with the numbers of the interface pins

int x=1;// take int value as 1

void setup() {
pinMode(9,INPUT);   //Digital pin 9 as 1st  input
pinMode(2,INPUT);   //Digital pin 2 as 2nd  input
pinMode(3,INPUT);   //Digital pin 3 as 3rd  input
pinMode(4,INPUT);   //Digital pin 4 as 4th  input
pinMode(5,INPUT);   //Digital pin 5 as 5th  input
pinMode(6,INPUT);  //Digital pin 6 as 6th  input
pinMode(7,INPUT);   //Digital pin 7 as 7th  input
pinMode(8,INPUT);   //Digital pin 8 as 8th  input
lcd.begin(); 
lcd.setCursor(0, 0);  // Print a message to the LCD.
lcd.print("Digital Input Tester");
}

void loop() 
{

 int a=digitalRead(9);   // reading pin values for 8 buttons
 int b=digitalRead(2);
 int c=digitalRead(3);
 int d=digitalRead(4);
 int e=digitalRead(5);
 int f=digitalRead(6);
 int g=digitalRead(7);
 int h=digitalRead(8);
            
     

if(a==LOW)  //if 1st input is high 
{       if(x==1)    // check if x is 1 if yes then execute the code
   {
lcd.setCursor(0, 1);  // Print a message to the LCD.
lcd.print("1st Input High");   
   
    x++;                     //increment x
     }
}
else if(b==LOW) //if 2nd input is high
{ 
 if(x==1) // check if x is 1 if yes then execute the code
      {
    lcd.setCursor(0, 2);  // Print a message to the LCD.
    lcd.print("2nd Input High");
         
         x++;
     }
}
if(c==LOW)  //if 3rd input is high
{       if(x==1)    // check if x is 1 if yes then execute the code
   {
lcd.setCursor(0, 3);  // Print a message to the LCD.
lcd.print("3rd Input High");

  
   
    x++;                     //increment x
     }
}
else if(d==LOW) //if 4th input is high
{ 
 if(x==1) // check if x is 1 if yes then execute the code
      {
    lcd.setCursor(0, 1);  // Print a message to the LCD.
    lcd.print("4th Input High");
         
         x++;
     }
}if(e==LOW)  //if 5th input is high
{       if(x==1)    // check if x is 1 if yes then execute the code
   {
lcd.setCursor(0, 2);  // Print a message to the LCD.
lcd.print("5th Input High");

  
   
    x++;                     //increment x
     }
}
else if(f==LOW) //if 6th input is high
{ 
 if(x==1) // check if x is 1 if yes then execute the code
      {
    lcd.setCursor(0, 3);  // Print a message to the LCD.
    lcd.print("6th Input High");
         
         x++;
     }
}if(g==LOW)  //if 7th input is high
{       if(x==1)    // check if x is 1 if yes then execute the code
   {
lcd.setCursor(0, 1);  // Print a message to the LCD.
lcd.print("7th Input High");

  
   
    x++;                     //increment x
     }
}
else if(h==LOW) //if 8th input is high
{ 
 if(x==1) // check if x is 1 if yes then execute the code
      {
    lcd.setCursor(0, 3);  // Print a message to the LCD.
    lcd.print("8th Input High");
         
         x++;
     }
}

}

link from which i copied most of the code and modified it as per my requirement

Thanks for the quick reply :wink:

The problem is that most power plants come equipped with black boxes.. what it means is that it will give only some common alarm to D.C.S .. not what caused the trip .. And most of the cases we cannot connect the P.G// P.C to the P.L.C as the code is proprietary ..
my idea was to monitor it external ..

And yes int not a Nuclear Plant :wink: you are safe :wink:

The code can be optimized by monitoring ports of 8 bits (pins) for any changes. Furthermore Pin Change Interrupts (PCINT) can be used to detect changed port pins, by either using interrupts or monitoring the port change flags.