Random Nerd Tutorials

Sending Data From an Arduino to the ESP8266 via Serial


In this tutorial you’re going to learn how to send data from an Arduino to the ESP8266 via serial communication.

Before you continue reading this project, please complete the following tutorials: 

If you like the ESP WiFi module and you want to build more projects you can download my eBook called “Home Automation using ESP8266” hereLet’s get started!

Watch the video demonstration below

Parts List

Here’s the hardware that you need to complete this tutorial example:

You can use the preceding links or go directly to MakerAdvisor.com/tools to find all the parts for your projects at the best price!

Uploading Your Arduino Sketch

The Arduino sketch for this tutorial is very simple.

You begin a serial communication in the setup() function at a baud rate of 9600. Then in the loop() function it prints “HI!” continuously every 1 second (that message will be received by your ESP later).

Copy the sketch below to your Arduino IDE and upload it to your Arduino board.

 * Rui Santos 
 * Complete Project Details https://randomnerdtutorials.com

// Send Data From Arduino to ESP8266 via Serial @ baud rate 9600
void setup() {

void loop() {

Now if you open your Arduino serial monitor at a baud rate of 9600, you’ll see a message appearing in your window saying “HI!” every 1 second.

Schematics (3.3V FTDI Programmer)

Having your ESP8266 flashed with NodeMCU, follow the next schematics to establish a serial communication between your FTDI programmer and your ESP8266 to upload some code.ESP-Bitcoin-price_bb

Downloading ESPlorer IDE

I recommend using the ESPlorer IDE which is a program created by 4refr0nt to create and save Lua files into your ESP8266. Follow these instructions to download and install ESPlorer:

  1. Click here to download ESPlorer
  2. Unzip that folder
  3. Go to the main folder
  4. Run ESPlorer.jar
  5. Open the ESPlorer (as shown in the Figure below). esplorer start

Writing Your ESP8266 Script

Copy and paste the code below into ESPlorer IDE window.

-- Rui Santos
-- Complete project details at https://randomnerdtutorials.com

ledOn = 0
uart.on("data", 3, 
        print("Received from Arduino:", data)
        if data=="HI!" then
            if ledOn==0 then
                ledOn = 1
                print("LED On")
                ledOn = 0
                print("LED Off")
end, 0)

Summary: The ESP is configured to listen to serial communications. Every time that receives the string “HI!” at a baud rate of 9600, it will turn the GPIO 2 on or off.

Uploading Your Script

When you open the ESPlorer IDE you should see a window similar to the preceding Figure, follow these instructions to send commands to your ESP8266:

  1. Connect your FTDI programmer to your computer
  2. Set bad raute as 9600
  3. Select your FTDI programmer port (COM3, for example)
  4. Press Open/Close
  5. Select NodeMCU+MicroPtyhon tab
  6. Copy the your Lua script into ESPlorer

Then you simply click the button Save to ESP and save your file with the name “init.lua”. Everything that you need to worry about or change is highlighted in red box in the following Figure.


Final Circuit

Follow the next schematics to complete this tutorial.

esp8266 talks via serial with arduino s

Note: I’m using a voltage divider to shift the TX signal of the Arduino from 5V to 3.3V. This works well for slow baud rates, but it might not work at faster baud rates. Read this blog post for more information about lowering the voltage of signals.


Now your LED should be blinking every one second. This means that your Arduino is sending the string “HI” and your ESP is receiving that data. Watch the video at the beginning of this post for a live demonstration.

Now instead of sending a string saying just “HI!”, you can attach sensors to your Arduino and send that data to your ESP instead. Later you can build a web server that displays that data.

Read Next…

You might also find interesting trying one of these tutorials:

Do you have any questions? Leave a comment down below!

Thanks for reading. If you like this post probably you might like my next ones, so please support me by subscribing my blog.

Learn ESP32 with Arduino IDE

This is our complete guide to program the ESP32 with Arduino IDE, including projects, tips, and tricks! The registrations are open, so SIGN UP NOW »

Recommended Resources

Home Automation using ESP8266 »
Build IoT projects and home automation gadgets with the ESP8266 Wi-Fi module.

Build a Home Automation System »
Learn how to build a automation system using open-source hardware and software from scratch.

Arduino Step-by-Step Projects »
Build 25 cool Arduino projects with our course even with no prior experience!

Leave a Comment:

Add Your Reply