Stepper motor controlled syringe pump

Dear forum,

I am trying to make syringe pump controlled with arduino, easy driver and stepper motor.

I have make basic hardware design:

But in principle, it should work like:

  • stepper moves CW and CCW
  • when hits limit switch 1 turns direction and again when hits limit switch 2 turns to other side
  • when limit switches are pushed in the same time i want to control relay to use valves
  • also i want to add speed control, so it will be able to basically control volume per minute

But now i am stuck at driving stepper, I have take inspiration from this tutorial

, but I am not good at programming so can anyone please give advice how to make it happens.

Might be a daft question...but why drive the two syringes this way? Why not one for each syringe for more control?

Anyway.

Where is your code? Have you tried any code at all yet?

Maths bit - I will link an old post of mine with some maths behind the volume rate.:

Yes, i have tried but no succes.

I am able to control relays change speed using button but only after few changes from original code :confused:

#define step_pin 9  // Pin 9 connected to Steps pin on EasyDriver
#define dir_pin 8   // Pin 8 connected to Direction pin
#define MS1 10       // Pin 10 connected to MS1 pin
#define MS2 11       // Pin 11 connected to MS2 pin
#define SLEEP 12     // Pin 12 connected to SLEEP pin
#define X_pin A0    // Pin A0 connected to joystick x axis
#define Joy_switch 4  // Pin 4 connected to joystick switch
#define Limit01 2  // Pin 2 connected to Limit switch out
#define Limit02 3  // Pin 3 connected to Limit switch out

#define RELE1 6  // Pin 6 connected as relay
#define RELE2 7  // Pin 3 connected as relay

int step_speed = 10;  // Speed of Stepper motor (higher = slower)
void setup() {
pinMode(MS1, OUTPUT);
pinMode(MS2, OUTPUT);
pinMode(dir_pin, OUTPUT);
pinMode(step_pin, OUTPUT);
pinMode(SLEEP, OUTPUT);
pinMode(Limit01, INPUT);
pinMode(Limit01, INPUT);

pinMode(6, OUTPUT);  //rele 1
pinMode(7, OUTPUT);  //rele 2

pinMode(17, OUTPUT);
pinMode(18, OUTPUT);
pinMode(19, OUTPUT);

digitalWrite(17, HIGH);

digitalWrite(RELE1, LOW);
digitalWrite(RELE2, HIGH);

pinMode(Joy_switch, INPUT_PULLUP);
digitalWrite(SLEEP, HIGH);  // Wake up EasyDriver
delay(5);  // Wait for EasyDriver wake up
/* Configure type of Steps on EasyDriver:
// MS1 MS2
//
// LOW LOW = Full Step //
// HIGH LOW = Half Step //
// LOW HIGH = A quarter of Step //
// HIGH HIGH = An eighth of Step //
*/
digitalWrite(MS1, LOW);      // Configures to Full Steps
digitalWrite(MS2, LOW);    // Configures to Full Steps
}


void loop() {

if (!digitalRead(Joy_switch)) {  //  If Joystick switch is clicked
delay(500);  // delay for deboucing
switch (step_speed) {  // check current value of step_speed and change it
  
case 1:
step_speed=10;  // slow speed
digitalWrite(17, HIGH);
digitalWrite(18, LOW);
digitalWrite(19, LOW);
break;

case 5:
step_speed=1;  // fast speed
digitalWrite(19, HIGH);
digitalWrite(18, LOW);
digitalWrite(17, LOW);
break;

case 10:
step_speed=5;  // medium speed
digitalWrite(18, HIGH);
digitalWrite(17, LOW);
digitalWrite(19, LOW);
break;
}




  
//
//digitalWrite(dir_pin, LOW);  // (HIGH = anti-clockwise / LOW = clockwise)
//digitalWrite(step_pin, HIGH);
//delay(step_speed);
//  
////if (analogRead(X_pin) > 712) {  //  If joystick is moved Left
//if (!digitalRead(Limit01)) {}  // check if limit switch is activated
//else {  //  if limit switch is not activated, move motor clockwise
//digitalWrite(dir_pin, LOW);  // (HIGH = anti-clockwise / LOW = clockwise)
//digitalWrite(step_pin, HIGH);
//delay(step_speed);
////digitalWrite(step_pin, LOW);
////delay(step_speed);
////}      
////}
////if (analogRead(X_pin) < 312) {  // If joystick is moved right
//if (!digitalRead(Limit02)) {}  // check if limit switch is activated
//else {  //  if limit switch is not activated, move motor counter clockwise
//digitalWrite(dir_pin, HIGH);  // (HIGH = anti-clockwise / LOW = clockwise)
//digitalWrite(step_pin, HIGH);
//delay(step_speed);
////digitalWrite(step_pin, LOW);
////delay(step_speed);
//}      


}    
if (analogRead(X_pin) > 712) {  //  If joystick is moved Left
if (!digitalRead(Limit01)) {  // check if limit switch is activated

digitalWrite(RELE1, HIGH);
digitalWrite(RELE2, LOW);
}

else {  //  if limit switch is not activated, move motor clockwise
digitalWrite(dir_pin, LOW);  // (HIGH = anti-clockwise / LOW = clockwise)
digitalWrite(step_pin, HIGH);
delay(step_speed);
digitalWrite(step_pin, LOW);
delay(step_speed);



}      
}
if (analogRead(X_pin) < 312) {  // If joystick is moved right
if (!digitalRead(Limit02)) {  // check if limit switch is activated

digitalWrite(RELE1, LOW);
digitalWrite(RELE2, HIGH);
}

else {  //  if limit switch is not activated, move motor counter clockwise
digitalWrite(dir_pin, HIGH);  // (HIGH = anti-clockwise / LOW = clockwise)
digitalWrite(step_pin, HIGH);
delay(step_speed);
digitalWrite(step_pin, LOW);
delay(step_speed);


}      


}
}

Your post seems interesting, but I am trying to achieve “aplicator” so in this case when one siringe is pulling liquid out second is getting liquids in so you do not waste time with sucking liquids - it is critical for aplication.

Without seeing your code or the datasheet for your stepper motors or knowing what stepper motor drivers you are using it is hard to offer specific advice.

You were too quick for me.

I strongly suspect that your use of the delay() function is inappropriate. The Arduino can do nothing during a delay() interval. Instead use millis() to manage timing as illustrated in Several Things at a Time The second example in this Simple Stepper Code also uses millis() and micros() for timing

...R
Stepper Motor Basics

Dear Robin2,

sorry I have forgotten somehow to post it :confused:

According your guidance I have checked your codes, but after several tries I have only managed to :

  • when I hit button CW it goes one side CW, but when I hit other CCW It does nothing. Same is when I do it with second firs CCW and after that CW button.

I was trying to somehow use together examples but I am lost now, I dont know how to buil so many ifs and else together.

Am I getting closer or this is complete wrong? :confused:

// testing a stepper motor with a Pololu A4988 driver board or equivalent

// this version uses millis() to manage timing rather than delay()
// and the movement is determined by a pair of momentary push switches
// press one and it turns CW, press the other and it turns CCW

byte directionPin = 8;
byte stepPin = 9;

byte buttonCWpin = 4;
byte buttonCCWpin = 5;

boolean buttonCWpressed = false;
boolean buttonCCWpressed = false;

int numberOfSteps = 3200; //2 full turns

byte ledPin = 13;

unsigned long curMillis;
unsigned long prevStepMillis = 0;
unsigned long millisbetweenSteps = 1; // milliseconds

void setup() { 

  Serial.begin(9600);
  Serial.println("Starting Stepper Demo with millis()");

  pinMode(directionPin, OUTPUT);
  pinMode(stepPin, OUTPUT);
  pinMode(ledPin, OUTPUT);
  
  pinMode(buttonCWpin, INPUT_PULLUP);
  pinMode(buttonCCWpin, INPUT_PULLUP);
  
}

void loop() { 
  
  curMillis = millis();
//  readButtons();
  actOnButtons();
  //right();
  //left();
}

//void readButtons() {
// 
//  buttonCCWpressed = false;
//  buttonCWpressed = false;
//  
//  if (digitalRead(buttonCWpin) == LOW) {
//    buttonCWpressed = true;
//  }
//  if (digitalRead(buttonCCWpin) == LOW) {
//    buttonCCWpressed = true;
//  }
//  }



void actOnButtons() {
  buttonCCWpressed = false;
  buttonCWpressed = false;

  if (digitalRead(buttonCWpin) == LOW) {
    buttonCWpressed = true;
  }
      while (buttonCWpressed == true) {
        digitalWrite(directionPin, LOW);
        //for(int n = 0; n < numberOfSteps; n++) {
        digitalWrite(stepPin, HIGH);
        // delayMicroseconds(pulseWidthMicros); // probably not needed
        digitalWrite(stepPin, LOW);
        delay(millisbetweenSteps);
        //singleStep();
        }

    
  if (digitalRead(buttonCCWpin) == LOW) {
    buttonCCWpressed = true;
      }
      while (buttonCCWpressed == true) {
        digitalWrite(directionPin, HIGH);
       // for(int n = 0; n < numberOfSteps; n++) {
        digitalWrite(stepPin, HIGH);
        // delayMicroseconds(pulseWidthMicros); // probably not needed
        digitalWrite(stepPin, LOW);
        delay(millisbetweenSteps);
        //singleStep();
        }
  }
  


//void right() {
//  
//  buttonCWpressed = false;
//
//  if (digitalRead(buttonCWpin) == LOW) {
//    buttonCWpressed = true;
//  }
//      while (buttonCWpressed == true) {
//        digitalWrite(directionPin, LOW);
//        //for(int n = 0; n < numberOfSteps; n++) {
//        digitalWrite(stepPin, HIGH);
//        // delayMicroseconds(pulseWidthMicros); // probably not needed
//        digitalWrite(stepPin, LOW);
//        delay(millisbetweenSteps);
//        //singleStep();
//        }
//        }
//void left() {
// buttonCCWpressed = false;   
// 
//  if (digitalRead(buttonCCWpin) == LOW) {
//    buttonCCWpressed = true;
//      }
//      while (buttonCCWpressed == true) {
//        digitalWrite(directionPin, HIGH);
//       // for(int n = 0; n < numberOfSteps; n++) {
//        digitalWrite(stepPin, HIGH);
//        // delayMicroseconds(pulseWidthMicros); // probably not needed
//        digitalWrite(stepPin, LOW);
//        delay(millisbetweenSteps);
//        //singleStep();
//        }
//  }









//void singleStep() {
//  if (curMillis - prevStepMillis >= millisBetweenSteps) {
//    prevStepMillis += millisBetweenSteps;
//    digitalWrite(stepPin, HIGH);
//    digitalWrite(stepPin, LOW);
//  }
//}

I want to firstly try to solve this "bouncing " from limit switch to limit switch, After that I will try to add speed control and relay controls.

Pepca_CZ:
Am I getting closer or this is complete wrong? :confused:

I have bookmarked this to look at it in the morning. If I forget please BUMP it on Thursday.

...R

I have now had a chance to look at this.

You seem to have completely mucked up what I thought was a simple piece of code. I had three separate functions for different activities, but you seem to be trying to merge them all into a single function. WHY?

Keeping things separate makes development and debugging simpler.

Go back and try my original code and tell me what it does, and what you would like it to do differently. Then maybe we can progress from that. It is much easier for me to help if I am working from familiar code.

...R