loading

Thanks to the guys those who ported the Esp8266 into Arduino IDE and helping all the arduino users happy to the core. Yes it's been long time since they did and this post is bit later to thanks the good hearted work by the guys out there.

Lets begin with Installing the Esp8266 support for the Arduino and see how to blink an LED ( the hello world in the electronics )

check out the video to know step by step tutorial on how to get started with our favourite chip Esp8266



Firstly open the Arduino IDE

Go to files and click on the preference in the Arduino IDE


copy the below code in the Additional boards Manager

http://arduino.esp8266.com/stable/package_esp8266com_index.json

click OK to close the preference Tab.



After completing the above steps , go to Tools and board, and then select board Manager


Navigate to esp8266 by esp8266 community and install the software for Arduino.

Once all the above process been completed we are read to program our esp8266 with Arduino IDE.



















For this example I have used NodeMCU esp8266 and if you are using any other vendor wifi chips or generic wifi module please check with the esp8266 Pin mapping which is very essential to make things works.

The reason why I used D7 pin for this example is , I uploaded the basic blink program that comes with the examples program in the arduino IDE which is connected with 13 pin of arduino. The 13th pin is mapped into D7 pin of NodeMCU.

go to board and select the type of esp8266 you are using. and select the correct COM port to run the program on your esp8266 device.


<p>void setup() {<br>  // initialize digital pin 13 as an output.
  pinMode(13, OUTPUT);
}</p><p>// the loop function runs over and over again forever
void loop() {
  digitalWrite(13, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);              // wait for a second
  digitalWrite(13, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);              // wait for a second
}</p>

upload the program and see the results.

if you like the above tutorial and if you want try out with cool projects you can also check this link here , that's the amazon book link where you can use that book to make IoT with Esp8266 or Nodemcu, that books gives you basic coverage on how to do simple things and get yourself started with arduino and goes on developing projects like sending data to webserver and creating a webserver, uploading and controlling data from a webpage, how to interface TFT LCD and I2C devices and many more things can find on the link.

Step 1: Control an LED From Web Browser

In this blog, we will see How to "Turn On and Turn Off" an LED that has connected to the Esp8266, the esp8266 has programmed from Arduino IDE to control the LED.

We will connect the Esp8266 to the Wi-Fi router using SSID and password of our Home network Wifi , where the esp8266 connect to our wifi and create a webserver, which can be accessed by looking through the serial Monitor of the Arduino window or you can also log into your Wifi router and check for the list of clients connected to your Wi-Fi router.

Here's a window which explains the step by step procedure to connect the Esp8266 to the Wi-fi server and How to access the Webpage and control the LED connected to the Esp8266

For the above video I have used NodeMcu, you can use any type of Esp8266 to make this thing work in your web browser.

look for the mapping of pins in with your Esp8266 vendor, if the program not working properly for you , the fault will be with the pin mapping functionalities, Here I used the D7 pin which mapped to 13th pin when program from the Arduino IDE.

Connect your Esp8266 to Arduino IDE and Select the correct COM Port and board type and 
upload the program. 
Note change the SSID to your WiFi Name and password to your Wifi password. if you forget to change it , esp8266 will not connect connect your wifi.

--------------------------------------------------------------------------------------------------------------------------

<br>

If everything completed you can turn to your serial monitor and check for the ip address that your devices has connected to . you will presented with an serial monitor that look exactly to the picture below.

if you like the above tutorial and if you want try out with cool projects you can also check this link here , that's the amazon book link where you can use that book to make IoT with Esp8266 or Nodemcu, that books gives you basic coverage on how to do simple things and get yourself started with arduino and goes on developing projects like sending data to webserver and creating a webserver, uploading and controlling data from a webpage, how to interface TFT LCD and I2C devices and many more things can find on the link.

<p>I have done this by config the internal MCU Led..</p>
<p>Works absolutely perfectly! For my project, it was a quick tweak to specify what I wanted, and that was it! Thank you. Very good tutorial as well!</p>
Hey, Why this NodeMCu is so unstable? I used your code to blink an LED from browser, after several operations even the page(html code on NodeMcu) won't load, Do we need to disconnect client after every connection? Or What to do? So that Page will load evrytime whenever we type it's IP on browser. Please help me.
<p>I think I had the same issue. It ended up being with the 'Wait until the client sends some data' loop. I added a timeout so if data isn't received in a few seconds it can break out of the loop.</p>
<p>sorry em new to electronics , can u please explain what a time out is ? is like like a delay ? thank you in advance.</p>
<p>such a life saver thank you so much </p>
<p>Thanks! It's so frustrating trying to use Putty to get the thing to do anything! I bought a pretty cheap Amica one from Ebay ($4), and have been fiddling for a few hours trying to get the firmware right.</p><p>Anyway, after that, following your quick tutorial, and changing the &quot;pinMode(16, OUTPUT);&quot; and for the other references to 13, it flashes the onboard blue LED just fine. Now to tinker some more :)h</p>
<p>Very good tutorial! Really helpful!</p>
<p>Very good tutorial!</p>
धन्यवाद सर
Are you thw author of the linked book?
<p>Hello, thank you for this tutorial. But I'm in trouble with the pinout. Could you provide it ? I found some images over the internet but it seems they are wrong.</p><p>Thanks in advance!</p>
<p>(in case you're still looking for it or anyone else is wondering:)</p><p>it depends on which version of the nodemcu you got.</p><p>this pin mapping works for me: <a href="https://www.roboburada.com/public/assets/ESP8266/pinmap.png" rel="nofollow">https://www.roboburada.com/public/assets/ESP8266/p...</a></p><p>compare the number of &quot;reserved&quot; (RSV) pins with your board</p>
In the arduino ide board manager, which board do I select for the esp8266nonemcu? there are other 8266's listed but not the nodemcu.<br>thanks<br>D6
*nodeMCU
<p>worked great. thank you. i am now triggering a buzzer in the other room to piss off my girlfriend when she leased expects it ;)</p>
<p>Board nodemcuv2 (platform esp8266, package esp8266) is unknown </p><p>Error compiling</p><p>What am i supposed to do?</p>
<p>nice project ,worked in first attempt,can you explain how can this page be displayed in a network other than local</p>
<p>Great start to NodeMCU!</p><p>This code misses a trick - if you want this to work without serial or indeed a connected computer and you wish to see if the Nodemcu has connected to Wifi, set the pinout to high first by changing the pin out line to HIGH and not LOW: digitalWrite(ledPin, HIGH); , which will light the LED. Set the LED low after it has connected to Wifi with the following:</p><p> Serial.println(&quot;WiFi connected&quot;); &lt;- After this line</p><p> digitalWrite(ledPin, LOW); &lt;- Add this</p><p>So now the LED lights until the Nodemcu connects to Wifi, then goes out and you can then connect to it through the browser.</p>
<p>Thank you for this tutorial..!!!.. I was stumped in a couple areas until I found this page.... great help!!</p>
<p>can you please provide a code for iot based energy meter reading </p>
<p>Awesome tutorial, got me up and running with this microcontroller very quickly.</p><p>Thanks!</p>
<p>Thanks! Works fine. I have included two more leds (green and red) for connection status.</p>
<p>When i enter the URL, Arduino gives me this error,</p><p><a href="http://arduino.esp8266.com/stable/package_esp8266com_index.json" rel="nofollow">http://arduino.esp8266.com/stable/package_esp8266c...</a> file signature verification failed. File ignored.</p>
<p>Great !, Thanks for easy step.</p>
<p>I had to search through about ten usb cables before I found one that would detect the device and add it to the ports section in windows device manager - just as I was getting ready to send all my modules back to the seller with a tirade....</p>
<p>Hi<br>I'm trying to make a web server using nodeMCU as a master and 2 Arduinos as my clients,I connected BH1750 and Ds18b20 to my Arduinos and I made a wireless connection between clients and master(nodeMCU).My nodeMCU is working by cp2102 not ch340g.I can coonect to my WIFI and I can load the webpage But there is a problem which I faced so many times and which is &quot;nodeMCU disconnects when I wanna get data from my clients and it won't load the web page and even it get disconnected from WIFI&quot;.so That's why I come to your web site and checked your tutorial,but when I upload your code on my nodeMCU it didn't connect to wifi.<br>I attached the Image of web server that I made <br>I desperately need your help.</p>
<p>my serial monitor always returns something like this:</p><p>&Ocirc;&yuml;H! )</p><p>please, how can i solve this problem?</p>
<p>Check your baudrate. It should be 115200 not 96000</p>
<p>Hi,</p><p>bravo for this fine Job. Please where is the code for the last part Ds18b20 to Thingspeak.</p><p>Cheers</p><p>Pierrick</p>
<p>I found it at here:</p><p>https://codebender.cc/embed/sketch:243988#Untitled_Project%20copy.ino</p>
<p>#include &lt;ESP8266WiFi.h&gt;</p><p>#include &lt;OneWire.h&gt;</p><p>#include &lt;DallasTemperature.h&gt;</p><p>#define myPeriodic 15 //in sec | Thingspeak pub is 15sec</p><p>#define ONE_WIRE_BUS 2 // DS18B20 on arduino pin2 corresponds to D4 on physical board</p><p>OneWire oneWire(ONE_WIRE_BUS);</p><p>DallasTemperature DS18B20(&amp;oneWire);</p><p>float prevTemp = 0;</p><p>const char* server = &quot;api.thingspeak.com&quot;;</p><p>String apiKey =&quot;Things speak api key&quot;;</p><p>const char* MY_SSID = &quot;your router name &quot;; </p><p>const char* MY_PWD = &quot;your wifi password&quot;;</p><p>int sent = 0;</p><p>void setup() {</p><p> Serial.begin(115200);</p><p> connectWifi();</p><p>}</p><p>void loop() {</p><p> float temp;</p><p> //char buffer[10];</p><p> DS18B20.requestTemperatures(); </p><p> temp = DS18B20.getTempCByIndex(0);</p><p> //String tempC = dtostrf(temp, 4, 1, buffer);//handled in sendTemp()</p><p> Serial.print(String(sent)+&quot; Temperature: &quot;);</p><p> Serial.println(temp);</p><p> //if (temp != prevTemp)</p><p> //{</p><p> //sendTeperatureTS(temp);</p><p> //prevTemp = temp;</p><p> //}</p><p> sendTeperatureTS(temp);</p><p> int count = myPeriodic;</p><p> while(count--)</p><p> delay(1000);</p><p>}</p><p>void connectWifi()</p><p>{</p><p> Serial.print(&quot;Connecting to &quot;+*MY_SSID);</p><p> WiFi.begin(MY_SSID, MY_PWD);</p><p> while (WiFi.status() != WL_CONNECTED) {</p><p> delay(1000);</p><p> Serial.print(&quot;.&quot;);</p><p> }</p><p> Serial.println(&quot;&quot;);</p><p> Serial.println(&quot;Connected&quot;);</p><p> Serial.println(&quot;&quot;); </p><p>}//end connect</p><p>void sendTeperatureTS(float temp)</p><p>{ </p><p> WiFiClient client;</p><p> if (client.connect(server, 80)) { // use ip 184.106.153.149 or api.thingspeak.com</p><p> Serial.println(&quot;WiFi Client connected &quot;);</p><p> String postStr = apiKey;</p><p> postStr += &quot;&amp;field1=&quot;;</p><p> postStr += String(temp);</p><p> postStr += &quot;\r\n\r\n&quot;;</p><p> client.print(&quot;POST /update HTTP/1.1\n&quot;);</p><p> client.print(&quot;Host: api.thingspeak.com\n&quot;);</p><p> client.print(&quot;Connection: close\n&quot;);</p><p> client.print(&quot;X-THINGSPEAKAPIKEY: &quot; + apiKey + &quot;\n&quot;);</p><p> client.print(&quot;Content-Type: application/x-www-form-urlencoded\n&quot;);</p><p> client.print(&quot;Content-Length: &quot;);</p><p> client.print(postStr.length());</p><p> client.print(&quot;\n\n&quot;);</p><p> client.print(postStr);</p><p> delay(1000);</p><p> }//end if</p><p> sent++;</p><p> client.stop();</p><p>}//end send</p>
<p>Hi, your code has an extra &quot; character inside the &lt;a&gt; tags. It should be:</p><p><br>client.println(&quot;&lt;a href=\&quot;/LED=ON\&quot;&gt;&lt;button&gt;Turn On &lt;/button&gt;&lt;/a&gt;&quot;);</p><p> client.println(&quot;&lt;a href=\&quot;/LED=OFF\&quot;&gt;&lt;button&gt;Turn Off &lt;/button&gt;&lt;/a&gt;&lt;br /&gt;&quot;);</p>
<p>Very good tutorial but I couldn't get the ESP8266 Led control program to load into Arduino IDE. &quot;could not load sketch&quot;... Any ideas why this may be happening ? I have tried other sketches (led blink etc.) in the nodemcu v3 device and they work okay. </p>
<p>Thanks, really easy how-to.</p>
<p>Fantastic! thank you for explaining so well the process to connect and use the ESP8266.</p>
<p>How to establish communication between Nodemcu and d Raspberry pi over WiFi?? I am hosting nodemcu as Client and Pi as server. I am unable to fetch data to raspberry pi. Is it possible to communicate directly between these two??Or do we need a broker in between like webpage or App?? </p><p>I am troubled in sending &quot;hello World&quot; message to raspberry pi over WiFi. I can get the message to one particular IP address, but facing issues to connect to Raspberry Pi.</p><p>NodeMCU and Raspberry pi are connected to same network.</p><p>Please help.</p>
<p>Is there a way to install the environment other than through the arduino board manager? My board manager crashes and wont allow me to load from the json file. It is a fresh install of arduino but it doesn't work on my Windows 10 installation.</p>
<p>I could resolve warning: espcomm_sync failed error. However, I am not able to triger relay. It seems that relay get small amount of voltage from Nodemcu board (wimos). The red LED is very dimly lit. Could you please help resolving this.</p><p>PS. in my other project LED on Relay is brighly lit.</p>
<p>I am not from electronics field. I am an accountant in Mumbai. However, with some efforts I could complete two projects with ultrasonice range finder and Relay.</p><p>To further explore knowledge on this, I bought your book on amazon.in which includes above mentioned project. I want to do this project for controlling AC devices like Bulb and Fan from my mobile phone</p><p>However, I am stuck with error at initial stage. Below mentioned is the error.</p><p>warning: espcomm_sync failed<br>error: espcomm_open failed<br>error: espcomm_upload_mem failed</p><p>I will be grateful, if you could help me resolving these errors.</p>
<p>Thanks, easiest how-to (for nodemcu /ardunio ide) on the web - I think I'll splash out on your book! :D</p>
<p>Very nice write-up for a Quick Start! Helped me confirm my hardware and software environment are set up correctly for first experience with a NodeMCU/ESP8266. </p><p>One suggestion I'd like to make: Since the ESP8266 saves the SSID and password to non-volatile storage, I define them in preprocessor directives rather than variables. I then use a #ifdef/#else/#endif block to call WiFi.begin(MYSSID,MYPASSWORD) if MYSSID is defined or WiFi.begin() if it isn't. Once I've successfully connected the board to my WiFi I delete the preprocessor directives from my code. This greatly reduces the possibility that I'll accidentally store my WiFi credentials in plaintext on GitHub, Codebender or any other code-sharing site.</p>
<p>Got my little nodemcu v3 in the mail a couple of days ago and this &quot;how to&quot; has got me really enthused . Thankyou . </p><p>Your code specifies port 80 but can I manually set an IP address within the code or do I have to set that up in my router fixed to the Esp8266 mac address ?</p>
<p>good stuff, just ordered 2 of these boards. for the money, size and capability i believe that this is the best board on the market. it can handle 99% of a regular consumers needs. its just amazing what they have accomplished with the esp8266 community and implementing arduino ide. thank you for this detailed write up, i will be coming back.!!</p>
Excellent tut. Thank you for taking the time to write this up. It is most helpful ?
<p>glad you liked it :)</p>

About This Instructable

152,736views

369favorites

License:

Bio: I make hobbyist stuffs and play with electronics follow me to know more https://www.facebook.com/arduinolabviewsolidworks https://twitter.com/learnrobotix
More by Magesh Jayakumar:Quick Start to Nodemcu (ESP8266) on Arduino IDE Course on MIT App Inventor and Arduino Hat for the Party 
Add instructable to: