1 wire communication and identification between arduinos

here is the thing..
i want to connect many arduino pro micro using only 1 mono jack cable for every connection..
so i have grounds...and just 1 pin.
Lets say that i have a transmitter and a receiver (but they can work also vice versa).
I want whenever i connect the transmitter to the receiver, it will know which EXACTLY is the pin that it received the signal and nothing more(like an identification thing)..then when i disconnect the cable i want the receiver to know that this cable is disconnected...

Until know after much thinking and some reading i have concluded that it can work with one of the following options:

  1. serial communication
    the transmitter send a specific char so the receiver knows that this is a specific pin

like this:
receiver code:

bool on = true;
bool pressedCon = false;
bool pressedDisc = false;
SoftwareSerial myCable1(myRxPin, 99);

void setup(){
     myCable1.begin(4800);
}
void loop() {
 if (myCable1.available()) {
    char myID = myCable1.read();
    if (myID == '!' && !pressedCon) {
      Serial.println("!, on");
      pressedCon = true;
      pressedDisc = false;
      
    }

  }
  else if(pressedCon && !pressedDisc){
    Serial.println("off");
    pressedCon = false;
    pressedDisc = true;
 }
//do other stuff
}

transmitter code:

SoftwareSerial myCable1(99, 2);
char myIDChar = '!';
void loop() {
myCable1.write(myIDChar);
//do other stuff
}

The problem with this code is that it works..but not always..
when i connect the cable i the "!, on" message..when i disconnect i see the "off" BUT after some connect/disconnect it stops working correctly..
so, when the cable is disconnected what happens to the char? is it waiting to be transmitted? do transmitter and receiver send and receive at the same exact time? what happen when the transmitter sends but receiver does "other stuff"

  1. another possible way is: transmitter send specific voltage and receiver knows that for example 3.5V is this specific ID (the char '!'), 3.6V will be the char '*' etc.. but again this needs voltage dividers, or DAC, or PWM that i guess will not work, because the receiver's analogRead cannot read the "average" of PWM, but it will read "100 Hz cycle"..

any opinion will be highly appreciated..

From what I gather you want CSMA/CR which yields Multi Master Non Destructive Arbitration. Consider 1 wire can as a possible solution. It is far from being the only solution but is well defined. Example: the MC33897: Single-Wire Can Transceiver will do what you want. The NXP® MC33897 series provides a physical layer for digital communication using a Carrier Sense Multiple Access/Collision Resolution (CSMA/CR) data link operating over a single wire medium. This is commonly referred to as single-wire Controller Area Network (SWCAN).

CAN bus operates with a single wire Operates directly from a vehicle's 12 V battery system or a broad range of DC-power sources at low or high (33.33 kbps or 83.33 kbps) data rates. A high-voltage wake-up feature allows the device to control the regulator used in support of the MCU and other logic. Complies with the GMW3089v2.4 General Motors Corporation specification.
Features:
Waveshaping for low Electromagnetic Interference (EMI).
Detects and automatically handles loss of ground.
Worst-case Sleep mode current of only 60 μA.
Current limit prevents damage due to bus shorts.
Built-in thermal shutdown on bus output.
Protected against vehicular electrical transients.
Under-voltage lockout prevents false data with low battery.
For more information look at the data sheet.
This gets you through the physical layer but you still have a lot to go and a bunch of software to write. A lot of what you need is in the Arduino CAN libraries.
This response is to help you get started in solving your problem, not solve it for you.
Good Luck & Have Fun!
Gil

Thanks for your answer..finally i used pwm to do my work..
although i could do serial communication successfully, i had limitations because i couldnt use more than one soft serial at a time..