Skip to content
Learnearn.uk » Home » Topic 3 – DC Motors & Servo Motors

Topic 3 – DC Motors & Servo Motors

DC Motors

Controlling a DC Motor

A DC 6V hobby motor is a type of direct current motor commonly used in hobbyist and DIY projects. These motors are popular among hobbyists due to their simplicity, affordability, and versatility.

Hobby motors can be controlled using various methods, including adjusting the voltage applied to the motor, using PWM (Pulse Width Modulation) signals.

Hobby motors are commonly used to drive wheels, propellers, and other moving parts in RC cars, boats, airplanes, and drones.

6V Motor with wheel

Lego DC Servo Motor

 

 

 

 

 

 

 

 

Single Motor

Controlling a Single Motor

Wiring Diagram

This is the wiring diagram for both DC Motors and Servo Motors for a single motor.

Click to enlarge

Test Code

The code below alternates which Pin is high (either pin o or pin 1). This has the effect of reversing the current, which reverses the direction of rotation of the motor.

Two Motors

Controlling two motors

You can control two motors with a single motor control board. You simply wiring the the other motor to the opposite side and wiring the two more signal wires in from Pin 2 and Pin 8

Two Motor Test Code

 

 

Pulse Width Modulation

Pulse Width Modulation

Pulse Width Modulation (PWM) is a modulation technique used to control the analog output voltage of a digital circuit by varying the duty cycle of a rectangular waveform. PWM is widely used in electronics and electrical engineering for applications such as motor speed control, LED dimming, audio signal generation, and power regulation.

Basic Principle

PWM works by rapidly switching a digital signal between ON and OFF states at a fixed frequency. The percentage of time the signal is in the ON state (called the duty cycle) determines the average voltage or power delivered to the load.

Duty Cycle

The duty cycle is the ratio of the ON time to the total period of the waveform. It is usually expressed as a percentage. For example, a duty cycle of 50% means that the signal is ON for half of the period and OFF for the other half.

Example PWM Code for a 25% duty cycle:

You can achieve the above automatically by using the analog write out block, which allows a duty cycle from 0 (0%) to 1023 (100%)

Frequency

PWM signals have a fixed frequency, which determines how often the signal repeats within a given time period. Common PWM frequencies range from a few hundred Hertz to several kilohertz or even megahertz, depending on the application requirements.

Simulation


Simluation

Resources