#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Continuity Tester for 6-in, 12-out Cable Configuration using Arduino
// Pins for incoming cables
const int inPins[6] = {2, 3, 4, 5, 6, 7};
// Pins for outgoing cables (each inPin has two associated outPins)
const int outPins[12] = {8, A0, 9, A1, 10, A2, 11, A3, 12, A4, 13, A5};
LiquidCrystal_I2C lcd(0x27, 20, 4); // I2C address 0x27, 16 columns and 2 rows
// Push button pin
const int buttonPin = 1;
void setup() {
// Set up incoming pins as OUTPUT
for (int i = 0; i < 6; i++) {
pinMode(inPins[i], OUTPUT);
}
// Set up outgoing pins as INPUT
for (int i = 0; i < 12; i++) {
pinMode(outPins[i], INPUT);
}
// Set up push button pin as INPUT
pinMode(buttonPin, INPUT);
// Initialize LCD
lcd.init();
lcd.backlight();
// Initialize serial communication
Serial.begin(9600);
lcd.setCursor(0, 1);
lcd.print(" Cable Tester v3.");
lcd.setCursor(0, 2);
lcd.print(" Press X to Start");
}
void loop() {
if (digitalRead(buttonPin) == LOW) { //the ondition for the push button if LOW the program started
int success = 0;
int short1 = 0;
int short2 = 0;
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Checking");
delay(30); // Adjust the delay based on your requirements
lcd.setCursor(8,0);
lcd.print(".");
delay(30); // Adjust the delay based on your requirements
lcd.setCursor(9,0);
lcd.print(".");
delay(30); // Adjust the delay based on your requirements
lcd.setCursor(10,0);
lcd.print(".");
delay(30); // Adjust the delay based on your requirements
lcd.setCursor(11,0);
lcd.print(".");
delay(30); // Adjust the delay based on your requirements
lcd.setCursor(12,0);
lcd.print(".");
delay(30); // Adjust the delay based on your requirements
lcd.setCursor(13,0);
lcd.print(".");
delay(30); // Adjust the delay based on your requirements
lcd.setCursor(14,0);
lcd.print(".");
delay(30); // Adjust the delay based on your requirements
lcd.setCursor(15,0);
lcd.print(".");
delay(30); // Adjust the delay based on your requirements
lcd.setCursor(16,0);
lcd.print(".");
delay(30); // Adjust the delay based on your requirements
lcd.setCursor(17,0);
lcd.print("...");
// the Loop that go through each incoming cable using for loop and only work when the button was pressed
String errorMessages1 = ""; // declare for String to accumulate error messages for continuity at outpins 1
String errorMessages2 = ""; // declare for String to accumulate error messages for continuity at outpins 2
String shortMessage1 = ""; // declare for String for shorts detections that happen in group 1
String shortMessage2 = ""; // declare for String for shorts detections that happen in group 2
for (int i = 0; i < 6; i++) { //looping 6 times because we want to check only 6 inpins and 2 set of 6 outpins
// Set the current incoming pin LOW before the HIGH voltage is send voltage through the wire
int continuity1 = 0; //the initial output for outpins 1 (8,9,10,11,12,13) for open detection
int continuity2 = 0; //the initial output for outpins 2 (A0,A1,A2,A3,A4,A5) for open detection
digitalWrite(inPins[i], HIGH); //send the high voltage to 1 inpin to check the output in 2 outpin
delay(300); // Delay here is for stability and to make sure that the voltage has been send to correct pin
// Read the voltage on the corresponding pair of outgoing pins (exp: inpin 2 with outpins 8,A0)
continuity1 = digitalRead(outPins[i * 2]); //read the continuity for for outpins 1 (8,9,10,11,12,13)
continuity2 = digitalRead(outPins[i * 2 + 1]); //read the continuity for for outpins 2 (A0,A1,A2,A3,A4,A5)
printDebugInfo(i, continuity1, continuity2); // function for Print debug information to Serial Monitor
// condition here was for Checking the continuity and accumulate error messages for all outpins
if ((continuity1 == 1 && continuity2 == 0)) { // first condition that outpin1 is HIGH but outpin2 is LOW
errorMessages2 += "B" + String(i + 1); //prepare the message if outpin2 has open in it
} else if ((continuity1 == 0 && continuity2 == 1)) { //Second condition that outpin1 is LOW but outpin2 is HIGH
errorMessages1 += "A" + String(i + 1); //prepare the message if outpin1 has open in it
} else if ((continuity1 == 0 && continuity2 == 0)) { //third condition that outpin1 and outpin2 is LOW
errorMessages1 += "A" + String(i + 1); //prepare the message if outpin1 has open in it
errorMessages2 += "B" + String(i + 1); //prepare the message if outpin2 has open in it
} else { //if the outpin1 and outpin2 is HIGH so it will add 1 to success as a indicator for display result
success++; //success here as indicator as for success=6 so there are no open detected in the cable
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ...
// for loop here was to Check for shorts in a cable with other cables in the same inpins connection group
// all variables are declared and initialized before the loop to avoiding error while compiling the program
for (int j = i + 1; j < 6; j++) { // the loop start from j = i + 1 to avoid duplicate pairs bcs j != i
int otherContinuity1 = digitalRead(outPins[j * 2]); //read the other continuity for for outpins 1
int otherContinuity2 = digitalRead(outPins[j * 2 + 1]); //read the other continuity for for outpins 2
if (continuity1 == 1 && otherContinuity1 == 1) { //if the continuity and othercontinuity is HIGH so there is a short happen
char result1 = (i < 6) ? 'A' + i : 'F' + (i - 6); //declare all outpin1 as a character from A to F
char result2 = (j < 6) ? 'A' + j : 'F' + (j - 6); //declare all outpin1 as a character from A to F
Serial.print("Short1 detected: "); //the result will be print on serial to make easy to check error
Serial.print(result1); ////the result will be print on serial to make easy to check error
Serial.print("<=>"); ////the result will be print on serial to make easy to check error
Serial.println(result2); ////the result will be print on serial to make easy to check error
shortMessage1 += result1 + String("-") + result2 + " "; //prepare the message if outpin has short in it
short1 = short1 + 1; //indicator for checking short at outpin1 (8,9,10,11,12,13)
}
if (continuity2 == 1 && otherContinuity2 == 1) { //if the continuity and othercontinuity is HIGH so there is a short happen
char result3 = (i < 6) ? 'G' + i : 'L' + (i - 6); //declare all outpin1 as a character from G to L
char result4 = (j < 6) ? 'G' + j : 'L' + (j - 6); //declare all outpin1 as a character from G to L
Serial.print("Short2 detected: "); //the result will be print on serial to make easy to check error
Serial.print(result3); //the result will be print on serial to make easy to check error
Serial.print("<=>"); //the result will be print on serial to make easy to check error
Serial.println(result4); //the result will be print on serial to make easy to check error
shortMessage2 += result3 + String("-") + result4 + " "; //prepare the message if outpin has short in it
short2 = short2 + 1; //indicator for checking short at outpin2 (A0,A1,A2,A3,A4,A5)
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////// ...
}
digitalWrite(inPins[i], LOW); // Reset the current incoming pin to LOW
//Serial.println(success);
delay(700); // Adjust the delay based on your requirements
}
// Display accumulated error messages and short messages on the LCD
displayLCDResults(errorMessages1, errorMessages2, shortMessage1, shortMessage2,success,short1,short2);
}
}
// Function to print debug information to Serial Monitor
void printDebugInfo(int cableNumber, int continuity1, int continuity2) {
Serial.print("Cable " + String(cableNumber + 1) + " - Continuity1: " + String(continuity1) + ", Continuity2: " + String(continuity2));
if (continuity1 == 1 && continuity2 == 1) {
Serial.println(" RESULT : [Pass.]");
} else {
Serial.println(" RESULT : [Fail.]");
}
}
// Function to display results on LCD
void displayLCDResults(String errorMessages1, String errorMessages2, String shortMessage1, String shortMessage2,int success, int short1, int short2) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("NG:");
lcd.print(errorMessages1);
if(success == 6){
lcd.setCursor(4, 0);
lcd.print("No Open Detected");}
lcd.setCursor(0, 1);
lcd.print("NG:");
lcd.print(errorMessages2);
if(success == 6){
lcd.setCursor(4, 1);
lcd.print("No Open Detected");}
lcd.setCursor(0, 2);
lcd.print("S:" + shortMessage1);
if(short1 == 0){
lcd.setCursor(3,2);
lcd.print("No Short Detected");}
lcd.setCursor(0, 3);
lcd.print("S:" + shortMessage2);
if(short2 == 0){
lcd.setCursor(3,3);
lcd.print("No Short Detected");}
delay(1000); // Display for 3 seconds
}