Wi-Fi Controlled Stepper Motor With an ESP Microcontroller

by KushagraK7 in Circuits > Wireless

7007 Views, 33 Favorites, 0 Comments

Wi-Fi Controlled Stepper Motor With an ESP Microcontroller

Cover Image.jpg

I recently came across this video and decided to modify the project to control a stepper motor and add an OLED display. In this quick, little project, let's learn how to control a stepper motor's position from a web browser using an ESP8266 microcontroller. Let's get started!

Get All the Required Stuff

20210804_173807.jpg

For this project, you will need:

  • An ESP8266 microcontroller
  • A Stepper Motor(Unipolar or bipolar)
  • *A suitable stepper motor driver
  • A breadboard
  • Some breadboard wires(Or male jumpers)
  • A 5-volt DC power source
  • ²A 128x64 I2C OLED display(Optional)

*A motor driver like ULN2003 can be used for unipolar stepper motors, while a driver like L298N can be used for both unipolar and bipolar stepper motors.

²The OLED display is an optional device and can be omitted if not available. The motor control will not be affected.

Install the ESP Board in the Arduino IDE

ESP8266_Stepper_Driver_Control_via_WLAN_with_OLED _ Arduino 1.8.13 05-08-2021 08_08_03.png
ESP8266_Stepper_Driver_Control_via_WLAN_with_OLED _ Arduino 1.8.13 05-08-2021 08_11_20.png

  1. Start by going to File> Preferences or by pressing Ctrl+Comma.
  2. Copy this link: https://arduino.esp8266.com/stable/package_esp826...
  3. Paste the link in the 'Additional Boards Manager URLs.
  4. Then go to Tools> Boards> Boards Manager and type in 'ESP' in the search box.
  5. Install the latest release of the ESP boards.

Install the OLED Library

ESP8266_Stepper_Driver_Control_via_WLAN _ Arduino 1.8.13 05-08-2021 07_47_43.png

Start with opening the library manager in the Arduino IDE. You can either go to Sketch> Include library> Manage libraries or press Ctrl+Shift+I. Search for SSD1306 as shown in the picture and install the latest version of the library.

You can skip this step if you are not using the OLED display in your project.

Program the ESP Microcontroller

ESP8266_Stepper_Driver_Control_via_WLAN _ Arduino 1.8.13 05-08-2021 07_54_46.png
ESP8266_Stepper_Driver_Control_via_WLAN_with_OLED _ Arduino 1.8.13 05-08-2021 07_54_48.png

Depending on whether you are using an OLED display or not, you can choose which code to upload on the ESP microcontroller. You can get the Arduino codes from here.

Make sure to put the SSID(name) and password of your Wi-Fi router in the code.

Plug on the ESP Microcontroller on the Breadboard

20210804_173634.jpg

Connect the OLED Display to the Microcontroller

20210804_173405.jpg
20210804_173508.jpg

You can skip this step if you are not using the OLED display in your setup.

Wiring connections from ESP to OLED display:

3v3 -> VCC

GND -> GND

D1 -> SCL

D2 -> SDA

Connect the Stepper Motor to the ESP Microcontroller

20210804_172444.jpg

Connect the stepper motor to the output pins/terminals of the driver module.

Here is how to wire up the stepper motor driver to the ESP microcontroller:

D5 -> IN1

D6 ->IN2

D7 ->IN3

D8 ->IN4

Some stepper motors, particularly unipolar ones have a different stepping sequence. So you might need to change the sequence of the input wire connections to the driver board.

Power Up the Setup

192.168.0.105 - Google Chrome 05-08-2021 11_19_52.png

If you have the OLED display connected to the ESP microcontroller, you can power it from any 5-volt power source. The display will show the IP address of the ESP microcontroller after it gets connected to the Wi-Fi router.

If you don't have the OLED display connected to the ESP microcontroller, then you can connect the microcontroller to your computer and open the serial monitor in the Arduino IDE, the IP address of the ESP microcontroller will be displayed after it gets connected to the Wi-Fi router.

Once you have obtained the IP address, type it in the address bar of the browser on a device that is connected to the same Wi-Fi router and you should be able to see a web page like in the above picture.

Test the Controls

Smartphone Controlled Stepper Motor | ESP8266 Wi-Fi Motor Control

On moving the slider on the browser, the motor should move and follow the direction of the slider as shown in the video.

If the motor just vibrates in place, change the sequence of wires connected to the input pins of the motor driver.

Share Your Creation and Do More!

If you have got your setup working, why not share a picture or two of your creation? I would love to see yours and it will inspire others to make this project. Also, try to take this project further by adding more features, perhaps a different type of screen, 2 stepper motors? There is a lot that can be done!