Home > Industry Insights >Servo
TECHNICAL SUPPORT

Product Support

Arduino Motor Control Tutorial Teaches You Step By Step From Wiring To Code

Published 2026-02-23

Want to control a motor, but looking at a bunch of pins and codes and don't know where to start? Don’t worry, this is a hurdle that almost every novice maker encounters. In fact, as long as you clarify your thinking, this matter is simpler than you think. Today we will dismantle this problem together and solve it step by step.

How to choose a suitable motor

Facing DC motors, stepper motors, andservos, novices can easily be confused. These types of motors have completely different temperaments and temperaments. If you choose the wrong one, no matter how well you write the code, it will be in vain. DC motors are the simplest and can turn when powered on, so they are suitable for car tires. As forservos, they can accurately turn to specified angles and are suitable for use as robotic arm joints. Stepper motors can accurately turn round and round, making them most suitable for use in 3D printers. What projects are you working on? First think about whether you need it to rotate all the way or to a specific position, so you can quickly lock the motor type.

What driver module should I use to avoid burning the board?

The current of the board itself is very small. If you directly connect the motor to it, the chip will burn out in all likelihood. This is like asking a small horse to pull a large cart. It will definitely not be able to pull it and will hurt your body. Therefore, a driver module must be added in the middle as a "bridge". For DC motors, L298N or L293D are common choices; controlling theservois the simplest, just plug it directly into the 5V and signal pins; stepper motors are usually equipped with an A4988 drive module. When buying a module, pay attention to the parameters to make sure it can withstand the voltage and current of your motor.

How to connect the lines correctly

Wiring is the most troublesome step, and it’s easy to feel intimidated when looking at the densely packed pins. In fact, don't panic, let's do it step by step: first connect it to the computer via USB and operate it in a power-off state. ️ 1. Power cord: The positive and negative poles of the power supply of the drive module are connected to the motor and external battery respectively (do not draw power from them). ️ 2. Signal line: Connect the IN1 and IN2 pins of the driver module to the digital pins, such as D9 and D10 respectively. ️ 3. Common ground: This step is very critical. You must connect the GND of the driver module and the GND of the driver module together so that they can "speak the same language".

How to write sample code

Just connect the wires without writing code, the motor is just a decoration. Let’s take the simplest DC motor as an example. You can open the IDE, create a new file, and enter these lines: define two pins, such as int enA = 9; int in1 = 8;. Set all pins in setup(). In loop(), use (in1, HIGH); to make the motor rotate, and use (enA, 150); to adjust the speed (value 0-255). If you want to stop, just (in1, LOW);. The amount of code is not large, each sentence has a clear function, and you will be familiar with it after typing it a few times.

What should I do if the motor does not rotate?

When you plug it in and find that the motor doesn't move at all, it's normal. Don't be quick to doubt your life. Check the three most basic things first: Is the power on? Is the battery charged? Are the wiring loose? Eighty percent of the problem lies here. If there is no problem with the power supply, the pin numbers in the code are different from the ones you actually connected. It is easy to get confused here. Not yet? Unplug the signal cable of the drive module and touch the signal terminal with your finger. If the motor responds a little, it means that the drive and motor are good, and the problem must be in the code or something. If you investigate in this order, you can quickly find the culprit.

Where can I find more ways to advance?

Learn the basics of forward and reverse and speed adjustment, and your creative journey has just begun. Want to make your car run? Search for "Bluetooth controlled car" and there are a lot of tutorials. Want to make a robotic arm? Search for "servo control robotic arm" and you can find the code and drawings. Don't just work on it alone, the major maker forums are full of open source projects and enthusiastic netizens. 99% of the problems you encounter have been encountered by others. Search more and read more, combine your ideas with the wisdom of others, and you will soon be able to produce a decent work.

Okay, after talking so much, I wonder if you have a small idea recently and are thinking about using a motor to realize it? Chat about your thoughts in the comment area. Maybe others can give you some advice. Just give it a like and share it so that more friends can join in the fun.

Update Time:2026-02-23

Powering The Future

Contact Kpower's product specialist to recommend suitable motor or gearbox for your product.

Mail to Kpower
Submit Inquiry
WhatsApp Message
+86 0769 8399 3238
 
kpowerMap