Controlling DC Motor Pump with Serial Port

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
migpics
 
Posts: 13
Joined: Sat Feb 15, 2014 2:58 am

Controlling DC Motor Pump with Serial Port

Post by migpics »

Hi, I am trying to control a motor using the AdaFruit Motor Shields by inputing a string into the Serial window.
Unfortunately the motor does not run although the Serial.println does work.

Was wondering if there is an issue with how I have set up the code.
I am using two motor shields.
The motor shield works when the code stopFlow() function is within the void() loop but does not work when it is within the if statement.

Thanks for your help.

Miguel

Code: Select all

#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_PWMServoDriver.h"

Adafruit_MotorShield AFMStop(0x61);
Adafruit_MotorShield AFMSbottom(0x60);

Adafruit_StepperMotor *myStepper1 = AFMStop.getStepper(100,2);



Adafruit_DCMotor *myMotor1 = AFMSbottom.getMotor(1);

int motorSpeed=0;
int motorOn;
String inData;
String motorStat;

void setup() {
  Serial.begin(9600);
  Serial.println("Water Pump MotorShield Test");
  
  AFMStop.begin();
  AFMSbottom.begin();
  
  
}



void loop() {

motorSpeed = Serial.read();
if (motorSpeed =='1'){
  goFlow();
  Serial.println("Water flowing!");
}

if (motorSpeed =='2'){
  stopFlow();
  Serial.println("Water not flowing!");
}


}






void goFlow(){
  myMotor1->run(FORWARD);
  myMotor1->setSpeed(10);
  myMotor1->run(RELEASE);

  
}

void stopFlow(){
  myMotor1->run(BACKWARD);
  myMotor1->setSpeed(10);
  myMotor1->run(RELEASE);  
}
  

void stopPump(){
  myMotor1->setSpeed(0);
}


User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Controlling DC Motor Pump with Serial Port

Post by adafruit_support_rick »

You're stopping the motor immediately after you start it:

Code: Select all

void goFlow(){
  myMotor1->run(FORWARD);     //start motor
  myMotor1->setSpeed(10);      //set speed
  myMotor1->run(RELEASE);     //stop motor
}

migpics
 
Posts: 13
Joined: Sat Feb 15, 2014 2:58 am

Re: Controlling DC Motor Pump with Serial Port

Post by migpics »

Thanks!
I thought the release, released the motor to start.
Probably thinking too much.

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Controlling DC Motor Pump with Serial Port

Post by adafruit_support_rick »

There's kind of a confusing comment in the sample code. I should probably fix that.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”