int Pin1 = 5; //D1;//IN1 is connected int Pin2 = 4; //D2;//IN2 is connected int Pin3 = 0; //D3;//IN3 is connected int Pin4 = 2; //D4;//IN4 is connected int pole1[] = {0, 0, 0, 0, 0, 1, 1, 1, 0}; //pole1, 8 step values int pole2[] = {0, 0, 0, 1, 1, 1, 0, 0, 0}; //pole2, 8 step values int pole3[] = {0, 1, 1, 1, 0, 0, 0, 0, 0}; //pole3, 8 step values int pole4[] = {1, 1, 0, 0, 0, 0, 0, 1, 0}; //pole4, 8 step values int poleStep = 0; int dirStatus = 3;// stores direction status 3= stop (do not change) String buttonTitle1[] = {"CCW", "CW"}; //Watch Video for details (on Udemy) String buttonTitle2[] = {"CCW", "CW"}; String argId[] = {"ccw", "cw"}; #include #include #include #include #ifndef STASSID #define STASSID "Livebox-37cc" #define STAPSK "8A6060920A8A86896F770F2C47" #endif const char *ssid = STASSID; const char *password = STAPSK; ESP8266WebServer server(80); void handleRoot() { //Robojax.com ESP32 Relay Motor Control String HTML = "\ \ \ \t\nRobojax 28BYJ-48 Motor Control\ \t\n\ \n\n\n\n\n\n

28BYJ-48 Stepper Motor Control

\n"; if (dirStatus == 2) { HTML += "\n\t

Motor Running in CW

\n"; } else if (dirStatus == 1) { HTML += "\n\t

Motor Running in CCW

\n"; } else { HTML += "\n\t

Motor OFF

\n"; } if (dirStatus == 1) { HTML += "\t
\n\t\t"; HTML += buttonTitle1[0]; //motor ON title } else { HTML += "\t\n\n"; //Watch details at my Arduino Course at Udemy.com if (dirStatus == 2) { HTML += "\t
\n\t\t"; HTML += buttonTitle1[1]; //motor ON title } else { HTML += "\t\n\n"; HTML += "\t\n\n\n"; server.send(200, "text/html", HTML); } void handleNotFound() { String message = "File Not Found"; message += "URI: "; message += server.uri(); message += "Method: "; message += (server.method() == HTTP_GET) ? "GET" : "POST"; message += "Arguments: "; message += server.args(); message += ""; for (uint8_t i = 0; i < server.args(); i++) { message += " " + server.argName(i) + ": " + server.arg(i) + ""; } server.send(404, "text/plain", message); } void setup(void) { //Robojax.com 28BYJ-48 Steper Motor Control pinMode(Pin1, OUTPUT);//define pin for ULN2003 in1 pinMode(Pin2, OUTPUT);//define pin for ULN2003 in2 pinMode(Pin3, OUTPUT);//define pin for ULN2003 in3 pinMode(Pin4, OUTPUT);//define pin for ULN2003 in4 Serial.begin(115200);//initialize the serial monitor Serial.println("28BYJ-48 Stepper Motor Control"); //Robojax.com 28BYJ-48 Steper Motor Control WiFi.mode(WIFI_STA); WiFi.begin(ssid, password); Serial.println(""); // Wait for connection while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(""); Serial.print("Connected to "); Serial.println(ssid); Serial.print("IP address: http://"); Serial.println(WiFi.localIP()); //multicast DNS //Robojax.com 28BYJ-48 Steper Motor Control if (MDNS.begin("Moteur")) { Serial.println("MDNS responder started"); Serial.println("access via http://robojaxESP8266"); } server.on("/", handleRoot); server.on("/motor", HTTP_GET, motorControl); server.onNotFound(handleNotFound); server.begin(); Serial.println("HTTP server started"); } void loop(void) { server.handleClient(); MDNS.update(); //Watch details at my Arduino Course at Udemy.com if (dirStatus == 1) { poleStep++; driveStepper(poleStep); } else if (dirStatus == 2) { poleStep--; driveStepper(poleStep); } else { driveStepper(8); } if (poleStep > 7) { poleStep = 0; } if (poleStep < 0) { poleStep = 7; } delay(1); //Robojax.com 28BYJ-48 Steper Motor Control } void motorControl() { //Watch details at my Arduino Course at Udemy.com if (server.arg(argId[0]) == "on") { dirStatus = 1;// CCW } else if (server.arg(argId[0]) == "off") { dirStatus = 3; // motor OFF } else if (server.arg(argId[1]) == "on") { dirStatus = 2; // CW } else if (server.arg(argId[1]) == "off") { dirStatus = 3; // motor OFF } handleRoot(); }//motorControl end void driveStepper(int c) { //Watch details at my Arduino Course at Udemy.com digitalWrite(Pin1, pole1[c]); digitalWrite(Pin2, pole2[c]); digitalWrite(Pin3, pole3[c]); digitalWrite(Pin4, pole4[c]); }//driveStepper end here