title: Serial Communication Arduino to NodeMcu
body: <p>I'm looking to take inputs via keyboard by Arduino mega through usb cable, and send them to nodemcu through serial communication (TX - RX ) so I can send it to a server (from wifi module in nodemcu).</p>
  <p>I have tried to  write the codes for both Arduino and NodeMCu can someone help me to correct them</p>
  <hr />
  <p>Arduino mega Code</p>
  <pre class="lang-cpp prettyprint-override"><code>#include &lt;SoftwareSerial.h&gt;
  SoftwareSerial trans(19,18);
  
  String scr =&quot;&quot;;
  String User = &quot;&quot;;
  String Request = &quot;&quot;;
  String Roomid = &quot;&quot;;
  String Email = &quot;&quot;;
  
  void setup() {
    Serial.begin(115200);
    trans.begin(115200);
  }
  
  void loop() {
    Serial.println(&quot;Enter your User ID.&quot;);
    while (Serial.available() == 0) {}
    User = Serial.readString(); //Reading the Input string from Serial port.
    Serial.println(&quot;Enter your Request.&quot;);
  
    while (Serial.available() == 0) {}
    Request = Serial.readString();
    Serial.println(&quot;Enter your Roomid.&quot;);
  
    while (Serial.available() == 0) {}
    Roomid = Serial.readString();
    Serial.println(&quot;Enter your Email.&quot;);
  
    while (Serial.available() == 0) {}
    Email = Serial.readString();
    Serial.println(&quot;-------------------------&quot;); //Showing the details
    Serial.println(&quot;YOUR User ID:&quot; + User);
    Serial.println(&quot;YOUR Request ID:&quot; + Request);
    Serial.println(&quot;YOUR Room id:&quot; + Roomid);
    Serial.println(&quot;YOUR EMAIL:&quot; + Email);
    Serial.println(&quot;Thanks You...&quot;);
    Serial.println(&quot;&quot;);
    scr = User+Request+Roomid+Email;
    
    trans.write(scr);
    while (Serial.available() == 0) {}
  }
  </code></pre>
  <hr />
  <p>NodeMcu Code</p>
  <pre class="lang-cpp prettyprint-override"><code>#include &lt;ESP8266WiFi.h&gt;
  #include &lt;WiFiClient.h&gt;
  #include &lt;ESP8266WebServer.h&gt;
  #include &lt;ESP8266HTTPClient.h&gt;
  #include&lt;SoftwareSerial.h&gt; //Included SoftwareSerial Library
  
  const char* ssid=&quot;SLT-4566&quot;;
  const char* password=&quot;1234&quot;;
  int data;
  const char *host = &quot;0.0.0.0&quot;; //Your pc or server (database) IP, example : 192.168.0.0 , if you are a windows os user, open cmd, then type ipconfig then look at IPv4 Address.
  
  void setup() {
    // put your setup code here, to run once:
    pinMode(2,OUTPUT);
  
    delay(1000);
    Serial.begin(115200);
    WiFi.mode(WIFI_OFF);        //Prevents reconnection issue (taking too long to connect)
    delay(1000);
    WiFi.mode(WIFI_STA);        //This line hides the viewing of ESP as wifi hotspot
    
    WiFi.begin(ssid, password); //Connect to your WiFi router
    Serial.println(&quot;&quot;);
  
    Serial.print(&quot;Connecting&quot;);
    // Wait for connection
    while (WiFi.status() != WL_CONNECTED) {
      delay(250);
      Serial.print(&quot;.&quot;);
      delay(250);
    }
  
    //If connection successful show IP address in serial monitor
    Serial.println(&quot;&quot;);
    Serial.println(&quot;Connected to Network/ssid&quot;);
    Serial.print(ssid);
    Serial.print(&quot;IP address: &quot;);
    Serial.println(WiFi.localIP());  //IP address assigned to your ESP
  }
  
  void loop() {
    // put your main code here, to run repeatedly:
    data = Serial.read();
    Serial.println(data);
  }
  </code></pre>