• Skip to main content
  • Skip to header right navigation
  • Skip to site footer
  • YouTube
  • MakerWorld
  • Instagram
  • Threads
  • Bluesky
  • Mastodon
  • Facebook
makerhacks-logo

Maker Hacks

Ideas, news & tutorials for makers and hackers – Arduino/Raspberry Pi, 3D printing, robotics, laser cutting, and more

  • Home
  • About
  • 3D Printing
  • Laser Cutting
  • CNC
  • Programming
  • Free Arduino Course
  • Free Robotics Course
  • Recommendations

Basic DC Motor Movement

You are here: Home / Robotics Course / Basic DC Motor Movement
Wire power and ground and watch it move

As mentioned elsewhere, DC motors are pretty simple. Get four AA batteries in a battery case, then connect the terminals to the + and – of the motor, and watch it move!

A really tiny motor can be pulsed straight from a microcontroller pin, as in the example below, but treat it as a demonstration rather than a habit. Every real motor in this course goes through a driver.

Driving a Tiny Motor

I have some tiny, tiny brushed motors that were intended for a miniature drone. They are powered at 3v and draw very little, plus I have spare Arduinos if I fry my board, so let’s try the most simple microcontroller controlled motor driving circuit!

Check your board first. An Arduino Uno R3 pin is happiest at 20mA (40mA is the absolute maximum, not a target), and the newer Uno R4 is rated at only 8mA per pin, so on an R4 skip this example and go straight to the driver lessons. Motors also kick back voltage spikes when they switch off, which is why the proper way is a transistor plus a flyback diode, or a motor driver board, as we do next.

(The video that went with this lesson is no longer available.)

PWM pulses visualized

We wire up our tiny motor to GND (Ground) and a PWM pin (marked with a ‘~’). PWM stands for Pulse Width Modulation and basically means we are going to “pulse” the motor on and off at a set rate using analogWrite(). You can think of it as being “pseudo-analog” because we are outputting on/off very, very quickly to give the effect of analog without it actually being analog :)

The faster and more often you turn your pin on, the faster the motor will run. This means we can easily control the speed of our tiny motor without anything more than our Arduino, a couple of wires, and the motor itself.

If you are worried about frying your stuff, or in any doubt about the power requirements of your motor, try a later example. This is just to show you the basics before moving on to more advanced (and safer for your equipment) examples. 

Serial Monitor settings: in the Arduino IDE, open the Serial Monitor, set the speed to 115200 baud and the line ending to “Carriage return”, then type a speed from 0 to 255, such as 150, and press Enter.

/*
 In this example we pulse a tiny motor.
 We can only do this safely because it IS tiny!
 If in doubt, follow one of the later examples. 
 You do not want to fry your kit.
 The analogWrite() function outputs PWM, 
 A PWM pin is usually marked with a '~'
 We are using pin 9 for this example.
 */

int pin = 9;           // the PWM pin the motor is attached to
int power = 0;         // how much power to send


// set things up ...
void setup() {

  // start the serial connection
  Serial.begin(115200);

  // declare pin 9 to be an output:
  pinMode(pin, OUTPUT);
}

// keep doing this forever:
void loop() {

  // play with the power setting to see
  // the effects
  while (Serial.available() > 0) {

    // look for the next power number in the serial monitor
    // turn it into an integer and place in our power var:
    int power = Serial.parseInt();
 
    // look for the carriage return (Enter)
    if (Serial.read() == '\r') {

        // report back the number we were provided:
        Serial.print(power);

        // output text to say we got it
        Serial.println(" - Roger!");
        
        // set the power of pin 9:
        analogWrite(pin, power);  

    }
  }
}
Previous IntroductionCourse contentsNext Forward and Reverse with Servos

Robot Course Lessons

  • Introduction
  • Choosing a Brain for your robot
  • Motors and Actuators
  • Basic Motor Controllers
  • Sensors
  • Breadboards, Batteries, Chassis, Wheels and Wires
  • Introduction
  • Basic DC Motor Movement
  • Forward and Reverse with Servos
  • Controlling DC Motors with the L293D H-Bridge Chip
  • Using Motor Drivers, Shields and Breakouts
  • Stepper Drivers
  • L298N Breakouts
  • Changing Direction with Tank Turning – L298n Breakout and Two Motors
  • Infrared Sensor
  • IR Remote Control
  • Robot Chassis
Creative Commons Attribution-ShareAlike 4.0 licence

Free to use, adapt and share. This course by Chris Garrett, Maker Hacks, is licensed under Creative Commons Attribution-ShareAlike 4.0. Workshops, schools and clubs are welcome to use it, including in your own handouts and sessions. Just credit “Chris Garrett, Maker Hacks (makerhacks.com)” with a link to the lesson, and share any adapted versions under the same licence. Embedded videos and other people’s content keep their own terms.

Improved a lesson or spotted a mistake? I would love to hear about it: get in touch.

  • 3D Printing
  • CNC
  • Electronics and Hardware
  • Laser Cutting
  • News and Reviews
  • Software and Programming

arduino budget cad cnc diode laser glowforge Hacks Ideas laser cutter linux Makes making python raspberry pi resin Reviews technology tips xTool Lasers

  • YouTube
  • MakerWorld
  • Instagram
  • Threads
  • Bluesky
  • Mastodon
  • Facebook

.

Maker Hacks Blog Copyright © 2026 · All Rights Reserved · Privacy Policy