Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagecpp
themeConfluence
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<ul><h3>Current / Power Issues</h3><p>The vast majority of the issues students face are power-related.&nbsp;A DC motor requires A LOT of current.</p><p>The current drawn increases significantly with the mechanical load. To reduce the mechanical load,&nbsp;</p><ul><li>Keep your robot light.</li><li>Use gear ratios that give high torque (usually at the expense of speed) where possible.</li><li>Make sure the driven wheels are properly aligned.</li><li>Lubricating the gearbox can help too.&nbsp;</li></ul><p>Another usual reason why you don't get sufficient current is bad batteries. 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. 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.&nbsp;The battery generally drains faster than you think it does, especially if the mechanical load is high. Adding more batteries in parallel (not series, assuming the overall voltage of the combination is at least 6 volts) can help with current, but they also add to the weight.&nbsp;</p><p>A third reason is that you are driving more motors from the same L293D output. L293D also has limits on the amount of current available from each output pin. Where possible, drive only one pin from each L293D output. The same control input from Arduino pin can be used as inputs to two different L293 inputs (assuming the motors are supposed to run at the same speed), as the current to run the motor isn't drawn from Arduino - however, be mindful of the fact that two motors might not be identical with respect to friction - one is likely to run faster than the other if you do so.&nbsp;</p><p>Caution: an overloaded L293D can heat up to 140<sup>o</sup> Celsius, so be careful.</p><p>Debugging tip: Write a simple program to turn the wheels without dependence on sensor (e.g. ultrasonic) readings. If it still doesn't work, lift the robot such that the wheels are not loaded. Sometimes, the wheel might need you to give it some help to overcome static friction.&nbsp;If the wheels eventually turn, it's a power-related issue.</p><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>