Welcome! You're about to read a step-by-step guide on how to successfully connect your Arduino Uno to the internet with the ESP8266 (ESP-01). It's also my first Instructable ever, so bare with me please!
Let me start off by saying that the ESP8266 is a tiny, low-priced piece of hardware that if correctly programmed can open a huge world, especially the IOT one. Suddenly all your projects can be activated through the web, be it through your phone or pc, at the click of a button. The possibilities are endless, and somehow it gets me really excited. Unfortunately it's not always an easy process and you will most likely run into problems I haven't. Either way, I'll try my best to answer questions and to mention every problem I encountered!
Step 1: Hardware
Alright, so this is a bit of a tricky part since there are many ways to communicate with the ESP6288. I tried to find the easiest ways out there possible and I'm sorry to tell you, but I don't think you'll be able to successfully upload code to the ESP without soldering a small switch or some buttons... In the end I used the following hardware:
- Arduino Uno
- ESP8266 (ESP-01)
- ESP8266 USB adapter
- ESP-01 adapter
- Switch for the USB adapter
- 4 female-male jumper wires
- USB cable to connect Arduino and PC
As you see, they're not that expensive plus there's no need to use a breadboard nor all those weird resistors and stuff like that. It's all simple adapters and wiring.
Obviously, you'll need an Arduino as well as the ESP8266. But then you also need two adapters for the ESP:
- One to be able to program it (number 3 on the list). This is also the adapter that will have our own modification to it with a switch.
- A second adapter so that you don't kill the ESP by connecting it to the Arduino (number 4 on the list). Since the ESP runs 3.3V, 5V from the Arduino will kill it. And the 3.3V from the Arduino aren't powerful enough.
Lastly, some jumper wires and a USB cable to connect the Arduino to the PC are also necessary.
Step 2: Soldering a Switch to the USB Adapter
Unfortunately, in order to program the ESP, you'll need a way to connect it's GND Pin and GPIO0 Pin. I managed to solder a tiny switch that let's you choose if you want to be in "Program mode" or not. The following Youtube Video will help you with this task, I highly recommend you watch it, since it also tells you a bit about software and why you have to connect Ground and GPIO 0.
In short, this is what I did:
- Cut one of the outer legs of the switch, it can be the right or the left one
- Turn the USB adapter upside down, and solder the two legs of the switch to the GND Pin and GPIO0 Pin. Be careful to not connect other pins as it might not work later on.
- Test your switch with a Multimeter
Again, if in doubt, check the Youtube link above.
Also, the picture above has the switch on the "Program mode". In case you soldered the exact same switch pins as I have, now you know what side is "Program mode".
And if you don't fancy switches, here's a tutorial with buttons.
Step 3: Software
For those who are just searching for links, here they are.
- Firmware (I'm pretty sure this will be the latest version, since it hasn't been updated since Dec 2016)
And for those, who have no idea what those links mean, let me guide you!
- The first step is to install the Arduino IDE. Should be pretty straightforward... Hit next next etc and you're done.
- Next up is the setup of the IDE so that you can program your ESP. To do this, you'll have to go to File -> Preferences and on the bottom under Additional Boards Manager URLs: paste the following URL.
- Then naviagte to tools -> Board -> Boards Manager and scroll all the way down until you find one called esp8266 and hit install. Latest Version please. When it's finished installing restart the IDE.
- Now go download both the flasher and the firmware for the ESP. Create a folder on your desktop called "Flasher" and unzip both downloaded files inside it. We'll need them later.
Cool, right now you should have all the software needed to program the ESP!
Step 4: Testing the ESP
Next up is your first connection with the ESP. This part is a bit tricky and what worked for me might not work for you... Let's hope for the best.
Let's start by uploading a premade sketch that blinks a blue LED on the ESP. For this to work, you'll need the following:
- A modded USB adapter for the ESP, so you can set it to "Program mode". Step 2 of this Instructable.
- Know what USB port (COM port) your ESP will be connected to.
If you don't know the COM port, don't worry. It's easy to find out. Open your IDE and click on tools -> Port and take note of the listed Port(s). After that, insert your USB adapter and go check the listed Ports again. The new one is the COM port you are looking for!
PS: I'm a windows user. If I recall correctly, Macs don't call them COM ports. Either way, it should still work!
So now that you know your Port, feel free to plug your USB adapter in! It should be on "Program mode", in other words, GND and GPIO0 should be connected. Open up the IDE and navigate to Tools -> Board and choose the Generic ESP8266 Module. Then, under Tools make sure that you have the following settings:
- Board: "Generic ESP8266 Module
- Flash size: "512K (no SPIFFS)"
- Port: Your COM port
Lastly, go to File -> Examples -> ESP8266 -> Blink and click on the little check mark on the top left corner of the IDE. This will verify your code and tell you if something is wrong with it. I highly recommend you do this every time before uploading a sketch to the ESP or the Arduino! If successful, you'll see a "Done compiling." text. The only thing left now is to click the "right arrow" icon on the top left of the IDE in order to upload the code. If everything is correctly set up, you should see it getting uploaded and eventually finish. Take a look at your ESP, it should have a blinking LED! Congrats, you just uploaded your first program onto your ESP!
In case you got an error though, don't worry. Probably the switch wasn't on the right side. Unplug your USB adapter and "switch the switch", plug it back in and repeat the process. If it works you know that that's the "Program mode" side! If that still doesn't work, then good luck. That's what I meant with "what worked for me might not work for you"... Post questions/problems in the comments and I'll try my best to help!
PS: Feel free to try other examples out! Maybe the File -> Examples -> ESP8266Wifi -> WifiScan. After uploading, open up the Tools -> Serial Monitor and wait a few seconds. If nothings shows up, either set the Baud rate to 9600 or 115200. And use "Both NL & CR". More on this later in this article, so don't worry if you didn't get any response!
Step 5: Test AT Commands
I call this step optional because none of the whole AT commands were working for me at first. Though I was sure the ESP was working fine because it did Blink with the previous sketch and I also managed to scan for Wifi. But each time I tried to talk to it over AT commands I'd never get an answer. Either way, I'll show you the steps I've made to be able to talk to it. If it doesn't work, jump to the next step.
Plug your ESP into the USB adapter and plug that into your PC. Make sure its not in "Program mode"! Go to Tools and change the Board to Generic ESP8266 Module. Make sure the correct Port is selected and then open up the Serial Monitor (Ctrl + Shift + M) and set the following settings:
- Both NL & CR
- 115200 Baud
If all is correct, try typing "AT" on the top bar and hit enter. You should get an "OK" back. If you do get an "OK", then holy smokes you just managed to connect with your ESP and you can be both proud and happy! Next type "AT+GMR" to get more info about your ESP. In case the SDK version is 1.54 then you can also jump the "Flashing the latest Firmware" step since you already have it.
In case you didn't get an answer, feel free to try it again and/or change the Baud rate. I recommend not "wasting" too much time with this though, since you know that your ESP is working because of Step 4.
PS: If the IDE wants you to save the sketch before verifying/uploading it, don't save it. I've had some problems with saving files and the serial monitor then not working. I'm not sure why yet, got to make some more testing, but I recommend you not to save your sketches.
Step 6: Flashing the Latest Firmware
Even if the previous step didn't work for you, try updating it's firmware with this step, maybe it'll fix it!
Now that you know how to program your ESP, it's time to update it's firmware! Start by plugging your ESP into the USB adapter and then selecting the right Board and Port for it. Don't forget to put it in "Program mode", else flashing won't work!
Next, you'll have to open the folder you created on "Step 2: Software" remember? With the flasher and the .bin file. Open it, and run esp8266_flasher.exe. If asked for admin rights, say yes. Now is also a good time to close the IDE, just to make sure nothing is interfering. Click on the Bin button and select a file named "AiThinker_ESP8266_DIO_8M_8M_20160615_V1.5.4.bin". Make sure your Port is the right one, that the next window is set to 0x00000 and that your ESP is in "Program mode" and click Download. It should start uploading the firmware onto your ESP and the blue LED should be flashing. Wait a bit until it's finished.
When it's done, you'll be rewarded with a "Failed to leave Flash mode" error, which is fine. Ignore it and close the flasher. You just updated your ESP's firmware! Nice.
In case you're having errors, again: Make sure your Port is the right one, that the next window is set to 0x00000 and that your ESP is in "Program mode"! If it still doesn't work, then I'd say your switch isn't working correctly.
Lastly, you might want to try to talk with your ESP through AT now, take a look at the "Test AT Commands" step. If it still doesn't work, don't worry. Go ahead and upload the Blink example again to make sure you didn't break your ESP. If it works, you're still good to go!
Step 7: Connecting Arduino and ESP
This is a simple step showing you how to connect the ESP to the Arduino Uno! As mentioned on step "Hardware", I used the ESP-01 Adapater.
First, plug your ESP onto the ESP-01 Adpater and make sure it's facing the right way! Next, grab your 4 jumper wires and connect them like so:
- Pin 3 on the Arduino to Pin RX on the Adapter
- Pin 2 on the Arduino to Pin TX on the Adapter
- Pin 5.5V on the Arduino to Pin VCC on the Adapter
- Pin GND on the Arduino to Pin GND on the Adapter
Wiring done. Easy pzy right?
PS: I recommend using a red wire for the 5V connection and a black wire for the GND connection. It's just a standard in electronics.
Step 8: End + Things to Keep in Mind
Alright, if you have followed my guide and I haven't messed anything up, you should now at least be able to have a working ESP with updated Firmware. Maybe it even talks to you and you to it, that would be perfect! Go ahead and explore this wonderful world of IOT and such. Maybe you'll want to turn on a light at the click of a button on your phone, or maybe turn on the watering system in your garden (like I am trying to do). I don't know, I'll let you choose. Feel free to write some feedback/questions about this instructable below!
Just some extra things to keep in mind:
- While uploading code to your Arduino, Pin 0 (RX) has to be free!
- If you are running your ESP through the 3.3V off the Arduino, beware it might not be powerful enough and you might be getting errors because of it! I highly recommend the ESP-01 Adapater.
- In case you want to communicate with your ESP over the Arduino and not the USB Adapter, you'll have to do the following:
- Necessary: You'll have to be able to talk with AT commands with your ESP over the USB adapter to be able to switch!
- Go ahead and plug your USB adapter with the ESP. Make sure it's not on "Program mode"!
- Choose the ESP8266 Board and correct Port and open the Serial Monitor (115200 Baud).
- Type "AT" and get an "OK" back.
- We'll have to change the default Baud rate of the ESP with the following command: "AT+UART_DEF=9600,8,1,0,0" (or for some versions "AT+CIOBAUD=9600").
- You should get an "OK" back or some type of confirmation
- Close the Serial Monitor.
- Unplug the USB adapter and plug your ESP into the Arduino adpater. Connect the adapter to the Arduino like shown on step "Connecting Arduino and ESP".
- Connect the Arduino with your PC.
- Change Board to Arduino and select the correct Port.
- Upload this code to the Arduino.
- Open the Serial Monitor once more, but this time at 9600 Baud.
- You should now be able to type "AT" and get an "OK" back.