Skip to content

10. OutPut

Week 10: Output Devices — DC Motor Control

Overview

I chose to explore output devices by working with a DC motor. Since my final project involves two motors to propel a robot forward, I thought it would be good to start messing with basic motor movement this week.

Group work

My group of Andrew, Cooper, and Noah tested the power drawing of an LED. We used a multimeter which showed that the LED drew 15 miliamps. This was a very quick group work week. Click here to get to the site.

Getting Started

At first, I thought making a motor move would be simple all I needed was to just give it power and let it run. But then I realized that this plan would most definitely not work. After some research, including reviewing FabAcademy documentation from past students, I learned I needed a motor driver to safely and efficiently control the motor. In my fab lab I found a selection of small DC motors and saw that we had both the full-size and mini version of the L298N motor driver. This was perfect for basic DC motor control. Since I didn’t need speed control yet, I focused on just making the motors go forwards and backwards.

Prototyping on a Breadboard

I began by wiring everything on a breadboard. I connected:

  • Power and ground to the motor driver
  • GPIO2 connected to L298N IN1
  • GPIO3 connected to L298N IN2
  • Two output pins from the motor driver to the motor’s ports

With this simple setup, I was able to make the motor spin in both directions. However with no control over speed it was always spinning fastest it could go. This meant I could not run it long.

Code

#include <Arduino.h>

#define IN1_PIN 2
#define IN2_PIN 3

void setup() {
  Serial.begin(115200);

  pinMode(IN1_PIN, OUTPUT);
  pinMode(IN2_PIN, OUTPUT);

  // Stop initially
  digitalWrite(IN1_PIN, LOW);
  digitalWrite(IN2_PIN, LOW);
}

void loop() {
  // Forward
  Serial.println("Moving forward...");
  digitalWrite(IN1_PIN, HIGH);
  digitalWrite(IN2_PIN, LOW);
  delay(4000);

  // Stop briefly
  digitalWrite(IN1_PIN, LOW);
  digitalWrite(IN2_PIN, LOW);
  delay(500);

  // Backward
  Serial.println("Moving backward...");
  digitalWrite(IN1_PIN, LOW);
  digitalWrite(IN2_PIN, HIGH);
  delay(4000);

  // Stop briefly
  digitalWrite(IN1_PIN, LOW);
  digitalWrite(IN2_PIN, LOW);
  delay(500);
}

Designing the PCB

Click here for files.

Once the breadboard test worked, I moved on to designing a custom PCB. It had:

  • A breadboard footprint for the ESP32-S3 Xiao
  • A custom pinout for the mini L298N motor driver

Unfortunately, I couldn’t find a footprint or datasheet for the mini version of the L298N , so I had to create one manually using measurements. I put the header pins in pairs, but my spacing was wrong. After some adjustments post milling though it worked.

And I did have one failed board that I had destroyed really horribly because of some bad soldering

Milling and Testing

After milling the PCB, I soldered the components and tested the circuit. It worked perfectly. Seeing the motor spin from my custom board was very nice.

Reflection

This was a really fun week. I’ve always loved making things move, kinda like bringing something to life. Even though this was simple, this week is a solid foundation for more advanced motor control. Soon, I’d like to use joystick control, whether real or virtual, and eventually use it with my final project.


Last update: June 3, 2025