user31472: Here's the system I want to work on:

The weight controller device detects weight which can transfer data via RS232 serial connection
I used RS232 converter to TTL serial module to connect the weight controller device to Arduino
The TTL connections were made to respective pins of Arduino UNO Board (GND-GND, VCC-5V, RX-0, TX-1)

The serial print from serial connection should produce 17 character length string : ST,GS    1.58,kg
Why am I getting strange results at times?
// Read Serial (RS232) data from Weight Controller Device via RS232 to TTL Converter Module

// Ignore the include statement, the editor does not allow pasting certain characters

include SoftwareSerial.h

int RX_PIN = 2;
int TX_PIN = 3;
int BAUD_IDE = 9600;
int BAUD_WEIGHT_SENSOR = 9600;

// serial port from weight controller
SoftwareSerial mySerial = SoftwareSerial(RX_PIN, TX_PIN);

void setup() {   
  mySerial.begin(BAUD_WEIGHT_SENSOR);
  Serial.begin(BAUD_IDE);
}

void loop() {  
  while (mySerial.available()) {
    int inChar = mySerial.read();    
    if (inChar != '\n') {
      serialData += (char)inChar;
    }
    else {
      int dataSize = serialData.length();      
      Serial.print(serialData);
      Serial.print(" length:  "); 
      Serial.print(dataSize); 
      Serial.print("\n"); 
      delay(3000); 
      serialData = "";
    }    
  }
  serialData = "";

}

// this one works perfectly but i want to store as string to 
process
// information and use for other functions
/*void loop() {  
if (mySerial.available()){          
  Serial.print((char)mySerial.read());  



user612: You are attempting to talk to your peripheral via a second serial UART implemented in software on arbitrary pins, which should leave the hardware UART free for uploading and debug or other runtime communication between the Arduino and a PC.
However, the "arbitrary pins" you choose to use to connect the peripheral are the same pins as used by the hardware UART.
Move your peripheral to two other pins, for example
int RX_PIN = 2;
int TX_PIN = 3;

and move the connections accordingly
Also consider if you really want Serial.println() which will add a line break after every character in the output, and will also print the received characters as their numeric ASCII codes, one per line, rather than printing the characters themselves.  You probably want Serial.write().

user30175: You need to disconnect the Arduino`s RX and TX pins from any device before trying to upload a sketch via USB, because the Serial data is directly wired from the USB chip to these pins. It's as if you're trying to flash the thing behind your RS232 adapter.

31472: <p>Here's the system I want to work on:</p>
<ol>
<li>The weight controller device detects weight which can transfer data via RS232 serial connection</li>
<li>I used <a href="https://i.stack.imgur.com/9Z6Uz.png" rel="nofollow noreferrer">RS232 converter to TTL serial module</a> to connect the weight controller device to Arduino</li>
<li>The TTL connections were made to respective pins of Arduino UNO Board (GND-GND, VCC-5V, RX-0, TX-1)</li>
</ol>
<p><strong>The serial print from serial connection should produce 17 character length string : ST,GS    1.58,kg</strong></p>
<h2>Why am I getting strange results at times?</h2>
<pre><code>// Read Serial (RS232) data from Weight Controller Device via RS232 to TTL Converter Module

// Ignore the include statement, the editor does not allow pasting certain characters

include SoftwareSerial.h

int RX_PIN = 2;
int TX_PIN = 3;
int BAUD_IDE = 9600;
int BAUD_WEIGHT_SENSOR = 9600;

// serial port from weight controller
SoftwareSerial mySerial = SoftwareSerial(RX_PIN, TX_PIN);

void setup() {   
  mySerial.begin(BAUD_WEIGHT_SENSOR);
  Serial.begin(BAUD_IDE);
}

void loop() {  
  while (mySerial.available()) {
    int inChar = mySerial.read();    
    if (inChar != '\n') {
      serialData += (char)inChar;
    }
    else {
      int dataSize = serialData.length();      
      Serial.print(serialData);
      Serial.print(&quot; length:  &quot;); 
      Serial.print(dataSize); 
      Serial.print(&quot;\n&quot;); 
      delay(3000); 
      serialData = &quot;&quot;;
    }    
  }
  serialData = &quot;&quot;;

}

// this one works perfectly but i want to store as string to 
process
// information and use for other functions
/*void loop() {  
if (mySerial.available()){          
  Serial.print((char)mySerial.read());  
</code></pre>
<p><a href="https://i.stack.imgur.com/9Z6Uz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9Z6Uz.png" alt="enter image description here" /></a></p>
 612: <p>You are attempting to talk to your peripheral via a second serial UART implemented in software on arbitrary pins, which should leave the hardware UART free for uploading and debug or other runtime communication between the Arduino and a PC.</p>

<p>However, the "arbitrary pins" you choose to use to connect the peripheral are <em>the same</em> pins as used by the hardware UART.</p>

<p><strong>Move your peripheral to two other pins</strong>, for example</p>

<pre><code>int RX_PIN = 2;
int TX_PIN = 3;
</code></pre>

<p>and move the connections accordingly</p>

<p>Also consider if you really want <code>Serial.println()</code> which will add a line break after every character in the output, and will also print the received characters as their numeric ASCII codes, one per line, rather than printing the characters themselves.  You probably want <code>Serial.write()</code>.</p>
 30175: <p>You need to disconnect the Arduino`s RX and TX pins from any device before trying to upload a sketch via USB, because the Serial data is directly wired from the USB chip to these pins. It's as if you're trying to flash the thing behind your RS232 adapter.</p>
