Introduction: Connect to Blynk Using ESP8266 As Arduino Uno Wifi Shield (Mac Only)

This is a tutorial to show you how to connect to Blynk using an ESP8266 - 01 as an Arduino Uno wifi shield. This tutorial is very detailed to help out those who are very new to this stuff.

-

Hardware needed:

Arduino Uno

Male to male jumper cables

Male to female jumper cables (if you don't have a breadboard adapter)

Solderless breadboard

USB 2.0 cable type A/B to connect the Arduino Uno to your Mac

ESP8266-01

Optional, but recommended:

Breadboard adapter (not required but it does make connecting the ESP8266 to the breadboard much easier

link to purchase: https://www.tindie.com/products/rajbex/esp8266-bre...

-

-

Software needed:

For easy access, move or download the following software to the desktop of your Mac. It can be moved later.

Arduino IDE

link: https://www.arduino.cc/en/main/software

Most recent Blynk library

link: https://github.com/blynkkk/blynk-library/releases

pySerial

link: http://sourceforge.net/projects/pyserial/files/py...

esptool

link: https://github.com/themadinventor/esptool

Sdk1.0.0 v0.22 ESP8266 firmware

link: http://esp8266.ru/download/esp8266-firmware/AT22S...

Blynk app on iphone or android

Step 1: Download Arduino IDE

Click the link provided in the intro and click what is in the red box. Make sure you move it to your desktop.

Step 2: Download Most Recent Blynk Library

Click the link provided in the intro and click what is in the red box. Make sure you move it to your desktop.

Step 3: Download PySerial

Click the link provided in the intro and click what is in the red box. Make sure you move it to your desktop. Once it's there, double click the "pyserial-2.7.tar.gz" file and it will create a pyserial-2.7 folder.

Step 4: Download Esptool

Click the link provided in the intro and click what is in the red box. Make sure you move it to your desktop.

Step 5: Download Sdk1.0.0 V0.22 ESP8266 Firmware

This will download just by clicking the link in the intro page. Make sure you move it to your desktop.

Step 6: Prepare Esptool for Flashing

Open the "esptool-master" folder and move the "AT22SDK100-2015-03-20-boot1.2.bin" file into it. Then, rename it to "AT22SDK10020150320boot12.bin". This step is very important. If you don't rename the file, you will get an error later on.

Step 7: Installing PySerial

Step1: Open your Mac Terminal (you can find Terminal in a spotlight search), then type "cd". Next, drag the "pyserial-2.7" folder into the terminal window and hit enter. The window should look something like:

~ Home$ cd /Users/Home/Desktop/pyserial-2.7
:pyserial-2.7 Home$

Step 2: Copy this text, "sudo python setup.py install" into Terminal and hit enter. It will ask you for your password. The window should now look something like:

~ Home$ cd /Users/Home/Desktop/pyserial-2.7

:pyserial-2.7 Home$ sudo python setup.py install

Password:

/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'use_2to3'

warnings.warn(msg)

running install

running build

running build_py

running build_scripts

running install_lib

running install_scripts

changing mode of /usr/local/bin/miniterm.py to 755

running install_egg_info

Removing /Library/Python/2.7/site-packages/pyserial-2.7-py2.7.egg-info

Writing /Library/Python/2.7/site-packages/pyserial-2.7-py2.7.egg-info

:pyserial-2.7 Home$

Congrats! You just installed pySerial!

Step 8: Add the Blynk Library to Your Arduino IDE

Step 1: Open the Arduino IDE (a blank sketch will open)

Step 2: Follow the steps in the first picture to get to "Add .zip Library..."

Step 3: Click "Add .zip Library...", then double click "Desktop" (assuming that is where you saved the Blynk Library), then double click "Blynk_v0". There will be a list of five files.

Step 4: Single click the first library ("Blynk") then click "Choose" to add it to your libraries. Repeat Step 3 until you have also added "BlynkESP8266_HardSer", "SimpleTimer", and "Time".

*You should then get the message shown in Picture 2 each time you add a library.

Step 9: Prepare the Code for the Arduino

Step 1: Open a new sketch

Step 2: Replace the existing code with the code below and save. DON'T upload it yet, though. Leave this window open. We will come back to it later.

//#define BLYNK_DEBUG
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space #include <ESP8266_HardSer.h>

#include <BlynkSimpleShieldEsp8266_HardSer.h>

// Set ESP8266 Serial object #define EspSerial Serial

ESP8266 wifi(EspSerial);

// You should get Auth Token in the Blynk App. // Go to the Project Settings (nut icon). char auth[] = "???";

void setup() { // Set console baud rate Serial.begin(9600); delay(10); // Set ESP8266 baud rate EspSerial.begin(115200); delay(10);

Blynk.begin(auth, wifi, "???", "???"); }

void loop() { Blynk.run(); }

Step 10: Wiring the Arduino and ESP8266

The above wiring scheme shows how to wire the Arduino and ESP8266. If you do not have a breadboard adapter, then you can use male to female jumper cables to connect to pinouts from the ESP8266 shown above.

**Make sure you power the ESP8266 with 3.3V. 5V kills it, be careful!

-

-

Overview of connections:

ESP8266:____________ Arduino:

GND -------------------------- GND

GP2 -------------------------- Not connected (open)

GP0 -------------------------- GND

RXD -------------------------- RX

TXD -------------------------- TX

CHPD ------------------------ 3.3V

RST -------------------------- Not connected (open)

VCC -------------------------- 3.3V

Step 11: Connecting Your Arduino to Your Mac

Step 1: Connect your Arduino to your Mac using your USB 2.0 cable.

Step 2: Go to the tools tab, then go to port. Next, select your device address. It should be the bottom one. Your device address will be different.

Step 12: Flashing the ESP8266

Step 1: Upload a blank sketch to your Arduino.

Step 2: Open your Mac Terminal (you can find Terminal in a spotlight search), then type "cd". Next, drag the "esptool-master" folder into the terminal window and hit enter. The window should look something like:

~ Home$ cd /Users/Home/Desktop/esptool-master

:esptool-master Home$

Step 2: Copy this text, "sudo ./esptool.py --port /dev/tty.??? write_flash 0x00000 AT22SDK10020150320boot12.bin" into Terminal. Replace the ??? with your device address you found in the previous step. You only replace the ??? with the characters after "cu." and before (Arduino Uno). For example, mine is /dev/cu.usbmodemfd121 (Arduino Uno), so I replaced the ??? with "usbmodemfd121". Make sure the device address is copied exactly. When I first did this, I was off by one letter and it took me a while to figure it out. Now, hit enter. It will ask you for your password. The window should now look something like:

~ Home$ cd /Users/Home/Desktop/esptool-master

:esptool-master Home$ sudo ./esptool.py --port /dev/tty.usbmodemfd121 write_flash 0x00000
AT22SDK10020150320boot12.bin Password: Connecting... Erasing flash... Wrote 520192 bytes at 0x00000000 in 49.8 seconds (83.5 kbit/s)... Leaving... :esptool-master Home$

Step 13: Upload Your Code to the Arduino

Step 1: Disconnect the ESP8266 GP0 pin from ground.

Step 2: Open your Blynk app on your phone.

Step 3: First, create an account, create a new project, and hit the gear button. Next, press the auth (long array of characters) and email it to yourself. Go to the "char auth[ ] = "???";" line of your code. Replace the ??? with your new auth characters.

Step 4: Go to the "Blynk.begin(auth, wifi, "???", "???");" line of your code. Replace the first ??? with your wifi name. Replace the second ??? with your wifi password.

Step 5: Click the upload button.

Step 6: Disconnect and reverse the RX and TX Arduino pins (so that the RXD pin of the ESP8266 is connected to the TX pin of the Arduino and the TXD pin of the ESP8266 is connected to the RX pin of the Arduino).

Step 14: Check Your Connection

Step 1: Open the serial monitor.

Step 2: Change the baud rate to 115200 if it is not that already (at bottom right corner of the serial monitor, there is a drop down menu to change it). You should get something similar to the response below.

[520] Connecting to ____

ATE0

AT+CWMODE?

AT+CWJAP="____","_____"

AT+CIFSR

[7611] IP: +CIFSR:STAIP,"___.___._.___"

+CIFSR:STAMAC,"__:__:__:__:__"

OK

AT+CIPMUX=0

[7633] Connected to WiFi

AT+CIPCLOSE

AT+CIPSTART="TCP","blynk-cloud.com",8442

AT+CIPSEND=37

[1] ________ [12901] Ready (ping: 14ms).

Now, you can go back to the Blynk app, press the dotted background, add a button, and connect it to digital pin: D13. Then, press the play button.

The LED next to pin 13 on your Arduino should turn on when you press the button.

If it does, CONGRATS! You have now connected to Blynk and can create your own projects.

Happy Blynking!!

Comments

author
nolmath (author)2015-09-04

If you have a question, feel free to post it here. I will try to answer it as soon as possible.

author

what problem in my serial monitor. (wifi name and pass is correct)

[19] Blynk v0.3.0

[20] Connecting to Rozelle Thai Cuisine

ATE0

AT+CWMODE?

AT+CWJAP="Rozelle Thai Cuisine","dekthai99087"

[10067] Failed to connect WiFi

AT+CIPCLOSE

AT+CIPSTART="TCP","cloud.blynk.cc",8442

AT+CIPCLOSE

AT+CIPSTART="TCP","cloud.blynk.cc",8442

AT+CIPCLOSE

AT+CIPSTART="TCP","cloud.blynk.cc",8442

AT+CIPCLOSE

AT+CIPSTART="TCP","cloud.blynk.cc",8442

AT+CIPCLOSE

author

This could mean that you need to register the MAC address of you esp8266 with your wifi provider (my apartment is like this) or that the wifi you're trying to connect to wont let you just input a password to connect with just a password (my schools wifi requires a browser to input a password so I get this error)

author

how can i do that?

author

It depends on your wifi provider. If you didn't have to do that for your other devices then that is not the problem. I sometimes get that the first few times I open the serial monitor. When I reopen it a few times, eventually it works

author
IsabelM13 (author)nolmath2015-11-10

Please help me with step 13, it says fatal error: failed to connect

author
TeenuJ (author)IsabelM132016-02-06

cmd comand cd

Desktop

pyserial-2.7 sudo python setup.py install but run tha software plz help me

author
AcrimoniousMirth (author)nolmath2016-02-04

I drag the file to Terminal and it complains that no such file or directory can be found. How do I solve this? Thanks!

author
nolmath (author)AcrimoniousMirth2016-02-04

If that doesn't work then you should type the path in manually

author
ThisunS (author)2017-05-30

Please help :'(

(step 12)

Password:

esptool.py v2.0-beta3

Connecting........_____....._____....._____....._____....._____....._____....._____....._____....._____....._____

A fatal error occurred: Failed to connect to Espressif device: Timed out waiting for packet header

Thisuns-MacBook-Pro:esptool-master thisunsudaraka$

author
quốcđạt (author)2017-05-25

update video

author
DanielT211 (author)2016-08-25

Hi, does blynk library works at more recent ESP8266-01 version? I got AT version:0.60.0.0(Jan 29 2016 15:10:17) SDK version:1.5.2. Thanks

author
nolmath (author)DanielT2112016-08-26

I would suggest using the version I used. I'm not sure if the newer one works or not

author
skiyer (author)2016-07-25

while trying step 12,.. i got this error .....

Subramanians-MacBook-Air:esptool-master skiyer$ sudo ./esptool.py --port /dev/tty.usbmodem1411 write_flash 0x00000 AT22SDK10020150320boot12.bin

esptool.py v1.2-dev

Connecting...

A fatal error occurred: Failed to connect to ESP8266

what should i do?

author
skiyer (author)2016-07-25

while trying step 12,.. i got this error .....

Subramanians-MacBook-Air:esptool-master skiyer$ sudo ./esptool.py --port /dev/tty.usbmodem1411 write_flash 0x00000 AT22SDK10020150320boot12.bin

esptool.py v1.2-dev

Connecting...

A fatal error occurred: Failed to connect to ESP8266

what should i do?

author
SemV1 (author)2016-07-01
i'm getting this error how can i fix this

sudo ./esptool.py --port /dev/tty.usbserial-A50285BI write_flash 0x00000 AT22SDK10020150320boot12.bin

esptool.py v1.2-dev

Connecting...

A fatal error occurred: Failed to connect to ESP8266

author
SunmeetC (author)2016-06-13

I am using the correct serial port name ass shown in step 12. But still I'm getting an error of invalid syntax.

Screen Shot 2016-06-13 at 3.56.24 AM.png
author
nolmath (author)SunmeetC2016-06-13

That should have worked. Maybe try reinstalling esptool and pyserial

author
spetyo (author)2016-06-12

https://www.youtube.com/watch?v=_A8iyLPsGAw

author
marten99 (author)2016-05-27

Now, my ESP8266 gets enough electricity, but when I open my Blynk app, it tells me that my Arduino Mega is not in Network.

When I look at the Serial Monitor, everything is like step 14, instead of the last row, when AT+CIPSEND =37 and when I should get the PING

what my Serial Monitor says:

[19] Blynk v0.3.3
[520] Connecting to ___
ATE0
AT+CWMODE?
AT+CWJAP="___","___"
AT+CIFSR
[3578] IP: +CIFSR:STAIP,"___.___._.___"
+CIFSR:STAMAC,"--:--:--:--:--:--"

OK
AT+CIPMUX=0
[3601] Connected to WiFi
AT+CIPCLOSE
AT+CIPSTART="TCP","cloud.blynk.cc",8442
AT+CIPCLOSE
AT+CIPSTART="TCP","cloud.blynk.cc",8442
AT+CIPCLOSE
AT+CIPSTART="TCP","cloud.blynk.cc",8442
AT+CIPCLOSE
AT+CIPSTART="TCP","cloud.blynk.cc",8442
author
nolmath (author)marten992016-05-27

It looks like you are using an old library. The server should be cloud-blynk.com. The server you're trying to use is no longer supported

author
marten99 (author)nolmath2016-05-29

I tryed every libary I found between v0.3.4 and v0.3.7 but they all deal with "cloud.blynk.cc"

And v0.3.4. is the only one wich has the "ESP8266_HardSer.h" Folder.

Could you give me a link for the right libary?

author
nolmath (author)marten992016-05-30

This is the one I use https://github.com/blynkkk/blynk-library/releases/download/v0.3.4/Blynk_v0.3.4.zip. It should work. I suggest deleting all the other blank library versions as well

author
marten99 (author)nolmath2016-05-30

Ok, my ArduinoIDE used an old library wich I installed weeks before I found this page in _documents_..., not in _Programs.., where my other librarys are...

Now, it works, but not reliable and stable. That means that I have to restart the Arduino a few times before the ESP8266 connects to the Internet. The times bevor, I get *Failed to connect WIFI* or *Failed to disable Echo*.

Could it be the ESP8266, if it is not booted already? But if I Interrupt the power supply of the arduino for a short moment and reconnect it, (ESP stays on), I've got the same Problem. :(

Or do you have another idea???


I hope to handle also this problem, but nonetheless I want to have a LED which lights, when the ESP is connectet to the Internet.

What do I have to write for *connectet* or *disconnected* ???

for example:

if(*connected*)

DigitalWrite(LED1,HIGH)

else

DigitalWrite(LED1,LOW)

Thank you for taking time :)

author
nolmath (author)marten992016-05-30

It looks like you need a more stable power source. The 3.3V output sometimes can't handle the ESP's current draw. Try the 5V with a voltage regulator or voltage divider. As for the code to see if it is connected, I'm not sure. I know the code to light an led when it connects to blynk but not the Internet. It should be a quick Google search though. Or check the Blynk community for posts about it

author
marten99 (author)nolmath2016-05-31

thats what I ment. I want the LED to shine if the Arduino is connected to Blynk. How can I do this? Google wasn't helpful in this case :/

author
nolmath (author)marten992016-05-31

if (Blynk.connected()) {
digitalWrite(LED1, HIGH);
}
else {
digitalWrite(LED1, LOW);
}

author
marten99 (author)nolmath2016-06-03

It works, thank you.

Hopefully last question on this issue:

It doesn't connect with the Internet when there is no connection between Laptop and Arduino! So if I power Arduino and ESP8266 with a battery, the blue LED of the ESP lights the whole time and the green LED (lights, if ESP is connected) stays off. Do I have to Change something with the Code if I want to run the construction Independent of a PC or similar?

author
nolmath (author)marten992016-06-03

A battery most likely won't be able to handle the ESP's current draw. You need a solid connection. I use an Arduino power supply and it works

author
nolmath (author)2016-05-31

Please look through the comments. This has been addressed

author
REGATTE (author)2016-05-27

hey man nice make

i have a prob

whenever i copy the py serial folder into terminal and paste the sudo...... line and press enter it shows no such directory exists

Last login: Sat May 28 08:55:25 on console

Flying-Horse-2:~ demo$ cd

Flying-Horse-2:~ demo$ /Users/demo/Desktop/pyserial-2.7

-bash: /Users/demo/Desktop/pyserial-2.7: is a directory

Flying-Horse-2:~ demo$ sudo python setup.py install

Password:

python: can't open file 'setup.py': [Errno 2] No such file or directory

Flying-Horse-2:~ demo$

what to do?

author
nolmath (author)REGATTE2016-05-28

Your first two commands should be a single command. It should look just like the example code I added on that step

author
REGATTE made it! (author)nolmath2016-05-28

still no change

it shows no such directroy

Screen Shot 2016-05-28 at 8.49.38 PM.png
author
nolmath (author)REGATTE2016-05-28

I'm sorry. There should be a space after cd. I will make the edit on the instructable

author
REGATTE made it! (author)nolmath2016-05-28

coming to the flashing esp8266 it dint give me the result u got it terminal

Screen Shot 2016-05-29 at 8.34.08 AM.png
author
nolmath (author)REGATTE2016-05-28

It should be ".bin" not ".binr"

author
REGATTE made it! (author)nolmath2016-05-28

even with .bin

im not getting the same result as yours

Screen Shot 2016-05-29 at 9.46.07 AM.png
author
nolmath (author)REGATTE2016-05-29

Actually, your problem is that you used dev/cu. take a look at step 2 under step 12. There should be a tty in there. The port name is also case sensitive

author
nolmath (author)REGATTE2016-05-29

Ok, so did you go through and check the name of your port as it says in the tutorial? You are using the name of my port "usbmodemFA131" and it may not be the same

author
joeyzh (author)2016-05-27

This is a very interesting project but it's just kind of complicated to setup wifi shield for me. I've been searching for an Arduino compatible platform with built-in wifi for a long time and found this platform is quite interesting: http://www.amebaiot.com/. I'll try to get some and may be post some project based on this platform later.

author
marten99 (author)2016-05-19
Hi guys,I try to do this at Win10 too...
but I have a Problem! When I try to verify the Sketch I get this error...

C:\Users\Marten\AppData\Local\Temp\arduino_modified_sketch_628403\sketch_may19a.ino:3:29: fatal error: ESP8266_HardSer.h: No such file or directory

#include <ESP8266_HardSer.h>

^

compilation terminated.

I hope you can help me and it won't be that complicated to fix it.please excuse my bad englishand thanks for every answer, Marten
author
nolmath (author)marten992016-05-20

Go back to step 8 and make sure you added those blynk libraries. That should fix the problem

author
marten99 (author)nolmath2016-05-20

I took 0.3.6. instead of 0.3.4.

that was my mistake! Thank you for your help!

Now, I was able to upload the Sketch, but there came another Problem :'-(

When I open the Serial Monitor, I get this ...

[19] Blynk v0.3.3
Failed to disable Echo
[19] Blynk v0.3.3
[520] Connecting to HunteLTE
ATE0
[1530] Failed to disable Echo
AT+CIPCLOSE
AT+CIPSTART="TCP","cloud.blynk.cc",8442


What's wrong this time ???

author
marten99 (author)marten992016-05-20

NEW INFORMATIONS:

I changed RX and TX and then it worked, but only about 2 minutes...

Then, I got the same error message. just WHY D-':

???any idea???
author
nolmath (author)marten992016-05-20

It looks like you need a more stable power source or one of your wires got disconnected. I would suggest using the 5V with a voltage regulator. That's what I use and it works great. You could also use a voltage divided. Just make sure you use the 5V. The 3.3V was just to get the initial connection

author
MartinJ18 (author)2016-05-18

It works great :) Nice tutorial. I made it work on windows 10

author
RodolfoR16 (author)2016-05-12

I made it on windows and it works 100%, but I have one question, if I want to read from an analog pin and write to a virtual should I upload the script to the arduino with all the serial and Blynk.begin() declarations or just the variables that I'm going to use?

author
nolmath (author)RodolfoR162016-05-12

Glad it worked! You need everything in the code I provided as well as any code you need for your project. I hope I understood your question correctly

author
RyanV26 (author)2016-04-04

are you able to update this tutorial with the new information? like blynk libraries etc

author
nolmath (author)RyanV262016-04-04

Yes, I've been meaning to do so but have been really busy with school

About This Instructable

120,419views

105favorites

Bio: Mechanical Engineering student at the University of Michigan
More by nolmath:Connect to Blynk using ESP8266 as Arduino Uno wifi shield (Mac only)
Add instructable to: