user67661: The nano is inside of the house, and the pro mini is outside of the house. I want to send/receive text between them. The communication will be always nano sending text to mini, and then mini sending text to pro in response. There will be no case where mini sends text on its own first.
The line has three wires, but since I have to power the mini with that line, one is used for VCC and another is used for ground, leaving only one wire free. It this case, can I do UART communication between the two? If so, how should I connect the wire to them (including the ground)? And on the software side, how should I handle the communication? Could you give a simple code example in which nano sends "Hello" to pro mini, and then pro mini, after receiving "hello", sends "World" to nano?


user80162: An example of protocol using a single wire (besides ground, so a total of 2) for both bi-directional communication AND power: Dallas 1-wire
There are few other similar standard protocols and you are free to think about your own as long as you are willing to implement all the internals instead of using a well-written and widely used library.

user3624: You could do it by using one wire for ground, one wire for nano->mini, and one wire for mini->nano.  The nano->mini wire carries both power and data.  You can keep it at some voltage above ground to provide the power and superimpose a data signal that is AC coupled off at the mini end.  Alternately, you can rectify the data to provide power if you make sure to send 01010101 whenever you don't have something else to say.

user20245: This question likely suffers from the X Y problem.  Where the question (about software) and possible answer (centered on hardware) do not approach the solution using the same methods.
The question is essentially asking how to design a 1-wire interface over longer than normal distances. There are 1-wire Arduino libraries and 1-wire Arduino tutorials. But it is likely you will run into problems if your cable is very long.
Guessing at the distance you want to run your 3 wires (power, ground and data), this may be more an electrical engineering than a software problem.
Power:
All wires have resistance.  Using a voltage drop calculator from here we can calculate, assuming we are trying to send 5V over an 18 AWG copper wire 100 meters long to a 250mA load, an expected voltage drop of slightly over a volt.  That may cause unexpected results.

If this might be an issue, consider an alternate power source such as batteries, solar power or a second mains power adapter for the far Arduino.  It may even be considered to over drive the power lines several volts and regulate the voltage at the far end Arduino.
Data:
Reference to ground type data transmission is more susceptible to error the longer the cable run.  Several options to mitigating unexpected behavior can be made.  However switching over to a balanced pair is usually the best option.
Options:
If you are willing to power the far Arduino independently or add 1 additional data wire (either of these options will make available 2 wires for data) we can run the data portion of the cable for a good distance while mitigating noise problems associated with long communication cable runs.
Try RS485:
Consider using an RS485 hardware interface at the near and far Arduino.  RS485 interfaces can be source easily for Arduino projects (here and here are two examples) and there are Arduino RS485 software libraries which handle the communications.
The intent of the project was not disclosed in the question.  However here is an example RS485 project where connected Arduinos communicate the position of a potentiometer such that the RS485 connected Arduino at the far end can mimic the potentiometer's movements on a motor driven servo.
The keen eye may note that the above project only uses 2 wires between the two Arduinos.  This is possible because in the above project the two Arduinos are independently powered (this is not seen in the diagram on the linked to web page).  Additionally, RS485 uses a balanced pair of signals (the 2 wires) and does not need to run an additional ground between the two Arduinos as a reference to detect the difference between 1s and 0s.

user7508: You can have bidirectional communication over a single wire by using
open-collector outputs. For this, you could add a circuit like this
on each side of the link:

simulate this circuit – Schematic created using CircuitLab
Here, TX is the transmit pin of the Arduino, and DATA is the data wire.
The RX pin is connected directly to the data wire and, while writing
your sketches, you should account for the fact that anything you send
will be received back by the sender as an “echo”.
This scheme will slow down your signal transitions, limiting the maximum
achievable baud rate. Start with something conservative, like
9600 bps, and lower further if it doesn't work reliably.

67661: <p>The nano is inside of the house, and the pro mini is outside of the house. I want to send/receive text between them. The communication will be always nano sending text to mini, and then mini sending text to pro in response. There will be no case where mini sends text on its own first.</p>
<p>The line has three wires, but since I have to power the mini with that line, one is used for VCC and another is used for ground, leaving only one wire free. It this case, can I do UART communication between the two? If so, how should I connect the wire to them (including the ground)? And on the software side, how should I handle the communication? Could you give a simple code example in which nano sends &quot;Hello&quot; to pro mini, and then pro mini, after receiving &quot;hello&quot;, sends &quot;World&quot; to nano?</p>
<p><a href="https://i.stack.imgur.com/VJr2c.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VJr2c.png" alt="enter image description here" /></a></p>
 80162: <p>An example of protocol using a single wire (besides ground, so a total of 2) for both bi-directional communication AND power: <a href="https://en.wikipedia.org/wiki/1-Wire" rel="nofollow noreferrer">Dallas 1-wire</a></p>
<p>There are few other similar standard protocols and you are free to think about your own as long as you are willing to implement all the internals instead of using a well-written and widely used library.</p>
 3624: <p>You could do it by using one wire for ground, one wire for nano-&gt;mini, and one wire for mini-&gt;nano.  The nano-&gt;mini wire carries both power and data.  You can keep it at some voltage above ground to provide the power and superimpose a data signal that is AC coupled off at the mini end.  Alternately, you can rectify the data to provide power if you make sure to send 01010101 whenever you don't have something else to say.</p>
 20245: <p>This question likely suffers from the <a href="https://en.wikipedia.org/wiki/XY_problem" rel="nofollow noreferrer">X Y problem</a>.  Where the question (about software) and possible answer (centered on hardware) do not approach the solution using the same methods.</p>
<p>The question is essentially asking how to design a <a href="https://en.wikipedia.org/wiki/1-Wire" rel="nofollow noreferrer">1-wire</a> interface over longer than normal distances. There are <a href="https://www.arduino.cc/reference/en/libraries/onewire/" rel="nofollow noreferrer">1-wire Arduino libraries</a> and <a href="https://www.hacktronics.com/Tutorials/arduino-1-wire-tutorial.html" rel="nofollow noreferrer">1-wire Arduino tutorials</a>. But it is likely you will run into problems if your cable is very long.</p>
<p>Guessing at the distance you want to run your 3 wires (power, ground and data), this may be more an electrical engineering than a software problem.</p>
<p><strong>Power:</strong></p>
<p>All wires have resistance.  Using a voltage drop calculator from <a href="https://www.rapidtables.com/calc/wire/voltage-drop-calculator.html" rel="nofollow noreferrer">here</a> we can calculate, assuming we are trying to send 5V over an 18 AWG copper wire 100 meters long to a 250mA load, an expected voltage drop of slightly over a volt.  That may cause unexpected results.</p>
<p><a href="https://i.stack.imgur.com/SGoJu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SGoJu.png" alt="enter image description here" /></a></p>
<p>If this might be an issue, consider an alternate power source such as batteries, solar power or a second mains power adapter for the far Arduino.  It may even be considered to over drive the power lines several volts and regulate the voltage at the far end Arduino.</p>
<p><strong>Data:</strong></p>
<p>Reference to ground type data transmission is more susceptible to error the longer the cable run.  Several options to mitigating unexpected behavior can be made.  However switching over to a balanced pair is usually the best option.</p>
<p><strong>Options:</strong></p>
<p>If you are willing to power the far Arduino independently or add 1 additional data wire (either of these options will make available 2 wires for data) we can run the data portion of the cable for a good distance while mitigating noise problems associated with long communication cable runs.</p>
<p><strong>Try RS485:</strong></p>
<p>Consider using an <a href="https://en.wikipedia.org/wiki/RS-485" rel="nofollow noreferrer">RS485</a> hardware interface at the near and far Arduino.  RS485 interfaces can be source easily for Arduino projects (<a href="https://www.sparkfun.com/products/10124" rel="nofollow noreferrer">here</a> and <a href="https://www.dfrobot.com/product-1024.html" rel="nofollow noreferrer">here</a> are two examples) and there are <a href="https://github.com/arduino-libraries/ArduinoRS485" rel="nofollow noreferrer">Arduino RS485 software libraries</a> which handle the communications.</p>
<p>The intent of the project was not disclosed in the question.  However <a href="https://create.arduino.cc/projecthub/maurizfa-13216008-arthur-jogy-13216037-agha-maretha-13216095/modbus-rs-485-using-arduino-c055b5" rel="nofollow noreferrer">here</a> is an example RS485 project where connected Arduinos communicate the position of a potentiometer such that the RS485 connected Arduino at the far end can mimic the potentiometer's movements on a motor driven servo.</p>
<p>The keen eye may note that the above project only uses 2 wires between the two Arduinos.  This is possible because in the above project the two Arduinos are independently powered (this is not seen in the diagram on the linked to web page).  Additionally, RS485 uses a balanced pair of signals (the 2 wires) and does not need to run an additional ground between the two Arduinos as a reference to detect the difference between 1s and 0s.</p>
 7508: <p>You can have bidirectional communication over a single wire by using
<a href="https://en.wikipedia.org/wiki/Open_collector" rel="noreferrer">open-collector</a> outputs. For this, you could add a circuit like this
on each side of the link:</p>

<p><img src="https://i.stack.imgur.com/93mZ7.png" alt="schematic" /></p>

<p><sup><a href="/plugins/schematics?image=http%3a%2f%2fi.stack.imgur.com%2f93mZ7.png">simulate this circuit</a> &ndash; Schematic created using <a href="https://www.circuitlab.com/" rel="noreferrer">CircuitLab</a></sup></p>
<p>Here, TX is the transmit pin of the Arduino, and DATA is the data wire.
The RX pin is connected directly to the data wire and, while writing
your sketches, you should account for the fact that anything you send
will be received back by the sender as an “echo”.</p>
<p>This scheme will slow down your signal transitions, limiting the maximum
achievable baud rate. Start with something conservative, like
9600 bps, and lower further if it doesn't work reliably.</p>
