I have two arduinos (An UNO R3 and a Mega 2560), and I need to communicate them via two ESP8266 modules to exchange some values.

In one arduino I'll use a SW-420 vibrarion module, and I need to send a value wirelessly to the other board, which it'll have an LCD screen that will display a message when a value is recieved.

How can I do that with that specific WiFi modules? Thanks in advance

  • You could have them both communicate with the same WiFi AP, or you could set one to be in SoftAP mode and connect the other to it. The choice is yours.
    – Majenko
    Oct 31, 2015 at 11:03
  • @Majenko The second option looks way more attractive to me, can you share a tutorial of how to do it? Thanks. Nov 1, 2015 at 0:25
  • No, I can't. I never use the modules connected to an Arduino - I program them direct.
    – Majenko
    Nov 1, 2015 at 0:39

1 Answer 1


Step 1: I would load NodeMCU on you ESP8266: https://github.com/nodemcu/nodemcu-firmware

Step 2: Connect to your home router or make an ap on one of your ESP and connect them... use the api: https://github.com/nodemcu/nodemcu-firmware/wiki/nodemcu_api_en over serial connection

Step 3: write a TCP server:

    print(payload) //This payload will be send to your arduino over soft serial
    conn:send("<h1> Hello, NodeMCU!!! </h1>")
  conn:on("sent",function(conn) conn:close() end)

Step 4: write a TCP client:

suc = false;
function sendData( host, pathData )
    suc = false;
    -- A simple http client
    conn=net.createConnection(net.TCP, 0)
    conn:on("receive", function(conn, payload)
        if(string.find(payload, "200 OK")~=nil) then
            suc = true;
            suc = false;
    conn:on("connection", function(c)
        conn:send("GET /".. pathData .." HTTP/1.1\r\nHost: ".. host .."\r\n"
            .."Connection: keep-alive\r\nAccept: */*\r\n\r\n") 
    conn:on("disconnection", function() 
        if(suc==false) then
    conn:on("reconnection", function() print("reconnection") end )

Step 5: Connect your esp boards with software serial to the arduino

Step 6: write (from board 1) to softserial to esp1: sendData( hostIP, yourData)

Step: 7 Parse the Data on sofserial read on the second arduino

Step 8: DONE!


Ok more infos on step 6. If you got your script running on your esp, you can call functions by sending the function name with parameters over your serial connection. So, this is some example code for your ardoino if you got the script from above:

SoftwareSerial wifi(3, 2); // RX, TX

//at some time in your programm
//Build up your string that will be send over serial
String i1 = "sendData(\"ipFromTheServer\", \"send.php?d=";
String i2 = i1+dataToSend;
String i3 = i2 +"\");";

This will call the sendData function on you esp. this will call the send.php on a Server... you can put a server up on an other esp and call it (dont have to be a php page)

More infos on step 7. the script on top will always print all incoming data. So you just have to read serial data on wifi:

if (wifi.available())
    Serial.write(wifi.read()); //this will print all inc data to your arduino console (serial) parse this data!

Info: I've build this on my own... dont know if this is best practice :)


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.