Controlling an Arduino with a WiFi ESP8266 adapter using a Windows 10 Universal App

If you’ve followed my previous post ‘Controlling an Arduino with a Bluetooth HC-05 adapter using a Universal App‘ you’ll notice many similarities when reading the instructions below.

There are, however, some advantages of using a WiFi ESP8266 module instead of a Bluetooth HC05 module:

  • the wireless range is larger;
  • the amount of devices that use WiFi is greater.

The goal is to communicate using WiFi from a phone, computer, … with an Arduino equipped with a ESP8266 module and drive a LED. A simple and fun proof of concept.

What do you need?

  • some code in C# for the Windows 10 Universal App platform;
  • an Arduino. I’m using a Leonardo;
  • a cheap ESP8266-01 module and a FTDI cable.
Part 1: The Aduino / ESP8266-01

There are many tutorials out there that show you how to connect your Arduino to an ESP8266. For example: this one or this one so you’ll forgive me if I’m not going to explain how to do that. The basic schematic however is this:

Ideally you could place a voltage divider between the Arduino Tx and ESP8266-01 Rx so the input pin of the ESP8266 is not subjected to 5V.

You could also place a LED on the Breadboard somewhere and attach it to your Arduino. We’re going to use the built in LED on pin 13.

You’ll notice that we have connected the Arduino’s Tx to the ESP8266-01’s Rx and the Arduino’s Rx to the ESP8266-01’s Tx and we didn’t even bother to use the ESP8266-01’s GPIO. That’s because we will relay all the messages sent via TCP/IP from our computer to the ESP8266 via Serial to the Arduino.

First, connect your ESP8266-01 via the FTDI cable to your computer. Make sure it’s in bootloader mode.

Then you’ll need to configure your Arduino IDE to compile for the ESP8266-01 (and not for Uno or Leonardo or …).

You can check out the code below as a reference. It doesn’t do much except it connects your ESP8266-01 to your SSID and retries if the network was not available.

The ESP8266-01 then waits for someone to connect to it and sends it a message. You’ll notice we don’t use the GPIO pins from the ESP8266-01. Instead we just forward the message trough it’s serial pins to our Arduino.

Program for the ESP8266-01

Program for the Arduino:

You could try to connect to your ESP8266-01 with a program like Putty and make sure everything is OK. Sending the message LED ON should light up your LED and LED OFF should dim it.

Part 2: The Universal App for Windows 10

Now, all the above… It’s not the main focus of today. I want to show you how easy it is to use the power of the Windows 10 Universal App API to connect to an ESP8266 module (or any other WiFi client).

The class TCPClient is kind of a wrapper around StreamSocket. It connects to a host and provides us with Events we can consume in the GUI. You could even recycle most of it if you would like to use Bluetooth.

The consumer (our GUI) is really basic and just allows us to connect and send a message over TCP/IP using an IP adress and a port.

If you start the application you’ll notice you can connect and there are two buttons. Clicking LED ON should drive the LED high and clicking LED OFF should drive the LED low.

You can find the complete GITHub repository here.

In conclusion

I must admit I kind of have a love / hate relationship with those tiny ESP8266-01 modules…

They are very small and cheap but they have some disadvantages that you should be aware of.

ESP8266-01’s only have 2 GPIO pin’s but they need to be in a certain state when the ESP8266-01 is powered on or else you get into the bootloader mode. This makes your I/O more difficult. You could use ESP8266-12 instead.

If you want to use an Arduino to expand the IO pins then know that these modules require 3.3V. If you connect them to the 3.3V pin, the Arduino can barely supply enough power. Depending on what you’re planning to drive, the 3.3V supply from the Arduino is not enough and you should look for an alternative solution (like a voltage divider on the 5V pins or a 3.3V voltage regulator or an external power supply).

With all that being said I must tell you that I grew out of using the ESP8266-01. They are too much of a hassle for me. I’m now in the habit of going nuclear and just use a Raspberry PI 2 / 3 with Windows 10 IOT. It’s just easy to be able to remote debug over TCP/IP, have a GUI, NuGet packages, … They are worth the extra price for me.

If you need to have exact timing (certain sensors, a LED strip), you’ll need a microcontroller like the Arduino. I would suggest to just get the Arduino Uno WiFi.

7 thoughts on “Controlling an Arduino with a WiFi ESP8266 adapter using a Windows 10 Universal App

  1. thanks for sharing the project , however it used the normal webserver which is so slow and probably so many time out will happen if encounter with busy serial bus , to solve this phenomenon I launch websoket server to keep the line alive , I really appreciated if you could extend your example with C# client websoket as well

    1. Hello,
      I want to send data continuously to the windows application can you help me out the c sharp code

      Hoping a positive reply from you

      Thank you.

  2. Is the arduino uno and the device running application connected to same external Wifi router???? Please reply aslam shaikh and i we both are working on the same project your reply will help us a lot….
    Thank you

    1. Hi

      I have only worked out the one way traffic (sending from c sharp to the esp8266). You can find the code here: ://

      There is a receive but I have never tested it. It’s taken from an asynchronous receive method I found somewhere in the Microsoft Universal app samples.

      Esp and computer are in the same network and subnet.

      Good luck!

  3. When I connect to ESP8266, the app says “Parameter is incorrect”. I still can’t solve it. Can you please help me to solve it?

  4. Hi,
    Thank you for sharing.
    I have a problem compiling the Arduino code. “Serial1 was not declared in this scope.”
    The ESP and C# are in place. My Arduino is a Nano

    What can I do to fix this?

    Best regards,

Leave a Reply

Your email address will not be published. Required fields are marked *