Arduino Continuity Tester

Hello, I am new to Arduino and I've stuck myself with a problem that I can't resolve on my own.
I am using a code i found on this forum to test a cable for continuity, short or open but I need to modify it to include two more wires. My issue is that the two wires I am adding are splices and each has 3 ends. So for 1 wire I will be needing 3 pins to test it. My issue is when i try to do something it either passes the test even when i disconnect one of the wires, or it is showing short when the connections are good. Can you help me modify the code? You assign the pins as you please.
Thanks a lot in advance.

// Cable Tester by "jurs" for Arduino forum
enum {PASS, FAIL_NOTCONNECTED, FAIL_WRONGCONNECTED, FAIL_SHORTENED };

// pin numbers for use at begin and end of cable
const byte pinsCableBegin[]= { 2, 3, 4, 5,  };
const byte pinsCableEnd[]  = {11,12,13,A0 };
const byte NUMCABLES=sizeof(pinsCableBegin);

void setup() {
  Serial.begin(9600);
  if (sizeof(pinsCableBegin)!=sizeof(pinsCableEnd))
  {
    Serial.println("Wrong cable pin configuration!");
    Serial.println("Fix declaration of pinsCableBegin[] and pinsCableEnd[] arrays!");
    while(1); // error stop with endless loop
  }  
  Serial.println();
  Serial.println("################################################");
  Serial.println("#                CABLE TESTER                  #");
  Serial.println("################################################");
  Serial.println();
}

void allPinsInputHigh()
{ // set all pins to INPUT_PULLUP in a for-loop
  for (byte i=0;i<NUMCABLES;i++)
  {
    pinMode(pinsCableBegin[i],INPUT_PULLUP);
    pinMode(pinsCableEnd[i],INPUT_PULLUP);
  }
}


void DoOneTest()
{
  byte result;
  Serial.println();
  Serial.println("### TEST ###");
  for (byte i=0;i<NUMCABLES;i++) // test each pin 
  {
    result= PASS; // initially there is no error found, assume PASS
    allPinsInputHigh();
    // first test is for continuity and OUTPUT/HIGH
    pinMode(pinsCableBegin[i], OUTPUT);
    if (digitalRead(pinsCableEnd[i])!=HIGH)
    {
        bitSet(result,FAIL_NOTCONNECTED);
    }
    // then check for continuity and OUTPUT/LOW
    digitalWrite(pinsCableBegin[i], LOW);
    if (digitalRead(pinsCableEnd[i])!=LOW)
    {
        bitSet(result,FAIL_NOTCONNECTED);
    }
    
    // next test: check for wrong connections to other pins
    for (byte j=0;j<NUMCABLES;j++)
    {
      if (j!=i && digitalRead(pinsCableEnd[j])==LOW)
      {
        bitSet(result, FAIL_WRONGCONNECTED);
      }  
    }
    // final test for short circuit against other pins
    for (byte j=0;j<NUMCABLES;j++)
    {
      if (j!=i && digitalRead(pinsCableBegin[j])==LOW)
      {
        bitSet(result, FAIL_SHORTENED);
      }  
    }
    Serial.print("Line ");
    Serial.print(i+1);
    if (result== PASS) Serial.print(" PASS");
    else Serial.print(" FAIL");
    if (bitRead(result,FAIL_NOTCONNECTED)) Serial.print(" BREAK");
    if (bitRead(result,FAIL_WRONGCONNECTED)) Serial.print(" WRONG");
    if  (bitRead(result,FAIL_SHORTENED)) Serial.print(" SHORT");
    Serial.println();
  }
  Serial.println("Test finished.");
  Serial.println();
}

void loop() {
  if (Serial.available())
  {
    DoOneTest();
    delay(20);
    while (Serial.available()) Serial.read(); // clear Serial input buffer
  }
}

Can you show us what was your best attempt to modify jurs's code?

From I can see you have modified only this lines:

const byte pinsCableBegin[]= { 2, 3, 4, 5, 6, 7, 8, 9,10 };
const byte pinsCableEnd[]  = {11,12,13,A0,A1,A2,A3,A4,A5 };

This is a code i've had ChatGPT generate me, but it's not giving me the desired results.

// Cable Tester by "jurs" for Arduino forum
enum {PASS, FAIL_NOTCONNECTED, FAIL_WRONGCONNECTED, FAIL_SHORTENED };

// pin numbers for use at begin and end of cable
const byte pinsCableBegin[]= { 2, 3, 4, 5, 6, 7 };
const byte pinsCableEnd[]  = {11,12,13,A0, 9, 10, A1 };
const byte NUMCABLES=sizeof(pinsCableBegin);

void setup() {
  Serial.begin(9600);
  if (sizeof(pinsCableBegin)!=sizeof(pinsCableEnd))
  {
    Serial.println("Wrong cable pin configuration!");
    Serial.println("Fix declaration of pinsCableBegin[] and pinsCableEnd[] arrays!");
    while(1); // error stop with endless loop
  }  
  Serial.println();
  Serial.println("################################################");
  Serial.println("#                CABLE TESTER                  #");
  Serial.println("################################################");
  Serial.println();
}

void allPinsInputHigh()
{ // set all pins to INPUT_PULLUP in a for-loop
  for (byte i=0;i<NUMCABLES;i++)
  {
    pinMode(pinsCableBegin[i],INPUT_PULLUP);
    pinMode(pinsCableEnd[i],INPUT_PULLUP);
  }
}


void DoOneTest()
{
  byte result;
  Serial.println();
  Serial.println("### TEST ###");
  for (byte i=0;i<NUMCABLES;i++) // test each pin 
  {
    result= PASS; // initially there is no error found, assume PASS
    allPinsInputHigh();
    // first test is for continuity and OUTPUT/HIGH
    pinMode(pinsCableBegin[i], OUTPUT);
    if (digitalRead(pinsCableEnd[i])!=HIGH)
    {
        bitSet(result,FAIL_NOTCONNECTED);
    }
    // then check for continuity and OUTPUT/LOW
    digitalWrite(pinsCableBegin[i], LOW);
    if (digitalRead(pinsCableEnd[i])!=LOW)
    {
        bitSet(result,FAIL_NOTCONNECTED);
    }
    
    // next test: check for wrong connections to other pins
    for (byte j=0;j<NUMCABLES;j++)
    {
      if (j!=i && digitalRead(pinsCableEnd[j])==LOW)
      {
        bitSet(result, FAIL_WRONGCONNECTED);
      }  
    }
    // final test for short circuit against other pins
    for (byte j=0;j<NUMCABLES;j++)
    {
      if (j!=i && digitalRead(pinsCableBegin[j])==LOW)
      {
        bitSet(result, FAIL_SHORTENED);
      }  
    }
    Serial.print("Line ");
    Serial.print(i+1);
    if (result== PASS) Serial.print(" PASS");
    else Serial.print(" FAIL");
    if (bitRead(result,FAIL_NOTCONNECTED)) Serial.print(" BREAK");
    if (bitRead(result,FAIL_WRONGCONNECTED)) Serial.print(" WRONG");
    if  (bitRead(result,FAIL_SHORTENED)) Serial.print(" SHORT");
    Serial.println();
  }
  
  // test two additional spliced cables
  for (byte i = NUMCABLES; i < NUMCABLES + 2; i++) {
    result = PASS;
    allPinsInputHigh();
    pinMode(pinsCableBegin[i], OUTPUT);
    digitalWrite(pinsCableBegin[i], LOW);
    for (byte j = NUMCABLES; j < NUMCABLES + 2; j++) {
      if (j != i && digitalRead(pinsCableEnd[j]) == LOW) {
        bitSet(result, FAIL_WRONGCONNECTED);
      }
    }
    for (byte j = 0; j < NUMCABLES; j++) {
      if (digitalRead(pinsCableBegin[j]) == LOW) {
        bitSet(result, FAIL_SHORTENED);
      }
    }
    for (byte j = NUMCABLES + 2; j < NUMCABLES * 2; j++) {
      if (digitalRead(pinsCableEnd[j]) == LOW) {
        bitSet(result, FAIL_SHORTENED);
      }
    }
    Serial.print("Additional Cable ");
    Serial.print(i - NUMCABLES + 1);
    if (result == PASS) Serial.print(" PASS");
    else Serial.print(" FAIL");
    if (bitRead(result, FAIL_WRONGCONNECTED)) Serial.print(" WRONG");
    if (bitRead(result, FAIL_SHORTENED)) Serial.print(" SHORT");
    Serial.println();
  }
  
  Serial.println("Test finished.");
  Serial.println();
}

How about try learn the basic a little bit then modify the code by yourself?

Ask again!

Of course not. It's not a programmer.

With the increasing use of ChatGPT, I t'ink it's time to withdraw. It's hard enough reading a noob's mind, let alone a noob advised by artificial insemination.
I'm done.

1 Like

How about...

You think about how this feature should work (using ideas, expressions, not program code). Come back here with a good description of how the test should be performed, and then people might help you with the coding part.

At the moment, you are asking us to research, design, and also implement it. You should do some of the work yourself.

Ask her/him/them/it to solve your problem.

1 Like

I know because I've tried. When cornered, chatGPT tap dances.

It will just apologize.

Wow, I just needed help making 3 pins test connectivity between them, didn't think i't would be such a big deal for you. Some of you seemed really offended by the use of ChatGPT, well I'm not a programmer, I did not know what to do and I asked a thing that would not be mad at me for asking. Sorry for bothering you guys :slight_smile:

The forum has a handy feature that will allow me to never see any of your posts again...

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