Connect an ESP8266 module to an Arduino Nano and control it with Blynk

We are going to build a circuit that is connected to an app build with Blynk. For this we connect an Arduino to an ESP8266 module and connect it through Wifi. This example uses an Arduino Nano, of course you may use an other type of Arduino, eg. the Uno. This guide assumes you already have some basic knowledge of Arduino and electronics and already did the “Getting started with Blynk” tutorial.

Connect the ESP8266 module

Connect the module:

TX from ESP8266 is connected to D2, RX to D3 of the Arduino (via 1K resistor). Beware that the 3.3V from the Arduino is usually not sufficient* to power the ESP8266 module. The ESP8266 needs a separate 3.3V power source, eg. from a breadboard power connector:

Take special care: for this type of breadboard power connector, never connect both wings to power sources! (USB power and a power adapter) You risk blowing up something, in the worst case your laptop!

* it is possible to use the 3.3V pin of an Arduino, if the Arduino is powered by a stronger power-source, eg. a 9V battery pack

Add a program to test and configure the module

My example: first_ESP8266_v2.ino
This example can initialize and test a new module. See comments in code for details. It is based on this example.

At first you will have to reset the device, set its speed to 9600 baud and configure it as a Wifi Client (Station mode). You communicate with the module by sending it AT-commands through the Serial Monitor. The code contains instructions and examples how to do this. If it does not work, check out the “ESP8266 troubleshooting” section at the bottom of this article.

Connect to Wifi

After you have configured the module as a Wifi client, it can connect to a Wifi network.

My example: first_esp8266_connect.ino

Open this example in the Arduino IDE, change the password (variable ‘pass’) and if necessary the ssid, and run it. It should connect to the Wifi network “mspot” and print details about the connection in the Serial Monitor. If it does not work, check out the “ESP8266 troubleshooting” section at the bottom of this article.

Unfortunately, the ESP8266 can not connect to the EDUROAM network we use at the university. That’s why I usually bring a Wireless Router to my workshops, which uses the SSID “mspot”. As an alternative you can turn your phone or laptop into a mobile hotspot.

Add a LED to the circuit

If you did the “Getting started with Blynk” tutorial first you still have a LED connected to your Arduino. If not, connect a LED.

Control the LED with Blynk

In the Arduino IDE load the “ESP8266_Shield” example via File > Examples > Blynk > Boards_WiFi . And change settings in red:

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "********";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "mspot";
char pass[] = "********";

// Hardware Serial on Mega, Leonardo, Micro...
//#define EspSerial Serial1
// or Software Serial on Uno, Nano...
#include <SoftwareSerial.h>
SoftwareSerial EspSerial(2, 3);
// RX, TX
// Your ESP8266 baud rate: (was 115200)
#define ESP8266_BAUD 9600

The auth variable should contain the Auth Token from the Blynk App (you can get it from the project settings in the app).

Run the sketch.
In the Blynk App, change the project settings to reflect the new way we connect to the Blynk cloud, via Wifi:

If you have the example from the “Getting started with Blynk” tutorial on your phone, you should now be able to control the LED from your phone.

Final step: add RFID module and identify a person (in the App)

Add the RFID module (step-by-step guide here). Add the necessary code to the Arduino Sketch.
You may use this complete example: first_esp8266_rfid.ino

The display widget ‘lcd’ is used to display the RFID code in a display widget in the Blynk App (which is connected to virtual pin V1). Add a LCD widget to the userinterface:

In the Arduino sketch, when an RFID is scanned, its ID will be sent to the display (lcd in the code) like this:

lcd.print(0,0, rfidUid);

Test the App, it should display the ID if you scan a card.

As a last example, we will add a notification to the App, which will display a notification if the card scanned is from a specific person. In the Blynk App, add an Eventor and a Notification widget. The Eventor can respond to events (if this … then …). In the Arduino sketch, when an RFID is scanned, it will be sent to a virtual pin V1 like this:

Blynk.virtualWrite(V1, rfidUid);

When this event occurs, the Eventor widget in the App can respond to it:

Use the ESP8266 standalone

For more compact circuits, you can also use the Wifi module without an Arduino, like this project “ESP8266 Temperature / Humidity Webserver”.

ESP8266 troubleshooting

If the ESP module is unable to connect or appears unresponsive, double-check the wiring. Are all wires connected according to the schematic at the top of this article?
As a next step, you can reset the module: connect a wire to the RST pin of the module and make sure the module is powered (the red LED on the module should be on). Then, for 2 seconds,
connect the wire to the GND. After that, connect it for 2 seconds to the VCC (3.3V). Remove the wire and try again.