Arduino mega continuity and short tester

Hello everyone,

I am searching for guidance in creating a continuity and short tester made of Arduino Mega.

I have some cables with 19 pin connector on one side and another one on the other side in total 38 pins.
The idea is to have a test for:
-short between pins
-continuity test

And all the results, and by results I mean if its is OK or Not OK, and for Not OK to tell me where is the problem between which pin is the short or the continuity issue and all of these to be displayed on a 16x2 LCD that uses I2C.

My list of parts so far are an Arduino Mega 2560, an blue LCD 16x2 and an I2C board for LCD.

I am hoping someone can help me and tell me how can i create this tester.

Best regards,
Paul L.

Is Google broken today? This kind of request is very common. I'm surprised you can't find some examples online. I will advise you to stay away from Instructables. Those projects are universally useless. But they can give you some good ideas to pursue.

What is your programming experience?

Do you have additional 19-pin connectors so that you can easily plug the cable-under-test into your tester?

Search
Arduino cable tester

A common test is a “walking one’s” test where you drive one line high while driving all the other lines low. Then of course, read the data at the other end to make sure it matches. Then, step to next line, etc…

In binary, a 4-bit walking one looks like this:
0001
0010
0100
1000

It pretty easy to identify an open or shorted line, but determining which line is shorted to which, or exactly how the cable is mis-wired or defective takes a bit more “software”.

Of course, you need current limiting resistors so a short doesn’t fry your Arduino.

…Where I work we test 8-bit I/O ports (not cables & not Arduino) with walking ones, or some of our tests just write all of the binary values from 0-255 (0-FF hex) and when there’s an error it shows the read & write hex* values so we can figure-out what’s wrong. (It usually takes a little more testing to figure-out exactly what’s wrong, and there’s a way we can type-in hex values to test.)

…I’ve seen some old-time testers that simply have an LED on each line. One LED at a time comes on in-sequence and you have watch to see if one of the LEDs doesn’t come-on, or if two LEDs come-on at once, or if they come-on out-of sequence.

  • Hex easier than decimal because it’s easy to convert between hex an binary. You can learn to do hex-binary conversions of any size in your head.

MorganS:
Is Google broken today? This kind of request is very common. I’m surprised you can’t find some examples online. I will advise you to stay away from Instructables. Those projects are universally useless. But they can give you some good ideas to pursue.

What is your programming experience?

Do you have additional 19-pin connectors so that you can easily plug the cable-under-test into your tester?

My experience in programming is very basic, i have the male and the female connectors of the cable that i need to test, i can wire it directly but i need a program.

So far i come up with this code, but nothing works… :frowning:

//LCD
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>  // F Malpartida's NewLiquidCrystal library


#define I2C_ADDR    0x27  // Define I2C Address for controller
#define BACKLIGHT_PIN  7
#define En_pin  4
#define Rw_pin  5
#define Rs_pin  6
#define D4_pin  0
#define D5_pin  1
#define D6_pin  2
#define D7_pin  3

#define  LED_OFF  0
#define  LED_ON  1
LiquidCrystal_I2C  lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin); 
int endA[10] = {30,31,28,29,26,27,24,25,22,23}; //pins end A
int endB[10] = {41,43,38,39,36,37,34,35,32,33}; //pins endB
int pSwitch=  49;
int pEncA= 59;
int pEncB= 63;

//results
int result[10] = {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1};
int test[10] = {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1};
int counter[10] = {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1};
bool fail =false;

void setup() {

  Serial.begin(115200); //serial used for debugging only
  lcd.begin(16,2);
  lcd.setBacklightPin(BACKLIGHT_PIN,NEGATIVE);
  lcd.setBacklight(LED_ON);
  
  //setup pins  
  for(int i=0; i<10; i++){
      pinMode(endA[i], OUTPUT);//set output pins (end A)
      pinMode(endB[i], INPUT_PULLUP);//set input pins (end B)
  }
  pinMode(pSwitch,INPUT_PULLUP);

}

void loop() {
    lcd.clear();
  delay(1000);
  lcd.home();
 //run the test
 runTest_5x2();
}

void runTest_5x2(){
  String resultS="";
  //user interface
  lcd.clear();
  lcd.print("Cable Tester 5x2"); 
  lcd.setCursor(0,1);
  lcd.print("Press Enc to Start");
  
  while(digitalRead(pSwitch))
  {
    delay(100);
  }
  delay(700); //debounce
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Testing: 5x2");
  lcd.setCursor(0,1);
  for(int i=0; i<10; i++){
     counter[i]=0;
    for(int j=0; j<10; j++){
        digitalWrite(endA[i], LOW); //set all outputs to LOW
    }
    for(int j=0; j<10; j++){  //check for crossed / open circuits vs closed, good, circuits
        digitalWrite(endA[j], HIGH); //scan across the inputs in turn
        test[i] = digitalRead(endB[i]); //read the output
        if(test[i] == 1 && j!=i){ //crossed or open circuit
          counter[i]++;
          result[i] = 20+j; 
        }
        else if(test[i] == 1 && j==i && result[i] <20 ){ //Good, closed circuit
          result[i] = 0; 
        }
        digitalWrite(endA[j],LOW);
        //debugging
        
          Serial.print("test1 input core  ");
          Serial.print(i);
          Serial.print(" with output core  ");
          Serial.print(j);
          Serial.print(" test =");
          Serial.print(test[i]);
          Serial.print(" counter =");
          Serial.println(counter[i]);
    }
    Serial.print("Core ");
    Serial.print(i);
    Serial.print(" result = ");
    if(result[i] == 0){
       Serial.println(" 1");
       resultS+="1";
    }
    else if(counter[i] == 9){
       Serial.println(" O");
       resultS+="0";
       fail=true;
    }
    else {
       Serial.println(" X");
       resultS+="X";
       fail=true;
    }
  }
  
  lcd.print(resultS); 
  lcd.setCursor(0,2);
 
 if(fail){
   Serial.println("FAILED");
   lcd.print("FAILED");
 }
 else{
   Serial.println("PASSED");
   lcd.print("PASSED");
 }
 Serial.println();
 lcd.setCursor(0,3);
 lcd.print("Press Enc to Restart");
   while(digitalRead(pSwitch))
  {
    delay(100);
  }
  delay(700); //debounce
}

Don't use [ quote ]. Use [ code ] instead. You can edit your post to fix the mistake.

"Nothing works" is the most useless thing you can say. Something works. There must be an error message displayed by the compiler or the code does something when it runs on the Arduino. Tell us if the LCD is blank or whatever actually happens.

Hi,
What do you mean "nothing works"?

Do you get a display on the LCD?

If not then write some code JUST to test the LCD, get it working first, forget about the rest for the moment.

Tom... :slight_smile:

Hi Tom,

I tested the LCD it`s working fine, but with this code it wont turn on...

Hi,
What do you get on the monitor

Tom... :slight_smile:

Hy Tom,

O the monitor I get full line of withe dots on the first line of the display…

I found this code on forum :smiley: mabe by “jurs”. I need some help change it in order to use a push button to start the test and all the result to be moved from serial monitor to an LCD with I2C, the address of the LCD is (0x27) and it`s useing pin21_SCL, pin20_SDA 5V and GND. I will try to modify the code by myself but if its anyone with more experience then me and could do that the help is welcome :slight_smile:

// 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, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 };
const byte pinsCableEnd[]  = {22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 31, 33, 34,35, 36, 37, 38 };
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
  }
}

Hi,
Can you post us the code that just makes your display work, nothing else, so we can compare to your malfunctioning working code?

Thanks.. Tom... :slight_smile:

This is the test code that is working with my display

/*
** Example Arduino sketch for SainSmart I2C LCD Screen 16x2
** based on https://bitbucket.org/celem/sainsmart-i2c-lcd/src/3adf8e0d2443/sainlcdtest.ino
** by
** Edward Comer
** LICENSE: GNU General Public License, version 3 (GPL-3.0)

** This example uses F Malpartida's NewLiquidCrystal library. Obtain from:
** https://bitbucket.org/fmalpartida/new-liquidcrystal 

** Modified - Ian Brennan ianbren at hotmail.com 23-10-2012 to support Tutorial posted to Arduino.cc

** Written for and tested with Arduino 1.0
**
** NOTE: Tested on Arduino Uno whose I2C pins are A4==SDA, A5==SCL

*/
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>

#define I2C_ADDR    0x27 // <<----- Add your address here.  Find it from I2C Scanner
#define BACKLIGHT_PIN     3
#define En_pin  2
#define Rw_pin  1
#define Rs_pin  0
#define D4_pin  4
#define D5_pin  5
#define D6_pin  6
#define D7_pin  7

int n = 1;

LiquidCrystal_I2C  lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);

void setup()
{
 lcd.begin (16,2); //  <<----- My LCD was 16x2

 
// Switch on the backlight
lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
lcd.setBacklight(HIGH);
lcd.home (); // go home

 lcd.print("SainSmartI2C16x2");  
}

void loop()
{
 // Backlight on/off every 3 seconds
 lcd.setCursor (0,1);        // go to start of 2nd line
 lcd.print(n++,DEC);
 lcd.setBacklight(LOW);      // Backlight off
 delay(3000);
 lcd.setBacklight(HIGH);     // Backlight on
 delay(3000);
}

Hi,
With the malfunctioning code, what do you get on the IDE monitor?

Tom.... :slight_smile:

Hi,
Can you run this code and tell me what the LCD displays?

/*
** Example Arduino sketch for SainSmart I2C LCD Screen 16x2
** based on https://bitbucket.org/celem/sainsmart-i2c-lcd/src/3adf8e0d2443/sainlcdtest.ino
** by
** Edward Comer
** LICENSE: GNU General Public License, version 3 (GPL-3.0)

** This example uses F Malpartida's NewLiquidCrystal library. Obtain from:
** https://bitbucket.org/fmalpartida/new-liquidcrystal 

** Modified - Ian Brennan ianbren at hotmail.com 23-10-2012 to support Tutorial posted to Arduino.cc

** Written for and tested with Arduino 1.0
**
** NOTE: Tested on Arduino Uno whose I2C pins are A4==SDA, A5==SCL

*/
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>

#define I2C_ADDR    0x27 // <<----- Add your address here.  Find it from I2C Scanner
#define BACKLIGHT_PIN     3
#define En_pin  2
#define Rw_pin  1
#define Rs_pin  0
#define D4_pin  4
#define D5_pin  5
#define D6_pin  6
#define D7_pin  7

int n = 1;

LiquidCrystal_I2C  lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);

void setup()
{
 lcd.begin (16,2); //  <<----- My LCD was 16x2

 
// Switch on the backlight
lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
lcd.setBacklight(HIGH);
lcd.home (); // go home

 lcd.print("SainSmartI2C16x2");  
}

void loop()
{
 // Backlight on/off every 3 seconds
 delay(3000);
 lcd.setCursor (0,1);        // go to start of 2nd line
 lcd.print("Hello World");
 lcd.setBacklight(LOW);      // Backlight off
 delay(3000);
 lcd.setBacklight(HIGH);     // Backlight on
 
}

Thanks… Tom… :slight_smile:

It`s blinking and shows on the first row "SainSmartI2C16x2" and on the second "Hello World"

Tom, if you will can you please help me to convert this code from serial monitor to lcd print and add a button to start the program instead of writing “Test” in serial monitor?

You can remove this

  Serial.println();
  Serial.println("################################################");
  Serial.println("#                CABLE TESTER                  #");
  Serial.println("################################################");
  Serial.println();

and add something to fit the 16x2LCD

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, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 22 };
const byte pinsCableEnd[]  = {23, 24, 25, 26, 27, 28, 29, 30, 31, 31, 33, 34,35, 36, 37, 38, 29, 40, 41 };
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
  }
}

UP :slight_smile:

Hi,
Do you have an LCD display?
Is it I2C or parallel interface?
What do you want displayed on the LCD.

You have the advantage of having monitor print scrolling down the screen and being able to see all you printout.
With the LCD you are limited to 2 rows of 16 characters, you can scroll with the LCD, but you will need to store your printout in character arrays, or some shorthand.

Tom... :slight_smile:

Yes I have an LCD with I2C, on the LCD i want to display the test result like Test Pass or Test Fail, and if it is possible to be displayed on the second row the issue like this example Open at pin 10 or Short at pin 10.

I also attached 2 photos of my Mega and LCD with I2C adapter.

Thank you,
Paul Lungoci

I manage to make it work :slight_smile:

Here is the final code :

#include <avr/wdt.h> //autoreset
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>

#define I2C_ADDR    0x27 // <<----- Add your address here.  Find it from I2C Scanner
#define BACKLIGHT_PIN     3
#define En_pin  2
#define Rw_pin  1
#define Rs_pin  0
#define D4_pin  4
#define D5_pin  5
#define D6_pin  6
#define D7_pin  7

int n = 1;

LiquidCrystal_I2C  lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);
//pins
int ledPinPass = 52;
int ledPinFail = 12;
int endA[10] = {30,31,34,38,40,42,44,46}; //pins end A
int endB[10] = {32,33,35,39,41,43,45,47}; //pins endB
int pSwitch=53; //you can put here what you want pin X to gnd
int pEncA= 59;
int pEncB= 63;

//results
int result[8] = {-1,-1,-1,-1,-1,-1,-1,-1};
int test[8] = {-1,-1,-1,-1,-1,-1,-1,-1};
int counter[8] = {-1,-1,-1,-1,-1,-1,-1,-1};
bool fail =false;

void setup() {

  MCUSR = 0;  // clear out any flags of prior resets.
  Serial.begin(115200); //serial used for debugging only
 lcd.begin (16,2); //  <<----- My LCD was 16x2

 
// Switch on the backlight
lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
lcd.setBacklight(HIGH);
lcd.home (); // go home
  
  //setup pins  
  for(int i=0; i<8; i++){
      pinMode(endA[i], OUTPUT);//set output pins (end A)
      pinMode(endB[i], INPUT_PULLUP);//set input pins (end B)
  }
  pinMode(pSwitch,INPUT_PULLUP);

}

void loop() {

  
 //run the test
 runTest_5x2();
}

void runTest_5x2(){
  String resultS="";
  //user interface
  lcd.clear();
  lcd.print(" tester ");
 
  lcd.setCursor(0,1);
  lcd.print(" test1 ");
  
  while(digitalRead(pSwitch))
  {
    delay(100);
    
  }
  delay(500); //debounce
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Cablu sub testare");
  delay(500);
  //lcd.setCursor(0,1);
  for(int i=0; i<8; i++){
     counter[i]=0;
    for(int j=0; j<8; j++){
        digitalWrite(endA[i], LOW); //set all outputs to LOW
    }
    for(int j=0; j<10; j++){  //check for crossed / open circuits vs closed, good, circuits
        digitalWrite(endA[j], HIGH); //scan across the inputs in turn
        test[i] = digitalRead(endB[i]); //read the output
        if(test[i] == 1 && j!=i){ //crossed or open circuit
          counter[i]++;
          result[i] = 20+j; 
        }
        else if(test[i] == 1 && j==i && result[i] <20 ){ //Good, closed circuit
          result[i] = 0; 
        }
        digitalWrite(endA[j],LOW);
        //debugging
        /*
          Serial.print("test1 input core  ");
          Serial.print(i);
          Serial.print(" with output core  ");
          Serial.print(j);
          Serial.print(" test =");
          Serial.print(test[i]);
          Serial.print(" counter =");
          Serial.println(counter[i]);
      */
    
    //old
    /*
     Serial.print("Core ");
    Serial.print(i);
    Serial.print(" result = ");
    if(result[i] == 0){
       Serial.println(" 1");
       resultS+="1";
    }
    else if(counter[i] == 9){
       Serial.println(" O");
       resultS+="0";
       fail=true;
    }
    else {
       Serial.println(" X");
       resultS+="X";
       fail=true;
    }
     */
         }
    //new
    delay(250); //delay between tests
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("Testare grup= "); //group test
    lcd.print(i);
   // lcd.setCursor(0,1);
   // lcd.print("result =");
    if(result[i] == 0){
    lcd.print(" 1");
       resultS+="1";
    }
    else if(counter[i] == 9){
      lcd.setCursor(0,1);
       lcd.print("Open grup "); //open at group X
       lcd.print(i);
       delay(1000);
    //   lcd.setCursor(4,1);
       resultS+="0";
       fail=true;
      
    }
    
    else {
      lcd.setCursor(0,1);
       lcd.print("FireInvers/scurt"); //short or cross wire
       delay(1000);
       resultS+="X";
       fail=true;
       
    }
  }
  
  //lcd.print(resultS); 
  lcd.setCursor(0,0);
 delay(1000);
 if(fail){
  lcd.clear();
   Serial.println("     FAILED");
   lcd.print(" Cablul defect");
   pinMode(ledPinFail, OUTPUT);
   digitalWrite(ledPinFail, HIGH);
 }
 else{
  
  lcd.clear();
   Serial.println("     PASSED");
   lcd.print("Cablul este bun");
   pinMode(ledPinPass, OUTPUT);
   digitalWrite(ledPinPass, HIGH);
   
 }
 Serial.println();
 lcd.setCursor(0,2);
 lcd.print(" Reset  automat");
  // while(digitalRead(pSwitch))
  {
    delay(300);
  }
  delay(700); //debounce
  //autoreset
  wdt_enable(WDTO_15MS); // turn on the WatchDog and don't stroke it.
for(;;) { 

} 
}

If anyone find some bugs or improves please do not be shy and post it here :slight_smile: