Basic Principle
- If an electric charge moves, it generates its own magnetic field, which interacts with the original field (from permanent magnets)
- Hence, a magnetic field exerts a force on a moving electric charge
- A DC motor uses a permanent magnet to exert a force on a current-carrying coil of wire
- The direction in which the coil of wire moves can be found using Fleming’s left hand rule
- Easy DIY DC Motor https://www.youtube.com/watch?v=DsZCW34LktU
- DC motors are used in applications which require good energy efficiency, but only imprecise control. Control, if necessary, has to be achieved through some external control mechanism
- Used in fans, drills, traction etc.
Here is a good interactive tutorial on DC motors - https://nationalmaglab.org/education/magnet-academy/watch-play/interactive/dc-motor
Torque and Speed
- The equivalent of force for rotation is called Torque
- Higher torque applied to the wheel = better ability to overcome obstacles / friction, climb up a slope etc.
- Usual DC motors run at very high rpm, but produces very low torque – typically not enough to run a robot
- We use gears to increase the torque, but this comes at the expense of speed
- Torque x rotational speed = power drawn by the motor
- Power drawn by the motor depends on the a number of factors, the most important being the duty cycle (in PWM)
- Duty cycle can be controlled using analogWrite()
Motor Driver
- An Arduino pin can deliver only ~40mA current.
- DC motors like the one we use draw several 100s of mA when loaded.
- We need a switch/ current amplifier to drive the motor based on the signals from the Arduino.
- Arduino -> Driver -> Motor.
- A motor driver allowing bidirectional drive is called an H-bridge
- L293D is a popular motor driver.
- L293D has 4 switches. This can be used to drive 4 motors unidirectionally or 2 motors bidirectionally
- Note that the enables for inputs 1 & 2 are combined (you probably won’t need it, but enable should be high for the PWM signal from Arduino to have any effect). Ditto for enables of inputs 3 & 4
- L293D has diodes are already connected inside the chip and need not be connected externally
Image courtesy : https://www.ti.com/lit/ds/symlink/l293.pdf
Pin Number | Pin Function | Description |
1 | Enable 1,2 | This pin enables the input pin Input 1(2) and Input 2(7). Usually connected to 5V of Arduino; can also be controlled from your program by connecting it to an Arduino digital output pin. |
2 | Input 1 | PWM control for Output 1 pin. From an Arduino pin supporting analogWrite() |
3 | Output 1 | Connected to one end of Motor 1 |
4 | Ground | Ground pins are connected to ground of circuit (0V) |
8 | Vcc2 (Vs) | Connected to the power source for running motors (4.5V to 36V) |
16 | Vcc1 (Vss) | Connected to +5V of Arduino to enable IC function |
Unidirectional Control
void setup() { pinMode(6, OUTPUT); } void loop() { analogWrite(6, speed); delay(10); } /* speed is between 0 and 255 depending on the desired speed / power */]] ></ac:plain-text-body></ac:structured-macro><h3>Bidirectional Control</h3><p><strong><ac:image ac:height="250"><ri:attachment ri:filename="image2019-12-28_18-35-2.png" /></ac:image></strong></p><ac:structured-macro ac:name="code" ac:schema-version="1" ac:macro-id="bc9bf6fb-2d06-4970-a24e-1df4b8108b2f"><ac:parameter ac:name="language">cpp</ac:parameter><ac:parameter ac:name="theme">Confluence</ac:parameter><ac:plain-text-body><![CDATA[void setup() { pinMode(5, OUTPUT); pinMode(6, OUTPUT); } void loop() { analogWrite(5, dir2speed); analogWrite(6, dir1speed); delay(10); } /*dir1speed and dir2speed should be between 0 and 255. Effective speed will be (dir1speed-dir2speed). For rotation in direction 1, dir1speed is set to the desired speed and dir2speed is set to 0 (and vice versa) */]] ></ac:plain-text-body></ac:structured-macro><h3>DC Motor with Battery</h3><p><strong><ac:image ac:height="250"><ri:attachment ri:filename="image2019-12-28_18-36-12.png" /></ac:image></strong></p><ul><li>It is better to power the motor directly from the battery rather than the 5V terminal of the Arduino.</li><li>The Arduino 5V pin might not be able to give sufficient current.</li><li>Pin 8 of L293D is connected directly to the +ve of the battery.</li><li>Here, Arduino board is purely a controller for the motor, and does not power it.</li><li>The -ve of the battery and GND of the Arduino have to be connected together.</li><li>The battery can also power the Arduino, allowing it to operate without the USB connection to the computer. Simply connect the +ve of the battery to Vin.<ul><li>Omit this connection when Arduino is connected to computer via the USB cable. Note that the GND and the -ve of the battery should be connected in any case.</li></ul></li></ul><h3>Screencast</h3><p><ac:structured-macro ac:name="widget" ac:schema-version="1" ac:macro-id="68672be6-2cb9-47e3-8fcf-b365b2f0d95e"><ac:parameter ac:name="url"><ri:url ri:value="http://youtube.com/watch?v=pIoBLng4Yno" /></ac:parameter></ac:structured-macro></p><p><br /></p>