Motion
Common Motors in Hobby Electronics
Common Motors in Hobby Electronics
Embarking on the exciting world of electronics and robotics might seem like a daunting task, but fear not! Let's start by diving into the magical realm of motors – those cool gadgets that make things move. Among the motor superheroes are DC motors, stepper motors, and servomotors, each with its own special powers.
DC motors are like the speedsters of the motor world, while stepper motors are the precise step-counting wizards, and servomotors are the ultra-precise angle magicians. Guess what? We're going to team up with our trusty sidekick, Arduino, to learn how to control these motors and bring our creations to life. So, buckle up, future inventors, as we embark on this thrilling adventure into the world of motors and Arduino!
At the end of this you must be able to:
Understand the function of DC, stepper and servo motors and how they work
Use them in practical applications using an Arduino
Understand how to choose an appropriate motor for your application
Understand the concept of gears, gearing ratios and torque
Understanding the theory behind motor control sets the foundation for more advanced projects and opens the door to exploring diverse applications in robotics, automation, and beyond.
DC or Direct current motors are the most common motor in hobby electronics.
A DC motor operates on the principle of electromagnetism, where the interaction between a magnetic field and an electric current generates mechanical motion.
Inside a DC motor, there is a coil (armature) that carries the electric current and is placed within a magnetic field created by magnets or other coils (stator). The interaction of these magnetic fields results in the rotation of the motor's shaft.
L298 Motor Controller
Very popular motor driver to use with the Arduino to drive a DC motor.
In essence, a motor driver is a crucial component for translating the digital signals from the Arduino into the high-power actions required to drive a DC motor effectively. It ensures the safety of both the Arduino and the motor, preventing damage that might occur if the motor were connected directly to the Arduino pins.
Controlling a DC motor involves understanding the basic principles of how motors work and addressing the challenges associated with their operation.
When it comes to controlling a DC motor using an Arduino, a motor driver becomes essential. The reason for this lies in the need for a bridge between the low-power signals from the Arduino and the high-power requirements of the motor. Arduino pins provide relatively low current and voltage, which are insufficient to drive a motor directly. A motor driver acts as an interface between the Arduino and the motor, capable of handling higher current and voltage levels.
The motor driver, often in the form of an H-Bridge configuration, allows bidirectional control of the motor's rotation. An H-Bridge consists of four switches(normally in the form of transistors) that can be independently controlled to determine the direction of current flow through the motor. By controlling these switches appropriately, the motor can rotate forward or backward.
Additionally, the motor driver enables finer control over the motor's speed by modulating the amount of power delivered to the motor through a process called pulse width modulation (PWM).
For this exercise you'll need a few basic components and the ability to understand and manipulate electrical signals. Here's a simple guide to get you started using an Arduino, a popular microcontroller platform ( The above videos also explain it clearly):
Materials Needed:
DC Motor: Choose a motor suitable for your project, considering factors like voltage and torque requirements.
Arduino Board: A microcontroller that will serve as the brain of your project.
Motor Driver: An H-Bridge motor driver IC (Integrated Circuit) to control the direction and speed of the motor.
Power Supply: A power source (usually a battery or external power supply) matching the motor's voltage requirement.
Jumper Wires: To connect components.
Steps:
Understand Motor Wiring:
DC motors typically have two wires: positive (usually red) and negative (usually black). Polarity matters for the motor's rotation direction.
Connect the control pins of the motor driver to the Arduino. Common pins include Enable, Input 1, Input 2, for basic direction control.
Connect the Motor Driver: Use jumper wires to connect the motor driver to the Arduino. Connect the motor terminals to the motor driver output.
Power Supply Connection: Connect the power supply to the motor driver. Make sure the voltage matches the motor's requirements.
Arduino Code: Write a simple Arduino program to control the motor. The code will involve setting the direction and speed of the motor through the motor driver.
5. Upload the code to your Arduino, and you should see your DC motor spinning according to the specified direction and duration in the code.
6. Only you are sure you understand how the individual motor is controlled should you add the second motor.
7.If this is your robot. Create functions for rotate left, rotate right, forward, back, turn left and right.
L298N Motor Driver Pin Diagram, Working, Datasheet & Arduino Connection - This website explain how the motor driver works very well
Circuit:
So basically, each motor is controlled by three lines: Enable line (ENA or ENB,) that control the speed and the other two lines (IN1 and IN2 or IN3 and IN4) are for direction.
Remember to handle electrical components carefully and check specifications to prevent damage. Once you've mastered the basics, you can explore more advanced techniques like motor speed control and feedback systems. Happy experimenting!
A stepper motor is a type of DC electric motor that divides a full rotation into a number of equal steps. Unlike a regular DC motor that rotates continuously when power is applied, a stepper motor moves in discrete steps, making it ideal for applications requiring precise control of position and speed.
When the motor operates, electrical current flows through the stator's coils, generating a magnetic field. This magnetic field interacts with the rotor, causing it to move in small, controlled steps rather than spinning continuously like a traditional DC motor. The direction, speed, and position of the rotor are managed by the sequence and timing of electrical pulses sent to the stator coils.
Different Ways the Stepper Motor Can Move
Full-Step Mode: This is like taking big steps. The motor turns the rotor by a set amount each time, moving it from one electromagnet to the next. It’s simple and strong but not very smooth.
Half-Step Mode: Imagine taking medium steps. The motor moves the rotor halfway between two electromagnets before moving to the next one. This makes the movement smoother and doubles the number of steps the motor can take.
Microstepping: This is like taking tiny baby steps. The motor moves the rotor in very small increments, making the movement super smooth and precise. It’s perfect for tasks that need a lot of accuracy.
Where Stepper Motors Are Used
You’ll find stepper motors in cool gadgets like 3D printers, which build objects layer by layer, or in robots that need to move their arms very precisely. They’re also in cameras that smoothly move to capture perfect pictures or videos.
So, stepper motors are special motors that help things move in exact steps, making sure everything is done just right.
Follow this step-by-step tutorial that explains how you can use the L298 motor driver to rotate the stepper motor.
For this you only need:
Arduino Uno
Arduino C App
Download cable
Stepper motor (28BYJ-48 + ULN2003 also fine)
L298 Motor driver
One of my favorite projects involves making a stepper motor move without using Arduino libraries. This requires determining the step sequence for the specific motor. For this example, I will use the 28BYJ-48 stepper motor, which is readily available at most electronics stores. But you can any stepper motor, even the ones you salvage from an old printer.
Using half-step switching with a 28BYJ-48 stepper motor involves energizing the coils in a sequence that allows for smoother and more precise movement. This motor has four coils that are typically controlled using a ULN2003 driver. Here’s a step-by-step guide to implementing half-step switching:
Half-Step Sequence
In half-step mode, the motor steps through a sequence that includes both the full-step positions and the intermediate positions between them. The sequence is:
This sequence tells you which coil/s will be high. You can see only one is changing at a time.
Using these steps you can create your code. In this code I have created variables, as shown on the right, for each of the coils to link to their colour. This is to make the code more user friendly and understandable as this is the wire colours on this stepper motor. Variables for other types of stepper motors may be named differently.
This is an example of the first step:
The delay in the Arduino code is necessary to control the speed of the stepper motor and ensure it has enough time to properly move to each step, preventing missed steps and erratic movement.
After creating the sequence from step 1 to step 8, implement a function to move the motor forward through these steps, and then create another function to reverse the sequence from step 8 back to step 1 to change the motor's direction.
The video on the left has some interesting solutions but I found this solution on ChatGPT(😀). I haven't thought of this solution but it is really elegant, so try it. You start to set up a multi-dimensional array, then loop through the array in a defined order.
A servo motor is a small device that helps move things precisely to a specific position. It has a tiny motor inside, gears to make it stronger, and a sensor to know exactly where it is.
When you tell the servo motor where to go using a special signal, it compares its current position with the desired position and moves until it matches.
Servo motors are used in many cool things like robots, remote-controlled cars, drones and even in toys to make them move in exact ways.
A servo motor works by receiving a control signal, typically a Pulse Width Modulation (PWM) signal, which specifies the desired position.
Inside the servo motor, there is a small DC motor connected to a set of gears. These gears reduce the motor's speed and increase its torque, allowing for precise movement. Attached to the output shaft is a potentiometer, a type of position sensor, which measures the current position of the shaft and sends this information to an internal control circuit.
The control circuit compares the current position with the desired position from the PWM signal. If there is a difference, it generates an error signal, which adjusts the motor's speed and direction to move the output shaft to the correct position. This feedback loop allows the servo motor to achieve and maintain precise positions.
Challenge:
Design a circuit and create code that move the servo motor position based on an input from the serial monitor or other.
Connect the Servo Motor to the Arduino:
Connect the GND (usually black or brown) wire of the servo motor to the GND pin on the Arduino.
Connect the VCC (usually red) wire of the servo motor to the 5V pin on the Arduino.
Connect the Signal (usually yellow, orange, or white) wire of the servo motor to a PWM-capable digital pin on the Arduino (e.g., pin 9).
Install the Servo Library:
Open the Arduino IDE.
Go to Sketch > Include Library > Manage Libraries...
Search for "Servo" and install the Servo library if it is not already installed.
Write the Arduino Code:
Open a new sketch in the Arduino IDE.
Include the Servo library at the beginning of the code.
#include <Servo.h>
Create a servo object. Servo myServo; // Create a servo object
Attach the servo object to the desired digital pin within setup loop
myServo.attach(9); // Attach the servo to pin 9
Use the write() function to set the position of the servo motor. myServo.write(90); // Move the servo to 90 degrees. The position can be anything between 0 and 180deg
Controlling a servo motor without using the Arduino Servo library involves directly manipulating the PWM (Pulse Width Modulation) signals that the servo motor understands.
How It Works
Pulse Width Modulation (PWM): Servo motors interpret the duration of a high pulse sent to their control pin to determine the position to which they should move. Typically, a pulse width between 1 ms (0 degrees) and 2 ms (180 degrees) is used.
Timing Explanation:
Sending a high signal for 1.5 ms moves the servo to 0 degrees.
Sending a high signal for 2.0 ms moves the servo to 90 degrees.
Sending a high signal for 2.5 ms moves the servo to 180 degrees.
Precision: Adjusting the duration of the high signal (pulse width) allows precise control over the servo's position.
By directly controlling the pulse width with digitalWrite() and delayMicroseconds(), you can achieve servo motor control without relying on the Arduino Servo library, providing a deeper understanding of how servo motors interpret control signals.
Now that we've explored how motors work, let's turn our attention to gears, which are essential partners in enhancing motor performance. Gears act as mechanical intermediaries between the motor and the driven components, allowing us to control how fast things move, how much force is applied, and even change the direction of motion.
The motor, known as the driver, turns one gear (or gear set), which in turn rotates another gear connected to the driven component. By combining different types of gears—like spur gears for straightforward power transfer or worm gears for precise control—with motors, we can make machines more efficient and versatile.
Learning about gears is not just about understanding mechanics; it's about gaining the skills to design and optimise systems that drive everything from cars and bikes to robots and industrial machinery. This knowledge empowers us to innovate and solve real-world engineering challenges effectively.
Gears are like magic wheels that help machines move and do work. Imagine you have two round discs with teeth around the edges. When you connect these discs so their teeth fit together, they form what we call gears.
Now, here’s the cool part: when you turn one gear, the teeth push against the teeth of the other gear. This makes the second gear also turn, but maybe faster or slower depending on the sizes of the gears and how they fit together. This is how gears help us control speed and power in machines.
What Gears Do:
Speed Up or Slow Down: Gears can make things go faster or slower. If a small gear turns a big gear, the big one goes slower but has more power. Think of how your bike works when you change gears.
Change Direction: Some gears can make things turn in different directions. This is handy for machines that need to turn around or go up and down.
Transfer Power: Gears help machines like cars and clocks take power from the engine or spring and make things move smoothly and reliably.
Understanding gears helps engineers design better machines that work efficiently and reliably.
Types of Gears:
Spur Gears: These are like regular circles with teeth straight across. They’re simple and used in things like bikes and toys.
Helical Gears: These gears have angled teeth, so they run more smoothly and quietly. You’ll find them in cars and machines that need to work quietly.
Bevel Gears: These are like gears for changing direction. They have teeth cut on an angle, so they can turn corners in machines like hand drills.
Worm Gears: These gears look like a screw and a wheel meshed together. They’re super strong and used in heavy machines like lifts and cranes.
Gears are everywhere around us, from the gears in a watch that make the hands move, to the gears in a car that help it go fast or slow.
These videos go into detail if you are interested in how they work and how they are designed.
In this hands-on activity, students will explore the principles of mechanical gears using a box of spur gears. To begin, gather spur gears of various sizes, axles or shafts for mounting, and a base or board for assembly.
Start by selecting a large gear as the driving gear and secure it onto an axle. Connect additional gears to form a gear train, ensuring that teeth mesh correctly.
Experiment with different gear configurations to observe how size affects rotational speed and torque.
This activity encourages students to understand gear ratios and mechanical advantage through practical application. It's an ideal project for fostering teamwork, problem-solving skills, and a deeper appreciation for mechanical engineering concepts.
For an advanced challenge, use Fusion 360 or similar, where students can design custom spur gears by specifying parameters such as number of teeth, pitch, and diameter.
This dual approach allows students to not only explore gear mechanics practically but also to engage in digital fabrication by creating and 3D printing their custom gear designs.
Through this hands-on project, students will develop critical thinking, problem-solving skills, and a deeper understanding of mechanical engineering concepts, making it an ideal STEM activity for high school classrooms.