Controlling Esp12E NodeMCU with LED from website (local network)

Teacher
Vivek Gupta
Vivek Gupta
Role : Writing free tutorials in free time
  • Website : http://vsgupta.in/
  • Experience : 5+ Years
  • Specialist in : IoT, NLP, Machine Learning, Chatbots, Voice Assistants, Hardware Engineering
Read More

CONTROLLING ESP12E NODEMCU WITH LED FROM WEBSITE (LOCAL NETWORK) – Part1

Introduction

Now, we will write a C code for ESP12E NodeMCU module such that, it will act as a server. And we will use the IP of ESP12E to control LED connected to it. If you are seeing this tutorial, then I would recommend you to start from beginning here "Controlling Esp12E NodeMCU with LED from website (local network)". Else you can begin with the tutorial. So I hope that you have bill of materials ready with you. Lets start:

  1. Open your Arduino IDE and create a new sketch.
  2. And copy and paste the following code:



     
  3. Change the line number 3 and 4 and replace it with your hotspot/wifi username and password
  4. And upload it on your ESP12E NodeMCU module which we will be controlling.
  5. Now plug out the USB and again plugin.
  6. After successfully uploading the code, open your serial terminal and copy the ip address.
  7. And in the browser type in
    http://Your IP Address (xxx.xxx.x.x)/D1/1
  1. This will turn on the LED connected to pin D1 of ESP12E NODEMCU.
  2. You can replace the pin 'D1' to 'D2' and 'D3' respectively.
  3. '1' represents 'on' and '0' represents off.
    http://Your IP Address (xxx.xxx.x.x)/D1/1 - to turn on the led
    http://Your IP Address (xxx.xxx.x.x)/D1/0 - to turn off the led.

Please refer this video along with the tutorial. I have completed the process along with the testing of this chapter.

I hope you enjoyed this tutorial. In the next step, we will make a html web app which will help us to control the LED of ESP12E NodeMCU development board directly.

Click on the next chapter below to start.

Please login to get access to the quiz
Setting up ESP12E NodeMCU on Breadboard with LED (Prev Lesson)
(Next Lesson) CONTROLLING ESP12E NODEMCU WITH LED FROM WEBSITE (LOCAL NETWORK) – Part2
Back to Controlling Esp12E NodeMCU with LED from website (local network)

Comments ( 11 )

  • Amrit Kumbhakar

    It is getting hanged frequently

    • Yes, Because it is in constant loop. What we are doing in this chapter is for education and experimentation. When going for production, we have to even take care of programming memory size, loops etc 🙂 . What are you trying to do? I will try to help you.

      • Amrit Kumbhakar

        I am going to use this for my room.
        I am doing exactly the same as u did.
        Tell me what kind precautions should i take.
        How can i optimize this code?.

        • Hi Amrit, The first thing you need to do this is move away from thingspeak. Thingspeak is mostly meant for collecting data. And we are using REST API which is very slow and not feasible option here. To make this work in realtime and reliable, you can use mqtt protocol. Or if you still want to use rest api, then you can use UBIDOTS cloud. It is reliable and fast. Only problem is that the usage limit. So basically four options here:
          1. Use mqtt(thingspeak provides mqtt. search in dashboard)
          2. Use UBIDOTS cloud instead of thingspeak
          3. Use BLYNK app. BLYNK app is pretty reliable. I have used it. But I don’t like it only for the reason because I am developer. Blynk is drag and drop and there is no learning involved.
          4. Create your own IoT cloud from scratch.Here I have already made tutorial on that: https://youtu.be/I1iz0YlBl84 . If you have a hosting service, then you can make your own cloud. Which can be real time.

          • I am not connecting it via thinkspeak. I am simply controlling the LED via webpage using ipaddress/D1/1or ipaddress/D1/0 command and it is getting hanged after some frequent operation.

          • Are you running loop? Make sure that there is free memory while running the code. I mean the use case which you just said does not require it to continuous run the code.

  • I am going to use this for my room.
    I am doing exactly the same as u did.
    Tell me what kind precautions should i take.
    How can i optimize this code?.

  • Pakistan boys

    Thank you for your road map and also help in our FYP.
    vivek bhai chumi tu bnti hai!

    Profound Regard
    Enggr.Zeeshan
    Enggr.Mujeeb
    Enggr.Qamar

  • John

    Hi. Your tutorials are amazing. I have followed them and they all worked fine. I have a question though. Instead of LEDs i need to have door/window sensors. They are some cheap magnetic devices that if a door/window opens/closes to send its current state. Could you advice how to change the code and have 3 sensors, instead of 3 LEDs? So i will know at any time which of the 3 doors/windows is open. If you can, please make a video tutorial on that, since you rock on that!
    Thanks in advance sir.

    • Hi John, Thanks for the appreciation. I will keep that in my mind for future tutorials. Answer your question : There is also a part where I am uploading sensor data on the database. Instead of temperature humidity, you can add three sensors and upload the data on cloud.

Post a Reply