int pins[5] = {D0, D1, D2, D3, D9}; void setup() { // put your setup code here, to run once: Serial.begin(115200); pinMode(D0, INPUT); pinMode(D3, INPUT); pinMode(9, INPUT); } void probe(int in_pin, int out_pin) { for (int i = 0; i < 5; i++) { if (i != in_pin && i != out_pin) { pinMode(pins[i], INPUT); } } pinMode(pins[out_pin], OUTPUT); pinMode(pins[in_pin], INPUT_PULLDOWN); digitalWrite(pins[out_pin], HIGH); delay(5); int value = digitalRead(pins[in_pin]); if (value == HIGH) { Serial.print(out_pin); Serial.println(in_pin); } } void loop() { // put your main code here, to run repeatedly: for (int out = 0; out < 5; out++) { for (int in = 0; in < 5; in++) { if (out != in) { probe(out, in); } } } delay(10); }