CONTROLLING DC MOTOR USING RASPBERRY PI

CONTROLLING DC MOTOR USING RASPBERRY PI

WHAT IS DC MOTOR?

If you are an electronics hobbyist and like to make robots then you must be familiar with motors and its type. DC motors are the commonly used motors in commercial as well as industrial projects. So what is DC Motor?
DC motor is an electronic device which uses DC current to convert electrical energy into mechanical energy.

DC Motor

Working Principle of DC motor

The DC motor consists of two electrical components, the armature and the field winding's. The armature winding's are made of conductors that terminate at a commutator.
The voltage provided to the armature is given by the carbon brushes which ride on the commutator. In the small DC motors, the stator is made of permanent magnets whereas in large motors the stator is an electromagnet.
When the current passes through the coil in a magnetic field, a magnetic force will come into existence and torque will be produced in the DC motor. Whenever a current-carrying conductor is placed in a magnetic field it will experience a mechanical force.
DC Motor
DC motor consists of :

  1. Commutator
  2. Armature Winding
  3. Stator
  4. Rotor
  5. Air Gap

DC motor consisting

Types of DC Motors:

  1. Self- excited motor
  • Series wound motor ( field winding is connected in series with the armature)
  • Shunt-wound motor ( field winding is connected in parallel with the armature)
  • Compound wound motor-
             a. Long Shunt

             b.Short Shunt

  1. Separately excited motor ( field winding is fed by an external source)
  2. Permanent Magnet motor

SELF EXCITED DC MOTOR

In self-excited DC motor, there is no need for any external supply to the field and armature winding. The field winding of the motor is either connected in series or in parallel or partly in parallel, partly in series to the armature winding.

Shunt Wound Self Excited DC Motor
Shunt Wound Self Excited DC MotorIn shunt wound DC motor, the field winding's are connected in parallel to the armature winding.

Series Wound Self Excited DC Motor
Series Wound Self Excited DC Motor
In series wound DC motor, the armature current passes through the field winding as it is connected in series to the armature winding.

Compound Wound Self Excited DC Motor
Compound Wound Self Excited DC Motor
In compound wound DC motor, the field winding connected both in series and in parallel to the armature winding.

SEPARATELY EXCITED DC MOTOR
SEPARATELY EXCITED DC MOTOR
In separately excited DC motor, the armature current does not flow through the field winding's.

PERMANENT MAGNET DC MOTOR
PERMANENT MAGNET DC MOTOR
In permanent magnet DC motor, there is armature winding but it is not necessary to have the field winding. In this motor, radially magnetized permanent magnets are mounted on the inner side of the stator core to produce the field flux.

The power required by the motor is quite high which the micro-controller can’t draw. The max. current that the pins can draw is 1500mA but is not enough and the motor requires 10 times of this current. The problem can be solved by adding an external IC which can handle all the power issues.
Another issue is there when the stator coil changes current a spike occurs which can cause damage to your micro-controller pins. Therefore we need an IC driver with an internal H bridge to resolve such issues. Also for changing the polarity of the stator poles in the process of reversing the current depends on the H bridge only. The commonly used H bridge IC used for motor interfacing is L293D. We are using here a motor shield with two L293DD( 20 pins) IC for the motor interfacing.

MOTOR SHIELD
MOTOR SHIELD
To control the DC motors through Raspberry Pi we require motor drivers or motor-shields. The driver/shield provides the motor with the necessary power to the motors for smooth operations and actions.

The current requirement for motors is high, even the 5V motor draws 300-400mA current initially. After the motor gains speed the current reduces to 150-200mA. This is a huge current to bear for our micro-controllers so never directly connect your motor to any micro-controller it will cause damage to it.
The solution to this is a motor driver/ motor driver. These are the circuits which provide the Raspberry Pi with the necessary drive current to run the motors.

We are going to use a Motor-shield which is based on the L293DD IC and is capable of driving 4 independent DC motors or 2 Stepper Motors. L293DD is a dual full-bridge driver that can output up to 1Amp per bridge with a voltage up to 24V.

  • Features: Dual H-Bridge IC L293DD.
  • Motor Input Supply Range: 6V – 24V.
  • Single Motor Output Current: 600mA or 1A peak per channel.
  • On board Arrow Indicator for motor direction indication.
  • 2 IR sensor connectors with 3.3V level output protection.
  • 1 Ultrasonic sensor connector with 3.3V level output protection.

Mounting the Motor-shield
Mounting the Motor-shield
To attach the Motor-shield to the Raspberry Pi, simply push the GPIO pin connectors on the underside of the Motor-shield onto the GPIO pins of the Raspberry Pi. Be careful to ensure that all of the pins are correctly seated and the Motorshield over-lays the Raspberry Pi.

Powering your Motor-shield

The motor-shield can draw power from the Raspberry Pi but not enough to power motors when loaded with the chassis of your robot. For testing your robot program however the Pi can provide enough to power the LEDs. To provide power for 4 motors you will need a supply of 7v to 12v with at least 1500mAH. For 2 motors power requirements are obviously less and you can use 4 x AA batteries, although these will drain quickly.

Connecting motors to the shield

Connect each motor to a single pair of labelled motor terminals on the Motor-shield (one terminal of the motor to one terminal on the Motor-shield).

CONNECTION

I. Add the shield on the Raspberry Pi and make sure the shield placement is correct. Wrong connections can damage your Pi and Shield both. Place the female headers of Motor-shield into the male header of Raspberry Pi.

II. Set up the power connection, power your motor-shield with a supply power of range
6V-24V. There are two ways to give the power to shield through the power header or via. screw power terminal. After connecting all the device switch on the power supply.

III.Now connect your DC motors to the motor terminals of the shield. At a time you can connect 4 DC motors.

IV.After the circuit setup, comes time to program your motor-shield. You can also use our test programs for motors. Follow these steps :

  1. Open your Raspberry Pi Terminal and clone the code by writing: git clone https://github.com/sbcshop/MotorShield.git
  2. Your code will be downloaded to '/home/pi' directory.
  3. Go to directory 'MotorShield' and open 'Test_Motor.py' with Python 3 IDLE.
  4. Run (Press F5) file 'Test_Motor.py'. This is the example code to run all the motors in 'Forward' and 'Backward' direction.

CONTROLLING DC MOTOR USING RASPBERRY PI

Hope you enjoyed reading this article.

Buy Motorshield for the Raspberry Pi

Also, check out Raspberry Pi Cases Collection

Serial Servo Motor

RELATED ARTICLES

Leave a comment

Your email address will not be published. Required fields are marked *

Please note, comments must be approved before they are published