Motors are what give robots the ability to move – to spin wheels, lift arms, or rotate sensors. In this section, we’ll explore how to connect and control basic DC motors using an Arduino board.
⚙️ Types of Motors Used in Robots
DC Motor – Spins in one direction or the other. Simple and fast.
Servo Motor – Rotates to a specific angle (0° to 180°). Great for precise control.
Stepper Motor – Moves in small steps. Used in CNC machines and printers.
🔌 Connecting a DC Motor to Arduino
You can't connect a DC motor directly to an Arduino. Why?
Motors need more current than Arduino can provide.
To reverse motor direction, we need a special circuit.
This is where a motor driver like the L298N or L293D comes in. It acts like a middleman that lets Arduino control the motor safely.
📦 Components Needed
1 x Arduino Uno
1 x L298N or L293D Motor Driver
2 x DC motors (like BO motors)
1 x External power source (battery or USB power bank)
Jumper wires
🔁 Controlling Motor Direction with Code
Here's a simple example of Arduino code to spin a DC motor in both directions using a motor driver: