Introduction: Programming the ESP8266 WeMos-D1R2 Using Arduino Software/IDE

In this Instructable I will guide you through the steps needed to install, configure and program the WeMos-D1R2 board using the Arduino IDE.

WeMos-D1R2 is an ESP8266-12 based WiFi enabled microprocessor unit on a Arduino-UNO footprint. That means the board looks and works (in most cases) like an UNO. Apparently several shields, sensors and output devices that are manufactured for the Arduino platform will work on the WeMos-D1R2 with the added advantage of builtin WiFi.

There are two WeMos boards in the market.If you are not careful you will end up with a D1 Board which is an older version. You have to make sure you have the current version of the board WeMos-D1R2. I bought my WeMos-D1R2 from Banggood, I believe it is a Hong Kong based online retailer. The quality of the product is good and has a short delivery time, about two weeks to the US. They carry the genuine WeMos-D1R2. There are several older model WeMos-D1 being sold as WeMos-D1R2 to unsuspecting customers by several other vendors.

You will find several similarities between this Instructable and my previous one - Programming the ESP8266-12E using Arduino software/IDEbecause of the fact that the ESP8266-12 is the foundation of the WeMos-D1R2 board. In some cases I have copied and pasted the complete steps.

Step 1: Differences Between the I/O Pins.

Though the Arduino UNO and the WeMos-D1R2 are similar, there are a few differences in their pin assignment. The above illustration provides the mapping of the pins. In some situations programs written for the UNO will need to be modified a little to the proper pin assignments of the WeMos-D1R2. More on this when we write our first sketch.

Step 2: Getting Started - Connect the WeMos-D1R2 to Your Computer

The WeMos-D1R2 board comes without an USB cable. Make sure you have a data cable and not a ordinary charging cable. A data cable causes your Windows OS to react. It announces the attachment of a new hardware and tries to install the USB drivers. It either finds the driver on your system or it does not. If it does not then you will need to download the USB drivers. The USB interface chip is the CH340G. You will need to install the drivers for this chip.

A Google search for the "CH340G drivers" finds several sites. You can download the Windows 7 drivers from here or the Windows 8 from here. Though I have not tried them, other operating systems can be downloaded from here. Some flavors of Windows operating system come with the drivers.

Step 3: Is the WeMos-D1R2 Happily Communicating With Your Computer?

Lets find out if the WeMos-D1R2 and your computer are communicating with each other. Getting this step right is important for any further action. Open the Device Manager via Control Panel| Hardware and Sound.

Step 4: Installing Arduino Software/IDE

I downloaded the most current Arduino software (Version 1.6.8) from here. It is a Windows installer exe file so double clicking on it will start the installation including the installation of several peripheral drivers. You can find detailed instructions to install the Arduino software here.

Once the Arduono software is installed, I tested the install by connecting an existing Arduino Uno that I had and uploaded the Blink sketch. All systems worked as they were supposed to.

Step 5: Where to Find the Arduino IDE Preferences Dialog

You will need to familiarize yourself with the File| Preferencesdialog box. We will need this info later.

Step 6: Where to Find the Arduino IDE Boards Manager Dialog

You will also need to know about the Tools | Board:… | Boards Manager dialog box. You have an older version of Arduino software if you cannot see Board Manager in the menu. Go update your software.

Step 7: Telling Arduino Where to Find the Wemos-D1R2 Library

The WeMos-D1R2 board can be added to the Arduino software/IDE by installing the necessary libraries. This community supported Github page: Unofficial list of 3rd party boards support has the information needed to get your Arduino software to support the WeMos-D1R2. Search/look for “ESP8266” on this webpage. Look for the URL shown in the image above. Copy and paste that URL into your Preferences dialog and select OK. Else you can copy the following and paste into your Preferences dialog and select OK: Either case do not click on the URL.

Step 8: Installing the WeMos-D1R2 Board Via the Board Manager

Open Tools | Board:|Boards Manager dialog box. Somewhere in there you will see the entry “esp8266 of ESP8266 Community version 2.1.0” select that. The Install button will appear, click the Install button. Wait for a while… This process will take some time to download and complete. After the install it is a good idea to shut the Arduino program and restarted it.

Step 9: Determining the COM Port WeMos-D1R2 Shows Up On

If not connected connect the Wemos-D1R2 board to your computer. Give it a couple of minutes to get to know the computer. Go to Control Panel| Hardware and Sound| Device Manager and click on Ports (COM & LPT). There you will find the port number that your Wemos-D1R2 is connected on. In my case it is COM12. Make a note of that, we need this info later.

Step 10: Selecting the WeMos-D1R2 Board

Go to Tools | Board:… scroll way down and select WeMos D1 R2 & mini. The Tools menu changes to the second image shown above.

Step 11: Configuring COM Port

In a Step 9 we had determined the COM port WeMos-D1R2 appears on. To select the COM port, go to Tools | Port: and select the COM port, in my case it was COM12.

Step 12: Configuring COM Port Speed

To select the speed of communication between the WeMos-D1R2 and the computer. Go to Tools | Upload Speed: and select 115200. We are ready to upload our first sketch.

Step 13: Test Drive the Setup

Test drive the complete setup using the boiler plate sketch.
To upload the boiler plate sketch go to Sketch | Upload or use the shortcut key Crtl+U or click on the right arrow button next to the check mark. A successful compile and upload means all systems are working and we are ready to get to the real stuff.

Step 14: Trying the Blink Example

Load the packaged example Blink. To find it go to File | Examples | 01.Basics | Blink. Compile and upload as instructed in the previous step. Nothing happens. :(

The reason nothing happens is because the on board LED on the UNO is connected to pin 13. Refer to the table in Step 2. On the WeMos-D1R2 the on board LED is connected to pin 14.

Replace all instances of pin 13 with pin 14 and save the sketch as WeMosBlink. Compile and upload as instructed in the previous step. Viola the blue LED starts blinking.

Replace all instances of pin 13 with pin 2 and save sketch. Compile and upload as instructed in the previous step. The blue LED on the ESP8266-12 module starts blinking.

Disconnect the WeMos-D1R2 from your computer and connect an external 5V power source. I connected it to the power bank that I use to charge my phone. The LEDs will start blinking.

We aren't WiFing yet. That will be in the next Instructable. Time permitting I will write one soon. If you feel motivated enough try adopting my previous Instructable Programming a HTTP Server on ESP-8266-12E to the WeMos-D1R2 and update me in the comments.

Happy IoTing.

Step 15: ​List of Other Instructables I Have Written


Damiend43 made it!(author)2017-01-16

Im super new to this and thank you very much for your help, its very precise and saved me a lot of nervous breakdown. Way to go.

I am trying to connect my wemos D1 mini to display data on a 1.8 screen tft (to get the weather) and all I get is a blank white screen when uploading example. Im not sure of my soldering skill. is there a way to know if the issue is hardware (soldering) or software (version issues and so on)?

TomK32 made it!(author)2017-01-17

White screen is a good first step, you just gotta make sure you match the pins.

I'm using ucglib and following did work for my D1 (I have a mini too but didn't try with that, yet):

Ucglib_ST7735_18x128x160_SWSPI ucg(/*sclk=*/ SCL, /*data=*/ SDA, /*cd=*/ D11 , /*cs=*/ D10, /*reset=*/ D12);

and wire the five pins scl, sda, cd (rs on my display), cs and rs to the correct pins.

btw, you know ?

Damiend43 made it!(author)2017-01-17

I am trying this (well at least trying to run examples for now) :

Just a blank screen, with any library I tried.

slarti.fartfast made it!(author)2017-05-17

It may be a bit late, but I think the problem is that it looks like TomK32 is using an I2C screen (scl/sda) not SPI (sck/mosi/miso/ce)

ucglib works fine for spi, on my ILI9341 screen to the ESP8266 I used

sck=d13 mosi=d11 miso=d12 (those are the esp8266 hardware spi default) then ce=d2 cs=d8 d/c=d4 reset=d0

the screens are sensitive to power upset on boot, mine was stuck in white screen mode till i put a hard reset into the code.

TomK32 made it!(author)2017-01-18

it's not so much about the library as the correct pinout.

kaihgr made it!(author)2017-05-01

Great Instructable/very clear steps!

Some of us have had trouble uploading to the WeMos, and discovered that D3 and D8 may need to be pulled to ground during uploading only (not during operation). See the thread at

Thanks for the great teaching!

Glumgad made it!(author)2017-04-30

Thank you for the detailed explanation.

I wish I read it BEFORE I bought the old version )))

Ivod8 made it!(author)2016-12-01

Excelent tutorial, I've used pin 2 for the D1 mini
One thing I've noticed is that the LED is ON when output is LOW

jainrk made it!(author)2017-04-23

That is correct. Low=ON

Gadh31 made it!(author)2017-04-23

Exactly the same for me on my D1 : pin 2 LED is ON when output is LOW.

Gadh31 made it!(author)2017-04-23

Thank you, very good tuto, work fines (except pin 2 for me, on my D1, which is ON when OUTPUT is LOW).

AnandM51 made it!(author)2017-04-05

thanks a lot sir,you article was like a diamond in an ocean!

brainfarth made it!(author)2017-03-19

Thanks a bunch! If only I had found this article Hours ago...

TheerapongSanthaveesuk made it!(author)2017-02-28

nice work!

KS10 made it!(author)2017-02-22

excellent tutorial. keep posting good one.

aryes1 made it!(author)2016-12-27

Compiled file is HUGE. Blink is 222k. Seems to be adding all possible functions even if they are not used.

isdubkov made it!(author)2017-02-10

kekeke. There is a competition in Russia who writes the smallest blink on Arduino or AVR, the ex-top result was 2 bytes, and now is 0 (zero) bytes (blinking via FUSES). So blink with code size 222k seems ridiculous.

TomK32 made it!(author)2017-01-17

Sure, but 4M on the wemos, who cares, right? I have some smaller esp8266 with 8M, just in case :D

tunaip made it!(author)2017-02-07


tunaip made it!(author)2017-02-06

Great tutiorial, simple and "to the point". Moving on to your next Wemo's D1 tutorial. Thank you.

DavidH818 made it!(author)2016-12-04

Couldn't find a pin 13 listed in any of the program lines under file/examples/basics/blink, DID find it under file/examples/digital/blink without delay, changed the pin number 13 to a 14, uploaded it and got an onboard led to blink. Little errors in instruction and programming could easily cause my noob self to chuck the board as a bricked unit. Although I do agree that experience is what you get when things go wrong. Seems like when you select the wemos d1 board in board manager...then it should load up the sketch examples for that specific board....especially allowing for the different from UNO pinouts and onboard led locations. Oh it is time to try some 8266 wifi stuff...glutton fpr punishment here! Thank you for this really did help over all.

TomK32 made it!(author)2017-01-17

my pro-tip: use D13, D14 instead of 13, 14. There's a header file that defines those to the correct interal pins say D6 becomes pin 12.

bbuldoc made it!(author)2017-01-05

Thank you very much.

johnip4 made it!(author)2016-12-09

I just got a Wemos D1. I was able to get the web server working without any problems. I'm an OK Arduino programmer but a complete NOOB on the Wemos. Is there a reference I can look to in order to better understand the wifi and web commands?

Tvixen made it!(author)2016-12-02

Hi there

Thanks for a great tutorial.

Does this one WeMos-D1R2 only control one on/off function, or can i control more in/outputs on the same ip and port ?

To be more exact. Can I control different devices with only one WeMos-D1R2 ?

Thanks in advance.

Ralphxyz made it!(author)2016-11-20

Hope someone is still monitoring this thread.

I ran the blink code and the LED blinks rapidly BUT then it stops!!

The On led is now on and the SCK led is slowly blinking but the led on Pin 14 no longer blinks!!

flyingsparkie made it!(author)2016-10-25

Brilliant tute, uploading to my WeMos before this, I was getting header, exit code 1 errors. I renamed the arduino15 to something different and loaded the IDE up, copied the link to the preferences etc...loaded the blink.....YAY!! it's working again.

Thanks a mil.

JurjunKoning made it!(author)2016-10-19

I'm blinking away! Awesome get started tutorial.

dupborges made it!(author)2016-10-07

thanks for the tutorial. It helps me a lot

DanielA384 made it!(author)2016-10-01

Hi, i tried to upload a sketch which was working for arduino mega, but i got a compiler error in an ISR declaration: ISR(TIMER3_COMPA_vect)

Can i use timer interrupts with WeMos?

Regards, Daniel

Erion made it!(author)2016-05-18

I felt motivated and i tried your previous instructable on my Wemos D1(retired). It work perfect, the only thing i had to change were the led pin assingment, thank you very much! Made me very happy when i got things to work! Hope to see more of your tutorials, greetings from Brazil!

jainrk made it!(author)2016-05-19

Erion, thank you for the update and kind words.

killeriq made it!(author)2016-04-14


What is the difference between D1 vs D1 R2 version?

I wrote to Wemos seller on Ali and he mention "R2 is compatible with nodemcu".


jainrk made it!(author)2016-04-25

I believe it has to do with the pull-up resistors. There could be more. I will need to fire up my D1R1 to know more.

About This Instructable




More by jainrk:ESP8266: I2C PORT and Address Scanner$1 USB to UART-serial flashing device (dongle) with 3.3 V power supply for ESP8266MOD ESP-12 moduleProgram/Flash the ESP8266MOD ESP-12 module using the Witty Board and Arduino IDE
Add instructable to: