Power Upgrade

Who wants to drive a slow car?  Lets soop it up.

To do before buying anything:

  • Maximum voltage and current for the Ardumoto shield
    • Based on this schematic, max voltage is 18V
    • Recommended voltage is 7-12V, otherwise the voltage regulator could overheat
  • Power requirements for the motors:
    • 4.5V and 2A max

Now buying the batteries:

  • I wanted to go with 18650 Lithium Phosphate cells because they can deliver a lot of power (20A continuous), are relatively high capacity (2600mAh), come with built-in protection (safer!) and many off the shelf cylindrical battery chargers will accept them.
    • Looking around, amazon was selling LG cells (yay LG).  Since I spend my days watching videos of LG cells go through a battery of tests (…ha!), I know these are some of the safest cells on the market.  Since I’m not using any sort of battery management system (yet), safety could be a concern.
    • I noticed there are some battery manufacturers which are getting ripped off by Chinese counterfeiters.  This guy actually tested the capacity of the cells against their claims and rated them in terms of warranty.  LG cells were the only ones who passed.
  • Picked up a battery charger as well.  It accepts almost all cylindrical format consumer battery cell.
  • Of course I needed a battery holder to connect these cells in series.  I’ll have 1 extra cell just in case.
  • And finally I’ll need a power jack so I can plug into the Arduino.  Surprisingly this took me the longest to choose.  I was originally was going to go with something similar to what I have, but figured modularity is always best so I went with cheaper screw terminals instead.
  • In total this cost me $50.  This is becoming an expensive hobby…

Power Upgrade Time!

The batteries came individually packed in the mail.  They look about the size of shotgun shells.

IMG_20160327_172911

I loaded 3 of these in series into a battery holder, and attached the screw terminals.  After plugging it into the Arduino power sound, I added some new code (see bottom) which I modified to be a more WASD friendly.  Here is the work in process.

 

#include
SoftwareSerial BT(4, 5);
// creates a “virtual” serial port/UART
// connect BT module TX to D4
// connect BT module RX to D5
// connect BT Vcc to 5V, GND to GND

// Clockwise and counter-clockwise definitions.
// Depending on how you wired your motors, you may need to swap.
#define CW 0
#define CCW 1

// Motor definitions to make life easier:
#define MOTOR_A 0
#define MOTOR_B 1

// Pin Assignments //
// Don’t change these! These pins are statically defined by shield layout
const byte PWMA = 3; // PWM control (speed) for motor A
const byte PWMB = 11; // PWM control (speed) for motor B
const byte DIRA = 12; // Direction control for motor A
const byte DIRB = 13; // Direction control for motor B

void setup()
{
setupArdumoto(); // Set all pins as outputs

// set digital pin to control as an output
pinMode(13, OUTPUT);
// set the data rate for the SoftwareSerial port
BT.begin(9600);
// Send test message to other device
BT.println(“Serial is working correctly”);
}

char a; // stores incoming character from other device
int setspeed; //1-255 charecter defining the motor speed

void loop()
{

if (BT.available())
// if text arrived in from BT serial…
{
a=(BT.read());
BT.println(a);
if (a==’1′)
{
digitalWrite(13, HIGH);
BT.println(“LED on”);
}
if (a==’2′)
{
digitalWrite(13, LOW);
BT.println(“LED off”);
}
if (a==’?’)
{
BT.println(“Send ‘1’ to turn LED on”);
BT.println(“Send ‘2’ to turn LED on”);
}
// you can add more “if” statements with other characters to add more commands

if (a==’w’) // FORWARD
{
BT.println(“FORWARD”);
driveArdumoto(MOTOR_A, CCW, 255); // Motor A at max speed.
driveArdumoto(MOTOR_B, CCW, 255); // Motor B at max speed.
delay(200); // Drive forward for a second
stopArdumoto(MOTOR_A); // STOP motor A
stopArdumoto(MOTOR_B); // STOP motor B
}

if (a==’s’) // BACKWARD
{
BT.println(“BACKWARD”);
driveArdumoto(MOTOR_A, CW, 255); // Motor A at max speed.
driveArdumoto(MOTOR_B, CW, 255); // Motor B at max speed.
delay(200); // Drive forward for a second
stopArdumoto(MOTOR_A); // STOP motor A
stopArdumoto(MOTOR_B); // STOP motor B
}

if (a==’a’) // RIGHT
{
BT.println(“RIGHT”);
driveArdumoto(MOTOR_B, CCW, 255); // Set motor B to CCW at max
delay(200); // Motor B will spin as set for 1 second
stopArdumoto(MOTOR_B); // STOP motor B
}

if (a==’d’) // LEFT
{
BT.println(“LEFT”);
driveArdumoto(MOTOR_A, CCW, 255); // Set motor A to CCW at max
delay(200); // Motor A will spin as set for 1 second
stopArdumoto(MOTOR_A); // STOP motor A
}

}
}

// driveArdumoto drives ‘motor’ in ‘dir’ direction at ‘spd’ speed
void driveArdumoto(byte motor, byte dir, byte spd)
{
if (motor == MOTOR_A)
{
digitalWrite(DIRA, dir);
analogWrite(PWMA, spd);
}
else if (motor == MOTOR_B)
{
digitalWrite(DIRB, dir);
analogWrite(PWMB, spd);
}
}

// stopArdumoto makes a motor stop
void stopArdumoto(byte motor)
{
driveArdumoto(motor, 0, 0);
}

// setupArdumoto initialize all pins
void setupArdumoto()
{
// All pins should be setup as outputs:
pinMode(PWMA, OUTPUT);
pinMode(PWMB, OUTPUT);
pinMode(DIRA, OUTPUT);
pinMode(DIRB, OUTPUT);

// Initialize all pins as low:
digitalWrite(PWMA, LOW);
digitalWrite(PWMB, LOW);
digitalWrite(DIRA, LOW);
digitalWrite(DIRB, LOW);
}

One Reply to “Power Upgrade”

  1. Thanks for sharing all of these! I never got very far with my arduino projects, but it’s exciting to see what you have been working on.

    Do you have any of this posted on github? I have the feeling that other people out there would be interested in what you have been working on, and it’s a pretty good way of storing and distributing code.

Comments are closed.