user20423: I have SIM800l module connected to Arduino and I'm trying to initialize it in my setup function with this code:
#include <SoftwareSerial.h>

//SIM800 TX is connected to Arduino D8
#define SIM800_TX_PIN 6
//SIM800 RX is connected to Arduino D7
#define SIM800_RX_PIN 7
SoftwareSerial serialSIM800(SIM800_TX_PIN,SIM800_RX_PIN);

void setup()
{
  Serial.begin(38400);
  while(!Serial);
  serialSIM800.begin(38400);
  Serial.println("wait for .... it");
  delay(10000);


  // comments added just for example, both commands return junk
  //serialSIM800.write("AT\r\n"); 
  //serialSIM800.write("AT+SAPBR=3,1,\"Contype\",\"GPRS\"\r\n");

  Serial.println("command sent");
  delay(2500);

  Serial.write(serialSIM800.read());
}

But Serial.write returns junk. 
When I use this code in loop:
  //Read SIM800 output (if available) and print it in Arduino IDE Serial Monitor
  if(serialSIM800.available()){
    Serial.write(serialSIM800.read());
  }
  //Read Arduino IDE Serial Monitor inputs (if available) and send them to SIM800
  if(Serial.available()){    
    serialSIM800.write(Serial.read());
  }

and send AT+SAPBR=3,1,"Contype","GPRS" or just AT command with serial monitor, everything works fine.
Can someone help with this?

user14737: NeoSWSerial would be better for this.  It can read and write at the same time, unlike SoftwareSerial, and it doesn't disable interrupts for the entire character receive time (~1ms!).  AltSoftSerial would be even better, but you can only use it on pins 8 & 9 (on an UNO, different pins on other Arduinos).

user43056: Somewhere you said that ...but Serial.write return's junk....
Make sure that serial print is Both NL & CR

user43411: You are getting junk because of baud rate, set as 9600.
Serial.begin(9600);
  while(!Serial);
  serialSIM800.begin(9600);
  Serial.println("wait for .... it");
  delay(10000);  

user73001: IIRC, SIM800 modems are very 1990s, they default to 9600 baud. You will get garbage at 38400.
I successfully used a SIM800 at 9600.

20423: <p>I have SIM800l module connected to Arduino and I'm trying to initialize it in my setup function with this code:</p>

<pre><code>#include &lt;SoftwareSerial.h&gt;

//SIM800 TX is connected to Arduino D8
#define SIM800_TX_PIN 6
//SIM800 RX is connected to Arduino D7
#define SIM800_RX_PIN 7
SoftwareSerial serialSIM800(SIM800_TX_PIN,SIM800_RX_PIN);

void setup()
{
  Serial.begin(38400);
  while(!Serial);
  serialSIM800.begin(38400);
  Serial.println("wait for .... it");
  delay(10000);


  // comments added just for example, both commands return junk
  //serialSIM800.write("AT\r\n"); 
  //serialSIM800.write("AT+SAPBR=3,1,\"Contype\",\"GPRS\"\r\n");

  Serial.println("command sent");
  delay(2500);

  Serial.write(serialSIM800.read());
}
</code></pre>

<p>But <code>Serial.write</code> returns junk. </p>

<p>When I use this code in loop:</p>

<pre><code>  //Read SIM800 output (if available) and print it in Arduino IDE Serial Monitor
  if(serialSIM800.available()){
    Serial.write(serialSIM800.read());
  }
  //Read Arduino IDE Serial Monitor inputs (if available) and send them to SIM800
  if(Serial.available()){    
    serialSIM800.write(Serial.read());
  }
</code></pre>

<p>and send <code>AT+SAPBR=3,1,"Contype","GPRS"</code> or just <code>AT</code> command with serial monitor, everything works fine.</p>

<p>Can someone help with this?</p>
 14737: <p><a href="https://github.com/SlashDevin/NeoSWSerial" rel="nofollow">NeoSWSerial</a> would be better for this.  It can read and write at the same time, unlike SoftwareSerial, and it doesn't disable interrupts for the entire character receive time (~1ms!).  AltSoftSerial would be even better, but you can only use it on pins 8 &amp; 9 (on an UNO, different pins on other Arduinos).</p>
 43056: <p>Somewhere you said that ...but Serial.write return's junk....
Make sure that serial print is Both NL &amp; CR</p>
 43411: <p>You are getting junk because of baud rate, set as 9600.</p>

<p>Serial.begin(9600);
  while(!Serial);
  serialSIM800.begin(9600);
  Serial.println("wait for .... it");
  delay(10000);  </p>
 73001: <p>IIRC, SIM800 modems are very 1990s, they default to 9600 baud. You will get garbage at 38400.</p>
<p>I successfully used a SIM800 at 9600.</p>
