Hi all, I started a project which initially I though thought would be easy but I have run into a couple of snags.
I am powering a Arduino and two dc 130 motors from a 500mAh liPo battery. My code is running both motors simultaneously at 150 with pwm and everything works well. When I however bump this to up to 255, the system runs for all of a second or two and then the entire things powers down and it appears that the battery is totally drained. If anyone could advise as to where i'm going wrong, it would be much appreciated.
I have included a fritzing jpg and my code below. The green breakout is a step-up module that converts the 3.7v from the battery to around 5v to power the Arduino. I have also included a lipo fuel gauge breakout and even just running the motors at 150 seems to deplete the battery far quicker than I estimated.
#include "MAX17043.h"
#include "Wire.h"
//Battery monitor
MAX17043 batteryMonitor;
//Motor Controles
int STBY = 10; //standby
//Motor A
int PWMA = 3; //Speed control
int AIN1 = 9; //Direction
int AIN2 = 8; //Direction
//Motor B
int PWMB = 5; //Speed control
int BIN1 = 11; //Direction
int BIN2 = 12; //Direction
void setup() {
//battery status
Wire.begin();
Serial.begin(9600);
Serial.println("MAX17043 Example: reading voltage and SoC");
Serial.println();
//motor output
pinMode(STBY, OUTPUT);
pinMode(PWMA, OUTPUT);
pinMode(AIN1, OUTPUT);
pinMode(AIN2, OUTPUT);
pinMode(PWMB, OUTPUT);
pinMode(BIN1, OUTPUT);
pinMode(BIN2, OUTPUT);
}
void loop() {
batteryMonitor.reset();
batteryMonitor.quickStart();
delay(1000);
float cellVoltage = batteryMonitor.getVCell();
Serial.print("Voltage:\t\t");
Serial.print(cellVoltage, 4);
Serial.println("V");
float stateOfCharge = batteryMonitor.getSoC();
Serial.print("State of charge:\t");
Serial.print(stateOfCharge);
Serial.println("%");
Serial.println();
//motor control
move(1, 150, 1); //motor 1, full speed, left
move(2, 150, 1); //motor 2, full speed, left
delay(1000);
move(1, 0, 1); //motor 1, full speed, left
move(2, 0, 1);
delay(1000);
}
void move(int motor, int speed, int direction) {
//Move specific motor at speed and direction
//motor: 0 for B - 1 for A
//speed: 0 is off, and 255 is full speed
//direction: 0 clockwise, 1 counter-clockwise
digitalWrite(STBY, HIGH); //disable standby
boolean inPin1 = LOW;
boolean inPin2 = HIGH;
if (direction == 1) {
inPin1 = HIGH;
inPin2 = LOW;
}
if (motor == 1) {
digitalWrite(AIN1, inPin1);
digitalWrite(AIN2, inPin2);
analogWrite(PWMA, speed);
} else {
digitalWrite(BIN1, inPin1);
digitalWrite(BIN2, inPin2);
analogWrite(PWMB, speed);
}
}
void stop() {
//enable standby
digitalWrite(STBY, LOW);
}