{"id":149679,"date":"2024-07-18T10:26:22","date_gmt":"2024-07-18T10:26:22","guid":{"rendered":"https:\/\/randomnerdtutorials.com\/?p=149679"},"modified":"2025-03-17T10:49:39","modified_gmt":"2025-03-17T10:49:39","slug":"esp8266-nodemcu-web-server-dc-motor-arduino","status":"publish","type":"post","link":"https:\/\/randomnerdtutorials.com\/esp8266-nodemcu-web-server-dc-motor-arduino\/","title":{"rendered":"ESP8266 NodeMCU Web Server: Control a DC Motor (Arduino IDE)"},"content":{"rendered":"\n<p>In this guide, we&#8217;ll build a web server with the ESP8266 NodeMCU to control a DC motor remotely. The web server will serve a web page with buttons to make the motor spin forward, backward, and stop. To control the motors we&#8217;ll use the L298N motor driver and the ESP8266 will be programmed using Arduino IDE.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" width=\"1200\" height=\"675\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/03\/ESP32-ESP8266-DCMotor-Web-Server.jpg?resize=1200%2C675&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP8266 NodeMCU Web Server Control a DC Motor Arduino IDE\" class=\"wp-image-149680\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/03\/ESP32-ESP8266-DCMotor-Web-Server.jpg?w=1920&amp;quality=100&amp;strip=all&amp;ssl=1 1920w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/03\/ESP32-ESP8266-DCMotor-Web-Server.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/03\/ESP32-ESP8266-DCMotor-Web-Server.jpg?resize=1024%2C576&amp;quality=100&amp;strip=all&amp;ssl=1 1024w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/03\/ESP32-ESP8266-DCMotor-Web-Server.jpg?resize=768%2C432&amp;quality=100&amp;strip=all&amp;ssl=1 768w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/03\/ESP32-ESP8266-DCMotor-Web-Server.jpg?resize=1536%2C864&amp;quality=100&amp;strip=all&amp;ssl=1 1536w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" \/><\/figure><\/div>\n\n\n<p>To better understand how this project works, we recommend taking a look at our DC motor getting started guide with the ESP8266:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/randomnerdtutorials.com\/esp8266-nodemcu-dc-motor-l298n-motor-driver-control-speed-direction\/\">ESP8266 NodeMCU with DC Motor and L298N Motor Driver \u2013 Control Speed and Direction (Arduino IDE)<\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"prerequisites\">Prerequisites<\/h2>\n\n\n\n<p>Before proceeding with the tutorial, make sure you check the following prerequisites.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"750\" height=\"422\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/02\/Control-DC-Motor-ESP8266-L298N-motor-driver.jpg?resize=750%2C422&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP8266 Connected to a DC Motor and a L298N motor driver\" class=\"wp-image-148721\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/02\/Control-DC-Motor-ESP8266-L298N-motor-driver.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/02\/Control-DC-Motor-ESP8266-L298N-motor-driver.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<h3 class=\"wp-block-heading\">1) Parts Required<\/h3>\n\n\n\n<p>To follow this tutorial, you need the following parts:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/mini-dc-motor\/\" target=\"_blank\" rel=\"noopener\" title=\"\">Mini DC Motor<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/l298n-motor-driver\/\" target=\"_blank\" rel=\"noopener\" title=\"\">L298N Motor Driver<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/esp8266-esp-12e-nodemcu-wi-fi-development-board\/\" target=\"_blank\" rel=\"noopener\" title=\"\">ESP8266 <\/a>(read<a href=\"https:\/\/makeradvisor.com\/best-esp8266-wi-fi-development-board\/\" target=\"_blank\" rel=\"noopener\" title=\"\"> Best ESP8266 boards comparison<\/a>)<\/li>\n\n\n\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/jumper-wires-kit-120-pieces\/\" target=\"_blank\" rel=\"noopener\" title=\"\">Jumper Wires<\/a><\/li>\n\n\n\n<li>External power supply for the motors\u2014we&#8217;ll be using <a href=\"https:\/\/makeradvisor.com\/tools\/4x-aa-battery-holder\/\" target=\"_blank\" rel=\"noopener\" title=\"\">4xAA batteries<\/a><\/li>\n<\/ul>\n\n\n<p>You can use the preceding links or go directly to <a href=\"https:\/\/makeradvisor.com\/tools\/?utm_source=rnt&utm_medium=post&utm_campaign=post\" target=\"_blank\">MakerAdvisor.com\/tools<\/a> to find all the parts for your projects at the best price!<\/p><p style=\"text-align:center;\"><a href=\"https:\/\/makeradvisor.com\/tools\/?utm_source=rnt&utm_medium=post&utm_campaign=post\" target=\"_blank\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/10\/header-200.png?w=1200&#038;quality=100&#038;strip=all&#038;ssl=1\"><\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2) Arduino IDE and ESP8266 Boards Add-on<\/h3>\n\n\n\n<p>We\u2019ll program the ESP8266 using Arduino IDE. So, you must have the ESP8266 boards installed on your Arduino \u00ceDE if you haven&#8217;t already.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/randomnerdtutorials.com\/installing-esp8266-nodemcu-arduino-ide-2-0\/\">Installing ESP8266 NodeMCU Board in Arduino IDE 2 (Windows, Mac OS X, Linux)<\/a><\/li>\n<\/ul>\n\n\n\n<p>If you want to use VS Code with the PlatformIO extension, follow the next tutorial instead to learn how to program the ESP8266:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/randomnerdtutorials.com\/vs-code-platformio-ide-esp32-esp8266-arduino\/\">Getting Started with VS Code and PlatformIO IDE for ESP32 and ESP8266 (Windows, Mac OS X, Linux Ubuntu)<\/a><\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">3) Filesystem Uploader Plugin<\/h3>\n\n\n\n<p>To upload the HTML and CSS files needed to build this project to the ESP8266 filesystem (LittleFS), we\u2019ll use a plugin for Arduino IDE:&nbsp;<strong>LittleFS Filesystem uploader<\/strong>. Follow the next tutorial to install the filesystem uploader plugin on Arduino 2 if you haven\u2019t already:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/randomnerdtutorials.com\/arduino-ide-2-install-esp8266-littlefs\/\">Arduino IDE 2: Install ESP8266 NodeMCU LittleFS Uploader (Upload Files to the Filesystem)<\/a><\/li>\n<\/ul>\n\n\n\n<p>If you\u2019re using VS Code with the PlatformIO extension, read the following tutorial to learn how to upload files to the filesystem:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/randomnerdtutorials.com\/esp8266-nodemcu-vs-code-platformio-littlefs\/\">ESP8266 NodeMCU with VS Code and PlatformIO: Upload Files to Filesystem (LittleFS)<\/a><\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">4) Install Libraries<\/h3>\n\n\n\n<p>We&#8217;ll build the web server using the following libraries:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/github.com\/ESP32Async\/ESPAsyncWebServer\" target=\"_blank\" rel=\"noopener\" title=\"\">ESPAsyncWebServer by ESP32Async<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/github.com\/ESP32Async\/ESPAsyncTCP\" target=\"_blank\" rel=\"noopener\" title=\"\">ESPAsyncTCP&nbsp;by ESP32Async<\/a><\/li>\n<\/ul>\n\n\n\n<p>You can install these libraries using the Arduino Library Manager. Go to&nbsp;<strong>Sketch&nbsp;<\/strong>&gt;&nbsp;<strong>Include Library<\/strong>&nbsp;&gt;&nbsp;<strong>Manage Libraries<\/strong>&nbsp;and search for the libraries&#8217; names.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">4) Schematic Diagram<\/h3>\n\n\n\n<p>The following schematic diagram shows how to connect a DC motor to the ESP8266 using a L298N motor driver.<\/p>\n\n\n\n<p class=\"rntbox rntclgreen\">Not familiar with the L298N motor driver? Follow this tutorial first: <a href=\"https:\/\/randomnerdtutorials.com\/esp8266-nodemcu-dc-motor-l298n-motor-driver-control-speed-direction\/\">ESP8266 NodeMCU with DC Motor and L298N Motor Driver \u2013 Control Speed and Direction (Arduino IDE)<\/a><\/p>\n\n\n\n<p>The motor we&#8217;ll control is connected to the motor A output pins, so we need to wire the ENABLEA, INPUT1, and INPUT2 pins of the motor driver to the ESP8266. Follow the next schematic diagram to wire the DC motor and the L298N motor driver to the ESP8266.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"1165\" height=\"1322\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/02\/ESP8266-Circuit-DC-Motor-L298N.jpg?resize=1165%2C1322&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Wiring ESP8266 to DC motor L298N motor driver schematic diagram\" class=\"wp-image-148580\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/02\/ESP8266-Circuit-DC-Motor-L298N.jpg?w=1165&amp;quality=100&amp;strip=all&amp;ssl=1 1165w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/02\/ESP8266-Circuit-DC-Motor-L298N.jpg?resize=264%2C300&amp;quality=100&amp;strip=all&amp;ssl=1 264w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/02\/ESP8266-Circuit-DC-Motor-L298N.jpg?resize=902%2C1024&amp;quality=100&amp;strip=all&amp;ssl=1 902w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/02\/ESP8266-Circuit-DC-Motor-L298N.jpg?resize=768%2C871&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 1165px) 100vw, 1165px\" \/><\/figure><\/div>\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>LN298N Motor Driver<\/strong><\/td><td><strong>Input 1<\/strong><\/td><td><strong>Input 2<\/strong><\/td><td><strong>Enable<\/strong><\/td><td><strong>GND<\/strong><\/td><\/tr><tr><td><strong>ESP8266<\/strong><\/td><td>GPIO 12 (D6)<\/td><td>GPIO 14 (D5)<\/td><td>GPIO 13 (D7)<\/td><td>GND<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>We&#8217;re using the GPIOs on the previous table to connect to the motor driver. You can use any other suitable GPIOs as long as you modify the code accordingly. Learn more about the ESP8266 GPIOs: <a href=\"https:\/\/randomnerdtutorials.com\/esp8266-pinout-reference-gpios\/\">ESP8266 Pinout Reference: Which GPIO pins should you use?<\/a><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Powering the LN298N Motor Driver<\/h4>\n\n\n\n<p>The DC motor requires a big jump in current to move, so the motors should be powered using an external power source from the ESP8266. As an example, we&#8217;re using 4AA batteries, but you can use any other suitable power supply. In this configuration, you can use a power supply with 6V to 12V.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"499\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/01\/4-AA-batteries.jpg?resize=750%2C499&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Powering the LN298N Motor Driver with battery pack\" class=\"wp-image-146198\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/01\/4-AA-batteries.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/01\/4-AA-batteries.jpg?resize=300%2C200&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<p>The switch between the battery holder and the motor driver is optional, but it is very handy to cut and apply power. This way you don&#8217;t need to connect and then disconnect the wires to save power constantly.<\/p>\n\n\n\n<p>We recommend soldering a 0.1uF ceramic capacitor to the positive and negative terminals of the DC motor, as shown in the diagram to help smooth out any voltage spikes. (Note: the motors also work without the capacitor.)<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"422\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/02\/DC-Motor-with-capacitor.jpg?resize=750%2C422&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Mini DC Motor with capacitor\" class=\"wp-image-148589\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/02\/DC-Motor-with-capacitor.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/02\/DC-Motor-with-capacitor.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<h2 class=\"wp-block-heading\">Project Overview<\/h2>\n\n\n\n<p>The following image shows the web page you\u2019ll build for this project.<\/p>\n\n\n\n<p>The web page has three buttons to control the DC motor. Each button makes a request on a different URL so that the ESP8266 knows which button was pressed and acts accordingly.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"653\" height=\"530\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/03\/Control-DC-Motor-ESP8266-Web-Browser-Web-Server.png?resize=653%2C530&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP8266 NodeMCU Control DC Motor using a Web server\" class=\"wp-image-149682\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/03\/Control-DC-Motor-ESP8266-Web-Browser-Web-Server.png?w=653&amp;quality=100&amp;strip=all&amp;ssl=1 653w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/03\/Control-DC-Motor-ESP8266-Web-Browser-Web-Server.png?resize=300%2C243&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 653px) 100vw, 653px\" \/><\/figure><\/div>\n\n\n<ul class=\"wp-block-list\">\n<li>Forward button: makes a request on the <span class=\"rnthl rntliteral\">\/forward<\/span> URL \u2014 the motor will spin forward<\/li>\n\n\n\n<li>Backward button: makes a request on the <span class=\"rnthl rntliteral\">\/backward<\/span> URL\u2014the motor will spin backward<\/li>\n\n\n\n<li>Stop button: makes a request on the <span class=\"rnthl rntliteral\">\/stop<\/span> URL\u2014the motor will stop<\/li>\n<\/ul>\n\n\n\n<p>To build this web page, we&#8217;ll create an HTML file (<em>index.html<\/em>) and a CSS file (<em>style.css<\/em>) that will be saved on the ESP8266 filesystem (LittleFS).<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"organize-files\">Organizing your Files<\/h2>\n\n\n\n<p>The files you want to upload to the ESP filesystem should be placed in a folder called&nbsp;<em><strong>data&nbsp;<\/strong><\/em>under the project folder. We\u2019ll move two files to that folder:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><span class=\"rnthl rntliteral\">index.html<\/span>&nbsp;to build the web page;<\/li>\n\n\n\n<li><span class=\"rnthl rntliteral\">style.css<\/span>&nbsp;to style the web page;<\/li>\n<\/ul>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"547\" height=\"358\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/03\/ESP8266-Web-Server-organizing-files-littlefs.png?resize=547%2C358&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP8266 web server with external files - data folder\" class=\"wp-image-149684\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/03\/ESP8266-Web-Server-organizing-files-littlefs.png?w=547&amp;quality=100&amp;strip=all&amp;ssl=1 547w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/03\/ESP8266-Web-Server-organizing-files-littlefs.png?resize=300%2C196&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 547px) 100vw, 547px\" \/><\/figure><\/div>\n\n\n<p>You should save the HTML, CSS, and JavaScript files inside a folder called&nbsp;<strong><em>data&nbsp;<\/em><\/strong>inside the Arduino sketch folder, as shown in the previous diagram. We\u2019ll upload these files to the ESP8266 filesystem (LittleFS).<\/p>\n\n\n\n<p><strong>You can download all project files:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><a href=\"https:\/\/github.com\/RuiSantosdotme\/Random-Nerd-Tutorials\/raw\/master\/Projects\/ESP8266\/ESP8266_DC_Motor_Web_Server\/ESP8266_DC_Motor_Web_Server.zip\" target=\"_blank\" rel=\"noopener\" title=\"\">Download All the Arduino Project Files<\/a><\/strong><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">HTML File<\/h2>\n\n\n\n<p>Create a file called index.html with the following content:<\/p>\n\n\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-html\">&lt;!DOCTYPE html&gt;\r\n&lt;html&gt;\r\n  &lt;head&gt;\r\n    &lt;title&gt;ESP IOT DASHBOARD&lt;\/title&gt;\r\n    &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1&quot;&gt;\r\n    &lt;link rel=&quot;stylesheet&quot; type=&quot;text\/css&quot; href=&quot;style.css&quot;&gt;\r\n    &lt;link rel=&quot;icon&quot; type=&quot;image\/png&quot; href=&quot;favicon.png&quot;&gt;\r\n    &lt;script src=&quot;https:\/\/kit.fontawesome.com\/0294e3a09e.js&quot; crossorigin=&quot;anonymous&quot;&gt;&lt;\/script&gt;\r\n  &lt;\/head&gt;\r\n  &lt;body&gt;\r\n    &lt;div class=&quot;topnav&quot;&gt;\r\n      &lt;h1&gt;CONTROL DC MOTOR&lt;\/h1&gt;\r\n    &lt;\/div&gt;\r\n    &lt;div class=&quot;content&quot;&gt;\r\n      &lt;div class=&quot;card-grid&quot;&gt;\r\n        &lt;div class=&quot;card&quot;&gt;\r\n          &lt;p class=&quot;card-title&quot;&gt;&lt;i class=&quot;fa-solid fa-gear&quot;&gt;&lt;\/i&gt; DC Motor A&lt;\/p&gt;\r\n          &lt;p&gt;\r\n            &lt;a href=&quot;forward&quot;&gt;&lt;button class=&quot;button-on&quot;&gt;&lt;i class=&quot;fa-solid fa-arrow-up&quot;&gt;&lt;\/i&gt; FORWARD&lt;\/button&gt;&lt;\/a&gt;\r\n            &lt;a href=&quot;backward&quot;&gt;&lt;button class=&quot;button-off&quot;&gt;&lt;i class=&quot;fa-solid fa-arrow-down&quot;&gt;&lt;\/i&gt; BACKWARD&lt;\/button&gt;&lt;\/a&gt;\r\n          &lt;\/p&gt;\r\n          &lt;p&gt;\r\n            &lt;a href=&quot;stop&quot;&gt;&lt;button class=&quot;button-stop&quot;&gt;&lt;i class=&quot;fa-solid fa-stop&quot;&gt;&lt;\/i&gt; STOP&lt;\/button&gt;&lt;\/a&gt;\r\n          &lt;\/p&gt;\r\n        &lt;\/div&gt;\r\n       &lt;\/div&gt;\r\n    &lt;\/div&gt;\r\n  &lt;\/body&gt;\r\n&lt;\/html&gt;\r\n<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/Random-Nerd-Tutorials\/raw\/master\/Projects\/ESP8266\/ESP8266_DC_Motor_Web_Server\/data\/index.html\" target=\"_blank\">View raw code<\/a><\/p>\n\n\n\n<p>In this HTML file, we create three buttons, that when clicked will make a request on different URLs.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>FORWARD: <span class=\"rnthl rntliteral\">\/forward<\/span><\/li>\n\n\n\n<li>BACKWARD: <span class=\"rnthl rntliteral\">\/backward<\/span><\/li>\n\n\n\n<li>STOP: <span class=\"rnthl rntliteral\">\/stop<\/span><\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code language-html\"><code>&lt;p&gt;\n    &lt;a href=\"forward\"&gt;&lt;button class=\"button-on\"&gt;&lt;i class=\"fa-solid fa-arrow-up\"&gt;&lt;\/i&gt; FORWARD&lt;\/button&gt;&lt;\/a&gt;\n    &lt;a href=\"backward\"&gt;&lt;button class=\"button-off\"&gt;&lt;i class=\"fa-solid fa-arrow-down\"&gt;&lt;\/i&gt; BACKWARD&lt;\/button&gt;&lt;\/a&gt;\n&lt;\/p&gt;\n&lt;p&gt;\n    &lt;a href=\"stop\"&gt;&lt;button class=\"button-stop\"&gt;&lt;i class=\"fa-solid fa-stop\"&gt;&lt;\/i&gt; STOP&lt;\/button&gt;&lt;\/a&gt;\n&lt;\/p&gt;<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">CSS File<\/h2>\n\n\n\n<p>Create a file called <span class=\"rnthl rntliteral\">style.css<\/span> with the following content to style the web page.<\/p>\n\n\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-css\">html {\r\n    font-family: Arial, Helvetica, sans-serif;\r\n    text-align: center;\r\n}\r\nh1 {\r\n    font-size: 1.8rem;\r\n    color: white;\r\n}\r\n\r\n.topnav {\r\n    overflow: hidden;\r\n    background-color: #0A1128;\r\n}\r\n\r\nbody {\r\n    margin: 0;\r\n}\r\n\r\n.content {\r\n    padding: 50px;\r\n}\r\n\r\n.card-grid {\r\n    max-width: 800px;\r\n    margin: 0 auto;\r\n    display: grid;\r\n    grid-gap: 2rem;\r\n    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));\r\n}\r\n\r\n.card {\r\n    background-color: white;\r\n    box-shadow: 2px 2px 12px 1px rgba(140,140,140,.5);\r\n}\r\n\r\n.card-title {\r\n    font-size: 1.2rem;\r\n    font-weight: bold;\r\n    color: #034078\r\n}\r\n\r\n.state {\r\n    font-size: 1.2rem;\r\n    color:#1282A2;\r\n}\r\n\r\nbutton {\r\n    border: none;\r\n    color: #FEFCFB;\r\n    padding: 15px 32px;\r\n    text-align: center;\r\n    font-size: 16px;\r\n    width: 150px;\r\n    border-radius: 4px;\r\n    transition-duration: 0.4s;\r\n}\r\n.button-on {\r\n    background-color:#034078;\r\n}\r\n\r\n.button-on:hover {\r\n    background-color: #1282A2;\r\n}\r\n\r\n.button-off {\r\n    background-color:#858585;\r\n}\r\n.button-off:hover {\r\n    background-color: #252524;\r\n}\r\n\r\n.button-stop {\r\n    background-color:#5e0f0f;\r\n    width: 100%;\r\n}\r\n.button-stop:hover {\r\n    background-color: #9b332c;\r\n}\r\n<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/Random-Nerd-Tutorials\/raw\/master\/Projects\/ESP8266\/ESP8266_DC_Motor_Web_Server\/data\/style.css\" target=\"_blank\">View raw code<\/a><\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">ESP8266 Web Server: Control a DC Motor &#8211; Arduino Sketch<\/h2>\n\n\n\n<p>The following code creates a web server that serves the webpage you&#8217;ve created previously to control a DC motor remotely using a web browser on the local network.<\/p>\n\n\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-c\">\/*********\r\n  Rui Santos &amp; Sara Santos - Random Nerd Tutorials\r\n  Complete instructions at https:\/\/RandomNerdTutorials.com\/esp8266-nodemcu-web-server-dc-motor-arduino\/\r\n  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files.\r\n  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\r\n*********\/\r\n\r\n#include &lt;Arduino.h&gt;\r\n#include &lt;ESP8266WiFi.h&gt;\r\n#include &lt;ESPAsyncTCP.h&gt;\r\n#include &lt;ESPAsyncWebServer.h&gt;\r\n#include &lt;LittleFS.h&gt;\r\n\r\n\/\/ Motor A pins\r\nint motor1Pin1 = 12; \r\nint motor1Pin2 = 14; \r\nint enable1Pin = 13; \r\n\r\n\/\/ Replace with your network credentials\r\nconst char* ssid = &quot;REPLACE_WITH_YOUR_SSID&quot;;\r\nconst char* password = &quot;REPLACE_WITH_YOUR_PASSWORD&quot;;\r\n\r\n\/\/ Create AsyncWebServer object on port 80\r\nAsyncWebServer server(80);\r\n\r\n\/\/ Initialize LittleFS\r\nvoid initFS() {\r\n  if (!LittleFS.begin()) {\r\n    Serial.println(&quot;An error has occurred while mounting LittleFS&quot;);\r\n  }\r\n  else {\r\n    Serial.println(&quot;LittleFS mounted successfully&quot;);\r\n  }\r\n}\r\n\r\nvoid initWiFi() {\r\n  WiFi.mode(WIFI_STA);\r\n  WiFi.begin(ssid, password);\r\n  Serial.println(&quot;Connecting to WiFi ..&quot;);\r\n  while (WiFi.status() != WL_CONNECTED) {\r\n    Serial.print('.');\r\n    delay(1000);\r\n  }\r\n  Serial.println(WiFi.localIP());\r\n}\r\n\r\nvoid moveForward(){\r\n  Serial.println(&quot;Moving Forward&quot;);\r\n  digitalWrite(enable1Pin, HIGH);\r\n  digitalWrite(motor1Pin1, LOW);\r\n  digitalWrite(motor1Pin2, HIGH);\r\n}\r\n\r\nvoid moveBackward(){\r\n  Serial.println(&quot;Moving Backward&quot;);\r\n  digitalWrite(enable1Pin, HIGH);\r\n  digitalWrite(motor1Pin1, HIGH);\r\n  digitalWrite(motor1Pin2, LOW);\r\n}\r\n\r\nvoid stopMotor(){\r\n  digitalWrite(enable1Pin, LOW);\r\n  digitalWrite(motor1Pin1, LOW);\r\n  digitalWrite(motor1Pin2, LOW);\r\n}\r\n\r\nvoid setup() {\r\n  Serial.begin(115200);\r\n\r\n  \/\/ Set motor pins as outputs\r\n  pinMode(motor1Pin1, OUTPUT);\r\n  pinMode(motor1Pin2, OUTPUT);\r\n  pinMode(enable1Pin, OUTPUT);\r\n\r\n  initWiFi();\r\n  initFS();\r\n\r\n  server.on(&quot;\/&quot;, HTTP_GET, [](AsyncWebServerRequest *request){\r\n    request-&gt;send(LittleFS, &quot;\/index.html&quot;, &quot;text\/html&quot;);\r\n  });\r\n\r\n  server.serveStatic(&quot;\/&quot;, LittleFS, &quot;\/&quot;);\r\n\r\n  server.on(&quot;\/forward&quot;, HTTP_GET, [](AsyncWebServerRequest *request) {\r\n    moveForward();\r\n    request-&gt;send(LittleFS, &quot;\/index.html&quot;, &quot;text\/html&quot;, false);\r\n  }); \r\n\r\n  server.on(&quot;\/backward&quot;, HTTP_GET, [](AsyncWebServerRequest *request) {\r\n    moveBackward();\r\n    request-&gt;send(LittleFS, &quot;\/index.html&quot;, &quot;text\/html&quot;, false);\r\n  });\r\n\r\n  server.on(&quot;\/stop&quot;, HTTP_GET, [](AsyncWebServerRequest *request) {\r\n    stopMotor();\r\n    request-&gt;send(LittleFS, &quot;\/index.html&quot;, &quot;text\/html&quot;, false);\r\n  });\r\n\r\n  server.begin();\r\n}\r\n\r\nvoid loop() {\r\n  \r\n}\r\n<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/Random-Nerd-Tutorials\/raw\/master\/Projects\/ESP8266\/ESP8266_DC_Motor_Web_Server\/ESP8266_DC_Motor_Web_Server.ino\" target=\"_blank\">View raw code<\/a><\/p>\n\n\n\n<p>You just need to insert your network credentials and <a href=\"#upload-code-files\" title=\"upload the filesystem image\">upload the filesystem image<\/a> and the code will work straight away.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>const char* ssid = \"REPLACE_WITH_YOUR_SSID\";\nconst char* password = \"REPLACE_WITH_YOUR_SSID\";<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">How the Code Works<\/h3>\n\n\n\n<p>Continue reading to learn how the code works or skip to the <a href=\"#demonstration\" title=\"\">Demonstration <\/a>section.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Including Libraries<\/h4>\n\n\n\n<p>First, include the required libraries to connect to Wi-Fi, create the web server and use the LittleFS filesystem.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>#include &lt;Arduino.h&gt;\n#include &lt;ESP8266WiFi.h&gt;\n#include &lt;ESPAsyncTCP.h&gt;\n#include &lt;ESPAsyncWebServer.h&gt;\n#include &lt;LittleFS.h&gt;<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Motor Pins<\/h4>\n\n\n\n<p>Define the GPIOs that will be controlling the motor.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>\/\/ Motor A pins\nint motor1Pin1 = 12; \nint motor1Pin2 = 14; \nint enable1Pin = 13; <\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Network Credentials<\/h4>\n\n\n\n<p>Insert your network credentials on the following variables so that the ESP8266 connects to your network.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>\/\/ Replace with your network credentials\nconst char* ssid = \"REPLACE_WITH_YOUR_SSID\";\nconst char* password = \"REPLACE_WITH_YOUR_SSID\";<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Creating a Server Object<\/h4>\n\n\n\n<p>Create an <span class=\"rnthl rntliteral\">AsyncWebServer<\/span> object called <span class=\"rnthl rntliteral\">server<\/span> on port 80.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>AsyncWebServer server(80);<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Initialize LittleFS<\/h4>\n\n\n\n<p>The following function <span class=\"rnthl rntliteral\">initFS()<\/span> initializes the LittleFS filesystem. We&#8217;ll call it later in the <span class=\"rnthl rntliteral\">setup()<\/span>.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>void initFS() {\n  if (!LittleFS.begin()) {\n    Serial.println(\"An error has occurred while mounting LittleFS\");\n  }\n  else {\n    Serial.println(\"LittleFS mounted successfully\");\n  }\n}<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Initialize Wi-Fi<\/h4>\n\n\n\n<p>The <span class=\"rnthl rntliteral\">initWiFi()<\/span> function connects to wi-fi using the SSID and password you&#8217;ve defined previously.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>void initWiFi() {\n  WiFi.mode(WIFI_STA);\n  WiFi.begin(ssid, password);\n  Serial.println(\"Connecting to WiFi ..\");\n  while (WiFi.status() != WL_CONNECTED) {\n    Serial.print('.');\n    delay(1000);\n  }\n  Serial.println(WiFi.localIP());\n}<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Functions to Control the DC Motors<\/h4>\n\n\n\n<p>We create three functions to control the DC Motor.<\/p>\n\n\n\n<p>The <span class=\"rnthl rntliteral\">moveForward()<\/span> function will move the motor forward.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>void moveForward(){\n  Serial.println(\"Moving Forward\");\n  digitalWrite(enable1Pin, HIGH);\n  digitalWrite(motor1Pin1, LOW);\n  digitalWrite(motor1Pin2, HIGH);\n}<\/code><\/pre>\n\n\n\n<p>The <span class=\"rnthl rntliteral\">moveBackward()<\/span> function moves the motor backward.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>void moveBackward(){\n  Serial.println(\"Moving Backward\");\n  digitalWrite(enable1Pin, HIGH);\n  digitalWrite(motor1Pin1, HIGH);\n  digitalWrite(motor1Pin2, LOW);\n}<\/code><\/pre>\n\n\n\n<p>Finally, the <span class=\"rnthl rntliteral\">stopMotor()<\/span> function stops the motor by setting all motor pins to <span class=\"rnthl rntliteral\">LOW<\/span>.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>void stopMotor(){\n  Serial.print(\"Motor Stopped\")\n  digitalWrite(enable1Pin, LOW);\n  digitalWrite(motor1Pin1, LOW);\n  digitalWrite(motor1Pin2, LOW);\n}<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">setup()<\/h4>\n\n\n\n<p>In the <span class=\"rnthl rntliteral\">setup()<\/span>, initialize the Serial Monitor for debugging purposes.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>Serial.begin(115200);<\/code><\/pre>\n\n\n\n<p>Set the motor pins as outputs.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>\/\/ Set motor pins as outputs\npinMode(motor1Pin1, OUTPUT);\npinMode(motor1Pin2, OUTPUT);\npinMode(enable1Pin, OUTPUT);<\/code><\/pre>\n\n\n\n<p>Initialize Wi-Fi by calling the <span class=\"rnthl rntliteral\">initWiFi()<\/span> function.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>initWiFi();<\/code><\/pre>\n\n\n\n<p>Initialize the LittleFS filesystem by calling the <span class=\"rnthl rntliteral\">initFS()<\/span> function we created previously.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>initFS();<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Handle Requests<\/h4>\n\n\n\n<p>Then, handle the web server. When you receive a request on the root (<span class=\"rnthl rntliteral\">\/<\/span>) URL\u2014this happens when you access the ESP IP address\u2014send the HTML text to build the web page:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>server.on(\"\/\", HTTP_GET, &#091;](AsyncWebServerRequest *request){\n  request-&gt;send(LittleFS, \"\/index.html\", \"text\/html\");\n});<\/code><\/pre>\n\n\n\n<p>When the HTML file loads on your browser, it will make a request for the CSS file. This is a static file saved on the same directory (LittleFS). So, we can simply add the following line to serve files in a directory when requested by the root URL\u2014this way, the CSS file will be served automatically.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>server.serveStatic(\"\/\", LittleFS, \"\/\");<\/code><\/pre>\n\n\n\n<p>When you click the <em>Forward <\/em>button, you make a request on the <span class=\"rnthl rntliteral\">\/forward<\/span> path. When the ESP8266 receives that request, it will call the <span class=\"rnthl rntliteral\">moveForward()<\/span> function to make the motor move forward.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>server.on(\"\/forward\", HTTP_GET, &#091;](AsyncWebServerRequest *request) {\n  moveForward();\n  request-&gt;send(LittleFS, \"\/index.html\", \"text\/html\", false);\n});  <\/code><\/pre>\n\n\n\n<p>Similarly, when you click the <em>Backward <\/em>button, the ESP8266 receives a request on the <span class=\"rnthl rntliteral\">\/backward<\/span> path. When that happens, call the <span class=\"rnthl rntliteral\">moveBackward()<\/span> function to make the motor move in the other direction.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>server.on(\"\/backward\", HTTP_GET, &#091;](AsyncWebServerRequest *request) {\n  moveBackward();\n  request-&gt;send(LittleFS, \"\/index.html\", \"text\/html\", false);\n});<\/code><\/pre>\n\n\n\n<p>When you click the <em>Stop<\/em> button, the ESP8266 receives a request on the <span class=\"rnthl rntliteral\">\/stop<\/span> path and calls the <span class=\"rnthl rntliteral\">stopMotor()<\/span> function.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>server.on(\"\/stop\", HTTP_GET, &#091;](AsyncWebServerRequest *request) {\n  stopMotor();\n  request-&gt;send(LittleFS, \"\/index.html\", \"text\/html\", false);\n});<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Initialize the Server<\/h4>\n\n\n\n<p>Finally, call the <span class=\"rnthl rntliteral\">begin()<\/span> method on the server object to initialize the server.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>server.begin();<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"upload-code-files\">Upload Code and Files<\/h2>\n\n\n\n<p>After inserting your network credentials, save the code. Go to&nbsp;<strong>Sketch<\/strong>&nbsp;&gt;&nbsp;<strong>Show Sketch Folder<\/strong>, and create a folder called&nbsp;<strong>data<\/strong>.<\/p>\n\n\n\n<p>Inside that folder, you should save the HTML and CSS files.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"547\" height=\"358\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/03\/ESP8266-Web-Server-organizing-files-littlefs.png?resize=547%2C358&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP8266 Organizing Files to Upload to LittleFS\" class=\"wp-image-149684\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/03\/ESP8266-Web-Server-organizing-files-littlefs.png?w=547&amp;quality=100&amp;strip=all&amp;ssl=1 547w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/03\/ESP8266-Web-Server-organizing-files-littlefs.png?resize=300%2C196&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 547px) 100vw, 547px\" \/><\/figure><\/div>\n\n\n<h3 class=\"wp-block-heading\">Upload Files to the Filesystem<\/h3>\n\n\n\n<p>With the HTML and CSS files saved in the <em><strong>data <\/strong><\/em>folder, you can now upload them to the board. Make sure you have the <a href=\"https:\/\/randomnerdtutorials.com\/arduino-ide-2-install-esp8266-littlefs\/\" title=\"\">Filesystem Uploader Plugin installed<\/a>.<\/p>\n\n\n\n<p>Select the ESP8266 board you&#8217;re using (<strong>Tools&nbsp;<\/strong>&gt;&nbsp;<strong>Board<\/strong>) and select the right COM port (<strong>Tools&nbsp;<\/strong>&gt;&nbsp;<strong>Port<\/strong>).<\/p>\n\n\n\n<p>Then, upload the files to the ESP8266 board. Press [<strong>Ctrl<\/strong>] + [<strong>Shift<\/strong>] + [<strong>P<\/strong>] on Windows or [<strong>\u2318<\/strong>] + [<strong>Shift<\/strong>] + [<strong>P<\/strong>] on MacOS to open the command palette. Search for the&nbsp;<strong>Upload LittleFS to Pico\/ESP8266\/ESP32<\/strong>&nbsp;and click on it.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"673\" height=\"586\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/02\/upload-to-filesystem-arduino-2-esp32-esp8266-pico.png?resize=673%2C586&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Upload LittleFS to Pico\/ESP8266\/ESP32\" class=\"wp-image-154922\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/02\/upload-to-filesystem-arduino-2-esp32-esp8266-pico.png?w=673&amp;quality=100&amp;strip=all&amp;ssl=1 673w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/02\/upload-to-filesystem-arduino-2-esp32-esp8266-pico.png?resize=300%2C261&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 673px) 100vw, 673px\" \/><\/figure><\/div>\n\n\n<p class=\"rntbox rntcred\"><strong>Important: <\/strong> ensure the Serial Monitor is closed. Otherwise, the upload will fail.<\/p>\n\n\n\n<p>After a few seconds, you should get the message &#8220;<strong>Completed upload.<\/strong> &#8220;. The files were successfully uploaded to the ESP8266 filesystem.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"702\" height=\"293\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/03\/esp8266-upload-files-filesystem-upload-completed.png?resize=702%2C293&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP8266 NodeMCU Files Uploaded Successfully to LittleFS\" class=\"wp-image-149689\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/03\/esp8266-upload-files-filesystem-upload-completed.png?w=702&amp;quality=100&amp;strip=all&amp;ssl=1 702w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/03\/esp8266-upload-files-filesystem-upload-completed.png?resize=300%2C125&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 702px) 100vw, 702px\" \/><\/figure><\/div>\n\n\n<h3 class=\"wp-block-heading\">Upload the Code<\/h3>\n\n\n\n<p>Then, upload the code to your ESP8266 board (make sure you\u2019ve added your network credentials in the code).<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"36\" height=\"39\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/05\/arduino-ide-2-upload-button.png?resize=36%2C39&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Arduino IDE 2 Upload Button\" class=\"wp-image-146269\"\/><\/figure><\/div>\n\n\n<h2 class=\"wp-block-heading\">Demonstration<\/h2>\n\n\n\n<p>When everything is successfully uploaded, open the Serial Monitor at a baud rate of 115200. <\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full is-resized\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"41\" height=\"39\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/02\/serial-monitor-logo-arduino-ide-2.png?resize=41%2C39&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Open Serial Monitor Arduino 2\" class=\"wp-image-148549\" style=\"width:41px;height:auto\"\/><\/figure><\/div>\n\n\n<p>Press the ESP8266 RST button, and it should print the ESP8266 IP address.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"690\" height=\"806\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/03\/Dc-Motor-Web-Server-ESP8266-IP-address.png?resize=690%2C806&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP8266 NodeMCU DC Motor Web Server Print IP address\" class=\"wp-image-149687\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/03\/Dc-Motor-Web-Server-ESP8266-IP-address.png?w=690&amp;quality=100&amp;strip=all&amp;ssl=1 690w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/03\/Dc-Motor-Web-Server-ESP8266-IP-address.png?resize=257%2C300&amp;quality=100&amp;strip=all&amp;ssl=1 257w\" sizes=\"(max-width: 690px) 100vw, 690px\" \/><\/figure><\/div>\n\n\n<p>With the motor connected to the ESP8266 via the L298N motor driver and powered up with an external power supply, open any browser on your local network and type the ESP8266 IP address. The following web page will load.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"653\" height=\"530\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/03\/Control-DC-Motor-ESP8266-Web-Browser-Web-Server.png?resize=653%2C530&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP8266 NodeMCU Control DC Motor using a Web server\" class=\"wp-image-149682\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/03\/Control-DC-Motor-ESP8266-Web-Browser-Web-Server.png?w=653&amp;quality=100&amp;strip=all&amp;ssl=1 653w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/03\/Control-DC-Motor-ESP8266-Web-Browser-Web-Server.png?resize=300%2C243&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 653px) 100vw, 653px\" \/><\/figure><\/div>\n\n\n<p>Click on the buttons to control the DC motor.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"422\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/03\/ESP-Control-DC-Motor.jpg?resize=750%2C422&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP8266 NodeMCU Control DC Motor via Web Server\" class=\"wp-image-149607\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/03\/ESP-Control-DC-Motor.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/03\/ESP-Control-DC-Motor.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<p>The server can handle multiple clients simultaneously. You can also control the DC motor from your smartphone as long as it is connected to your local network.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"421\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/03\/ESP32-Control-DC-Motor-via-Web-Server.jpg?resize=750%2C421&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP8266 NodeMCU Control DC Motor via Web Server Smartphone\" class=\"wp-image-149608\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/03\/ESP32-Control-DC-Motor-via-Web-Server.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/03\/ESP32-Control-DC-Motor-via-Web-Server.jpg?resize=300%2C168&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<h2 class=\"wp-block-heading\">Wrapping Up<\/h2>\n\n\n\n<p>In this tutorial, you&#8217;ve learned how to create a simple asynchronous web server with the ESP8266 to control a DC motor remotely from your computer or smartphone. You can now extend this project to control more motors or control other outputs or even display sensor readings. You can take a look at the following tutorials:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/randomnerdtutorials.com\/esp8266-web-server-gauges\/\">ESP8266 Web Server: Display Sensor Readings in Gauges<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/stepper-motor-esp8266-websocket\/\">ESP8266 Web Server: Control Stepper Motor (WebSocket)<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/esp8266-nodemcu-web-server-websocket-sliders\/\">ESP8266 Web Server (WebSocket) with Multiple Sliders: Control LEDs Brightness (PWM)<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/esp8266-nodemcu-web-server-sent-events-sse\/\">ESP8266 Web Server using Server-Sent Events (Update Sensor Readings Automatically)<\/a><\/li>\n<\/ul>\n\n\n\n<p>If you would like to learn more about building web servers with the ESP8266 from scratch, we recommend taking a look at our exclusive eBook:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/randomnerdtutorials.com\/build-web-servers-esp32-esp8266-ebook\/\" title=\"\">Build Web Servers with ESP32 and ESP8266 eBook<\/a><\/li>\n<\/ul>\n\n\n\n<p>Thanks for reading.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this guide, we&#8217;ll build a web server with the ESP8266 NodeMCU to control a DC motor remotely. The web server will serve a web page with buttons to make &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"ESP8266 NodeMCU Web Server: Control a DC Motor (Arduino IDE)\" class=\"read-more button\" href=\"https:\/\/randomnerdtutorials.com\/esp8266-nodemcu-web-server-dc-motor-arduino\/#more-149679\" aria-label=\"Read more about ESP8266 NodeMCU Web Server: Control a DC Motor (Arduino IDE)\">CONTINUE READING \u00bb<\/a><\/p>\n","protected":false},"author":5,"featured_media":149680,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[265,214,246,300,240,264],"tags":[],"class_list":["post-149679","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-esp8266-project","category-esp8266","category-esp8266-arduino-ide","category-0-esp8266","category-esp8266-projects","category-project"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/03\/ESP32-ESP8266-DCMotor-Web-Server.jpg?fit=1920%2C1080&quality=100&strip=all&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/149679","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/comments?post=149679"}],"version-history":[{"count":13,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/149679\/revisions"}],"predecessor-version":[{"id":168048,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/149679\/revisions\/168048"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media\/149680"}],"wp:attachment":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media?parent=149679"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/categories?post=149679"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/tags?post=149679"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}