In this tutorial, we’ll learn how to control the speed of a motor using an ESP8266 microcontroller and create a web interface to adjust the motor speed wirelessly. The ESP8266 will act as an Access Point, allowing us to connect to it from any device with a web browser.

Hardware Requirements:

ESP8266 board (e.g., NodeMCU)
Brushless DC (BLDC) motor
Electronic Speed Controller (ESC)
Jumper wires

Software Requirements:

Arduino IDE
ESP8266WiFi library
ESP8266WebServer library
Servo library (for controlling the ESC)

Steps:

Setup Hardware:
    Connect the BLDC motor to the ESC.
    Connect the ESC signal wire to pin D1 on the ESP8266 board.

Write the Code:
    Include the necessary libraries and define constants for the ESC pin, Access Point SSID, and password.
    Create functions to handle requests for the root page ("/"), speed adjustment ("/speed"), and motor stop ("/stop").
    Use HTML and CSS to create a simple web interface with a slider to adjust the motor speed and buttons to set the speed or stop the motor.
    Use the Servo library to control the ESC and set the motor speed based on the input received from the web interface.

Upload the Code:
    Connect the ESP8266 board to your computer via USB.
    Open the Arduino IDE, select the appropriate board and port, and upload the code to the ESP8266.

Test the Web Interface:
    Power up the ESP8266 board.
    Use a device with a web browser to connect to the ESP8266's Access Point (SSID and password specified in the code).
    Open a web browser and navigate to the IP address of the ESP8266.
    Adjust the slider to set the motor speed and click the "Set Speed" button.
    Click the "Stop Motor" button to stop the motor.

Conclusion:
In this tutorial, we’ve learned how to control the speed of a motor using an ESP8266 microcontroller and create a web interface for adjusting the motor speed wirelessly. With this project, you can remotely control the speed of a motor for various applications such as robotics, automation, and IoT projects.

Here is the Arduino firmware:

#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <Servo.h>

#define ESC_PIN D1
#define AP_SSID "CS"
#define AP_PASSWORD "password123"

Servo esc;
ESP8266WebServer server(80);

void handleRoot() {
  String message = "<html><head><title>Welcome to BLDC Motor Control</title></head><body>";
  message += "<h1>Welcome to Eclipse IoT</h1>";
  message += "<p>This is the control interface for the BLDC motor.</p>";
  message += "<p>Please use 'Eclipse Iot System' app from Google Play store to control the motor speed over wifi.</p>";
  message += "</body></html>";
  server.send(200, "text/html", message);
}

void handleSpeed() {
  int speed = server.arg("speed").toInt();
  speed = constrain(speed, 0, 180); // Limit speed value between 0 and 180
  int throttle = map(speed, 0, 180, 1000, 2000); // Map speed to ESC throttle range
  esc.write(throttle); // Set motor speed
  String successMessage = "Speed set to " + String(speed);
  successMessage += "<br><a href='/'>Go back</a>";
  server.send(200, "text/html", successMessage);
}

void handleStop() {
  esc.write(1000); // Set motor speed to 0
  String successMessage = "Motor stopped";
  successMessage += "<br><a href='/'>Go back</a>";
  server.send(200, "text/html", successMessage);
}

void setup() {
  esc.attach(ESC_PIN,  1000, 2000);
  esc.write(0);
  delay(2000);
  
  // Start Access Point
  WiFi.softAP(AP_SSID, AP_PASSWORD);
  IPAddress apIP = WiFi.softAPIP();
  Serial.print("AP IP address: ");
  Serial.println(apIP);
  
  // Setup web server routes
  server.on("/", HTTP_GET, handleRoot);
  server.on("/speed", HTTP_GET, handleSpeed);
  server.on("/stop", HTTP_GET, handleStop);
  
  // Start the server
  server.begin();
  Serial.println("Server started");
}

void loop() {
  server.handleClient();
}

Download From GitHub : https://github.com/geekcraftery/esp8266

To control the Device please down Android App from google play store: Eclipse IoT system

Leave a Reply

Your email address will not be published. Required fields are marked *