Shopping Cart

⚡️ We’re Helping 1 Million People Build Their First Robots

🇺🇸 Proudly Women-Owned Small Business
wemos wifi controlled robot using l298n

WeMos WiFi Controlled Robot using L298N

We sometimes use affiliate links in our content. This won't cost you anything, but it helps us to offset the costs of paying our writing team. You can support us directly on BuyMeACoffee. Thank you!

Hello and welcome back to this week’s Learn Robotics tutorial! I’m going to preface this article by saying, man, did I dig myself into a bit of a hole with this one! For those of you on Instagram, I posted a video saying I was going to build and program a Wifi-connected robot using a WeMos D1 Mini (based on ESP8266) and an L298N motor controller. Basically retrofitting my Arduino Robot to use a wifi-enabled chip, rather than the Arduino Uno + Sensor shield.

Anyways, I ramble. What I thought was going to be a fairly straightforward and easy reconfiguration, turned into an afternoon of frustration. Who would have thought the WeMos D1 Mini would be so difficult to implement with a motor controller? I think part of my problems included not using a breadboard from the start and having loose motor signal wires.

There aren’t too many full-blown tutorials that show you start-to-finish how to do this, so sit back, relax, and let’s get our robots connected and controlled via magic (wifi!).

Things you’ll need to create a WeMos Wifi Controlled Robot using L298N

wemos wifi controlled robot using l298n

Prework – Before Starting, Construct your Robot

Before proceeding with the tutorial, you’re going to want to assemble your robot chassis, motors, and wheels. You’ll also want to mount your battery pack and breadboard. Once that’s all set, go ahead and jump to Step 1.

Step 1 – Wire up the WeMos & L298N Motor Controller

Because I like writing tutorials that include resources all in one place, here are the two wiring diagrams you’ll need to properly connect your WeMos (Wiring Diagram) to your L298N motor controller. I suggest clicking on both diagrams before continuing…

  1. Place a jumper on both the ENA and ENB pins.
  2. Attach the motor polarity wires as follows. (Use the L298N wiring diagram to figure out the motor pin numbers.):
    • Pin 1 – Left + Red
    • Pin 2 – Left – Black
    • Pin 3 – Right Black –
    • Pin 4 – Right Red +
  3. Connect the motor signal pins as follows:
    • IN1 to D7
    • IN2 to D6
    • IN3 to D3
    • IN4 to D4

Note: If you decide to use different pins, you’ll have to modify the source code.

Step 2 – Configure the Software

You’re going to need a copy of the Arduino IDE. So before we get started, download and install a copy of it here.

    1. Update the Arduino Board Manager. Go to Arduino >> Preferences and paste the following code in the “Additional Board Manager URLs” field.
       https://arduino.esp8266.com/stable/package_esp8266com_index.json
    2. Add the ESP8266 Library. Go to Sketch >> Include Library >> Manage Libraries >> then Search “ESP8266com” & install.
    3. Set your board WeMos D1 R2 & mini under Tools >> Start
    4. Change baud rate to 115200. Tools >> Upload Speed >> 115200

If you need additional help, check out the WeMos wiki for the WeMos D1 Mini.

Step 3 – Download the Arduino Sketch or Create Your Own

I’m not going to go in-depth on how to configure the software for this robot because the code is well commented on Github. You can access the code by signing in below. If you have specific questions or problems that you need help solving, please contact me!

Step 4 – Modify Sketch Parameters to work with your Network

If you choose to use my code, you’ll need to update a few parameters. Let’s go through that now.

Find this block of code:

// Replace with your network credentials
const char* ssid     = "yourssid";
const char* password = "yourpassword";
  1. Replace yourssid with your Wifi network name.
  2. Replace yourpassword with the Wifi network password.

Compile the code and be sure you don’t have any errors before proceeding.

Note: You may need to connect your WeMos to the computer using the Mini USB cable.

Step 5 – Test Drive

Here’s the moment of truth. Be sure your board is selected (Step 2 part 3) and the baud rate is set to 115200 (Step 2 part 4). Connect your WeMos to your computer via USB. Then upload the code like you usually would any other Arduino sketch.

Note: This code takes much longer to upload versus a typical Arduino Uno. BE PATIENT!

Once the code is done uploading, open up the Serial Monitor. Click the magnifying glass in the top right corner or navigate to Tools >> Serial Monitor.

You should see the following printout:

wemos wifi controlled robot using l298n

Copy the IP address (in my case it’s 192.168.2.107) and paste it into an Internet Browser. This is the webpage that is generated at that IP address.

It’s the moment of truth! Time to test out the connectivity. Make sure you prop your robot up if it is on a table, or it will go flying off. Once it’s propped up, feel free to click the control buttons to try out the RC features of this Wifi-enabled robot!

wemos wifi controlled robot using l298n

You can also unplug the USB cable from your computer, place the robot on the ground, and run your mobile robot off of batteries. The webpage will be active so long as your robot is 1) powered on and 2) connected to your home network/router.

Feel free to try out driving the robot from your wifi-connected smartphone or laptop browser page! Connectivity appears to be real-time, and it’s actually quite fun to drive around!

Step 6 – It works, now what?

This is actually a really good starting point for your Wifi-controlled robot projects. While I’m sure you’re creative and can think of at least 10 improvements, here are my top 5 recommendations for where to go with this:

  • Control the type of turn the robot makes. For example, make a 90-degree turn or 45-degree turn. Use either a text input box, form, or pre-programmed button to send commands to the robot.
  • Customize the Robot outputs to be visually appealing. Instead of printing out a text that says ON or OFF and a direction, find a way to visually represent this data on the screen.
  • Control the motor speed. You’ll probably have to remove the jumper pins on the L298N motor controller and utilize the analogWrite feature.
  • Host the webpage on a WWW website rather than your home network. Then call up a friend and have them drive your robot around from their house. I’m actually tempted to try this. I’ll keep you posted if I actually go through with it. 😉
  • Clean up the webpage by generating it in PHP or a separate HTML file. I’ve seen examples of using PHP and a CSV file to write and read values for commands. Might be something I look into for the future and ease of reusability for this code.

 

Subscribe to Learn Robotics on YouTube

What did you think of this tutorial? IMO, it’s been probably the coolest thing I’ve worked on as of late 😉

If you’d like to learn more about building mobile robots (and work with me 1-on-1), join my online Robotics course. It’s a 30-day guided crash course to give you the tools you need to be successful within robotics. Sign up here

Support Content Like This

You May Also Like

Have a question? Need Help?

Thanks for dropping by! Comments are no longer moderated daily.
Before posting your comment, please consider buying a coffee.
If you'd like to work with Liz, you can schedule a call here.

6 comments

  1. Great tutorial, unfortunately, the link to the wiring diagram -> https://smartmodules.ru/image/catalog/blogimg/pinout/wemos-d1-mini-pinout.png is not valid anymore. Would you mind updating the link?
    And the search for “ESP8266com” in the library manager returns no results.
    Thank you!

    1. Liz Miller

      Thanks for letting us know, Iwan. The link has been fixed. Good luck! ~Liz from Learn Robotics

  2. Cecil Moore

    Thank you for posting your video And I like your project I am doing one of my own using a wheelchair for a robot platform i have been looking all over for a code just like this thanks again

    1. Liz Miller

      You’re welcome Cecil! Your wheelchair robot project sounds like a lot of fun! Do share when you’re finished!

      1. Cecil Moore

        can I modify your code to give motor speed control ? If someone has done this already please let me know.
        Thanks again

        1. Liz Miller

          Cecil, absolutely. I’ve written a library for the Arduino Uno using the L298N, which you can find here. Feel free to leave a link to your Github with the updates, or fork the Create library and add your changes. Should be as easy as using analogWrite(…) for the Enable Pins… presuming that you’ve enabled both pins in your configuration. Let me know how it goes!

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Learn Robotics Botly Favicon

Become a Learn Robotics Insider

 

Be the first to know when we launch new robotics content. Plus gain FREE robotics tips to your inbox.

Awesome! Check your inbox for a surprise!

Remote Robotics Courses for High School, Middle School, or Pre-College Training

Join the Powered by Learn Robotics Program

Teach robotics anywhere with our turnkey robotics program!

Download our free program brochure!

Success! Check your email for the download!