๐ŸŒ๐Ÿ”ฅ Controlling your motors over WiFi will let you operate them from any phone or PC browser, which is perfect for a wireless robot or remote control system! ๐Ÿš€


๐Ÿ”น Plan: How It Works

1๏ธโƒฃ The Arduino R4 WiFi creates a web server.
2๏ธโƒฃ A simple webpage (with buttons/sliders) controls the motors.
3๏ธโƒฃ The Arduino reads button presses and moves the servo + stepper motors accordingly.


๐Ÿ”น Components Needed

โœ… Arduino R4 WiFi
โœ… SG90 Servo
โœ… 28BYJ-48 Stepper + ULN2003 Driver
โœ… WiFi Network (Router or Hotspot)


๐Ÿ”น Step 1: Connect Motors to Arduino

๐Ÿ”ธ SG90 Servo

Servo PinArduino Pin
VCC (Red)5V
GND (Black)GND
Signal (Orange)Pin 6

๐Ÿ”ธ 28BYJ-48 Stepper (via ULN2003 Driver)

ULN2003 PinArduino Pin
IN18
IN29
IN310
IN411
VCC5V
GNDGND

๐Ÿ”น Step 2: Arduino Code (WiFi Web Server)

This code sets up a webpage with buttons to control both the servo and stepper motor.

#include <WiFiS3.h>
#include <Servo.h>
#include <Stepper.h>

const char* ssid = "YOUR_WIFI_NAME";      // Change to your WiFi
const char* password = "YOUR_WIFI_PASS";  // Change to your WiFi password

WiFiServer server(80);  // Start web server on port 80

Servo myServo;
const int stepsPerRevolution = 2048;
Stepper myStepper(stepsPerRevolution, 8, 10, 9, 11);

void setup() {
    Serial.begin(115200);
    myServo.attach(6);
    myStepper.setSpeed(10);

    // Connect to WiFi
    WiFi.begin(ssid, password);
    while (WiFi.status() != WL_CONNECTED) {
        delay(500);
        Serial.print(".");
    }
    Serial.println("Connected to WiFi!");
    Serial.println(WiFi.localIP()); // Print IP Address

    server.begin(); // Start web server
}

void loop() {
    WiFiClient client = server.available();  
    if (client) {
        String request = client.readStringUntil('\r');
        client.flush();
        
        if (request.indexOf("/servo_up") != -1) {
            myServo.write(180);  // Move Servo UP
        } else if (request.indexOf("/servo_down") != -1) {
            myServo.write(0);  // Move Servo DOWN
        } else if (request.indexOf("/stepper_left") != -1) {
            myStepper.step(-50);  // Stepper Left
        } else if (request.indexOf("/stepper_right") != -1) {
            myStepper.step(50);  // Stepper Right
        }

        // HTML Webpage
        client.println("HTTP/1.1 200 OK");
        client.println("Content-type:text/html");
        client.println();
        client.println("<html><body>");
        client.println("<h2>Motor Control</h2>");
        client.println("<button onclick=\"fetch('/servo_up')\">Servo Up</button>");
        client.println("<button onclick=\"fetch('/servo_down')\">Servo Down</button>");
        client.println("<br><br>");
        client.println("<button onclick=\"fetch('/stepper_left')\">Stepper Left</button>");
        client.println("<button onclick=\"fetch('/stepper_right')\">Stepper Right</button>");
        client.println("</body></html>");
        client.println();
        delay(100);
    }
}

๐Ÿ”น Step 3: How to Use It

1๏ธโƒฃ Upload the code to your Arduino R4 WiFi.
2๏ธโƒฃ Open Serial Monitor โ†’ It will show your IP address (e.g., 192.168.1.100).
3๏ธโƒฃ On your phone or PC, open a web browser and go to:
๐Ÿ‘‰ http://YOUR_IP_ADDRESS/
4๏ธโƒฃ Click the buttons to move the servo & stepper wirelessly! ๐ŸŽฎโœจ


๐Ÿ”น Next Steps & Upgrades

๐Ÿ”ฅ Use a slider to set the servo angle smoothly.
๐Ÿ”ฅ Add joystick-like buttons for stepper speed control.
๐Ÿ”ฅ Host a better-designed webpage with a mobile-friendly UI.


๐Ÿ“กBroadcast the signal โ€” amplify the connection.

Leave a Reply