With this done, we move to the void setup() function. String redstate = "off" // state of red LED String greenstate = "off" // state of green LED Next, we declare the pins of the Nodemcu to which the red and green LED will be connected and create variables to hold the state of the LEDs. String header // This storees the HTTP request We also specify the port through which the system will communicate and create a variable to hold requests. Ensure the username and password are in-between the double quotes. Next, add the credentials of the WiFi access point to which the NodeMCU will be connected. To start, as usual, we include the library that will be used for the code which in this case, is the ESP8266wifi library. It’s a little bit complex and might be difficult to follow for those without the knowledge of HTML but I will do my best to break it down. The code for this project is a modified version of the code by Rui Santos (credits for him). The Web server should be accessible via a browser on any device on the same network as the NodeMCU. The libraries come attached with the NodeMCU board files for the Arduino, so there is no need to install them once the board files have been installed.Īs mentioned above, our goal is to create a web server through which the GPIOs of the NodeMCU can be controlled. It contains all we need to create a WiFi access point or join up with an existing access point and also create a server and client which are all important for today’s project. This library contains cool functions to implement WiFi based activities and project on the NodeMCU. The main driver behind today’s tutorial is the ESP8266WiFi Library. With that done, we can now move to the code. Follow this detailed tutorial to learn how to set up your Arduino to program ESP8266 based boards. If you are using the Arduino IDE to program the NodeMCU for the first time, you need to do this first before proceeding with the tutorial. However, this requires setting up the Arduino IDE by installing the board support file for NodeMCU. One of the easiest ways to program the NodeMCU is via the Arduino IDE. With the schematics done, we can now move to the code for the project. The positive legs of the green and red LEDs are connected to digital pins 1 and 2 of the NodeMCU (respectively), while their negative legs are connected to ground via a 220 ohms resistor to limit the amount of current flowing through the LEDs. While LEDs are being used here, you can decide to use more useful components like a relay, which could then be used to control appliances in your home.Ĭonnect the components as shown in the schematics below. As mentioned earlier, we will toggle LEDs to demonstrate what can be achieved using the NodeMCU Web server. The schematic for this project is quite simple. The following components are required to build this project Its ease of use and low cost, quickly endeared it to the heart of makers and it is one of the most popular boards today.Īt the end of today’s tutorial, you would know how to use the NodeMCU as a web server and how to control the GPIO pins of your NodeMCU/ESP8266 board from a webpage. The NodeMCU was born out of the desire to overcome all the bottlenecks associated with the first versions of the ESP8266 module which was not compatible with breadboards, difficult to power and even more difficult to program. It is based on the ESP8266 WiFi Module and runs the Lua based NodeMCU firmware. The NodeMCU development board is an open source platform for developing WiFi based embedded devices.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |