UART communication between two arduino uno

I have sensor connected to one arduino and i want to send the analog value of this sensor to another arduino connected via UART. How can this be achieved?

If possible please mention codes for sending and recieving this analog reading from sensor.

I would recommend using a software serial port on each Uno so that the hardware serial ports (USB) can be used for program upload, output and debugging.

The SoftwareSerial library that comes with the IDE has example code to get you started.

The serial input basics tutorial has information on using serial communication.

Software serial is not ideal - it is a bodge done because people have an Uno and want/ "need" to use serial comms with something else.

If you do the design work before you decide on the processor you would not be trying to force the Uno in to this you would have picked obe of the chips that has more than 1 hardware serial port.

Take a look at using SPI or I2C.


The following setup shows 3 possible ways of exchanging data between 2 UNOs in serial mode -- Soft UART Port, I2C Bus, and SPI Port.
Figure-1: 3 ways of exchanging data between two UNOs in serial mode

1. Software UART Port Based Serial Data Communication
Because the hardware UART Port is engaged with the Serial Monitor and IDE for debugging and uploading, many programmers use software UART Port (SUART Port) to exchange data between two/more compatible devices.
(1) Make SUART Port connection between UNO and NANO as per Fig-1.

(2) Create SUART Port (for both Sender and Receiver) by including the following coded in the sketch.

SoftwareSerial SUART(5, 4); //SRX=DPin-5, STX=DPin-4

3. Connect a Pot (Potentiometer R1) with analog Ch-0 of UNO to send analog signal (range: 0.00 - 5.00V) to NANO.

4. Prepare sketches for both Sender and Receiver to accomplish the following tasks:
(1) UNO acquires the wiper-point voltage of Pot (R1) and shows it on Serial Monitor-1 (SM1) in float form (0.00V - 5.00V).
(2) UNO will send this voltage to NANO over the SUART Port.
(3) NANO will receive the signal and will show it (in float form: 0.00V - 5.00V) of SM2.