
Checking the battery voltage when unloaded using a voltmeter or checking if the battery can power an LED isn't good enough - that doesn't guarantee the current delivered is good. The battery generally drains faster than you think it does, especially if the mechanical load is high. A battery that shows good voltage in isolation (i.e., when not loaded) doesn't necessarily deliver a good current - the voltage drops significantly when you try to draw more current.

Here, Arduino board is purely a controller for the motor, and does not power it.Pin 8 of L293D is connected directly to the +ve of the battery.The Arduino 5V pin might not be able to give sufficient current.It is better to power the motor directly from the battery rather than the 5V terminal of the Arduino.Effective speed will be (dir1speed-dir2speed).įor rotation in direction 1, dir1speed is set to the desired speed and dir2speed is set to 0 (and vice versa) */ DC Motor with Battery *dir1speed and dir2speed should be between 0 and 255. L293D has freewheeling/flyback diodes already connected inside the chip and need not be connected externally.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).This can be used to drive 4 motors unidirectionally or 2 motors bidirectionally L293D has 4 switches (half H-bridges).
#Two dc motors arduino code driver
A motor driver allowing bidirectional drive is called an H-bridge.We need a switch/ current amplifier to drive the motor based on the signals from the Arduino.DC motors like the one we use draw several 100s of mA when loaded.An Arduino pin can deliver only ~40mA current.Duty cycle can be controlled using analogWrite().

Power drawn by the motor depends on the a number of factors, the most important being the duty cycle (in PWM).Torque x rotational speed = power drawn by the motor.We use gears to increase the torque, but this comes at the expense of speed.Usual DC motors run at very high rpm, but produces very low torque – typically not enough to run a robot.Higher torque applied to the wheel = better ability to overcome obstacles / friction, climb up a slope etc.The equivalent of force for rotation is called Torque.Here is a good interactive tutorial on DC motors - Torque and Speed Control, if necessary, has to be achieved through some external control mechanism DC motors are used in applications which require good energy efficiency, but only imprecise control.The direction in which the coil of wire moves can be found using Fleming’s left hand rule.

