arduino diy needle seder with steep motors

hello,

I will need help with arduino code for my seeder.
i have 2 steep motors, i need to move first motor 70% left ,pause 1 second ,move right to vertical botton and pause 1 second, in same time second motor move 1 step left and wait 3 second, when first motor is in 70% position vacum pump need suck seed and when is 1 mottor vertical 0 position vacum pump need blow seed ... im not rly good english speker sry for thet.. i will put video so you can see what i'm thing .diy needle seeder - YouTube i have 2 l298 module for stepp motor and 12/5/3,3 V power suply.

tnx for answer

You need to post the code you have tried and explain exactly what it does and what you want it to do that is different.

If you want someone to write code for you please ask in the Gigs and Collaborations section of the Forum and be prepared to pay.

These links may help
Stepper Motor Basics
Simple Stepper Code

The demo Several Things at a Time illustrates the use of millis() to manage timing.

Planning and Implementing a Program

...R

tnx for answer.This is a sketch of my work so you can esier understand my problem .

  1. first i need 2 steep motor normal rotate to senzor and them i need pause 3 second.
  2. 1 steep motor start rotate left when he detect somthing on senzor
  3. 1 steep motor rotate form 100% point to 70% point and pause 1 second , because vacum pump need to
    take seed, after 1 second he return to 100% point and blow seed. zhis will need repeat 19 time because container have 19 hole.
  4. 2 steep motor after senzor detect container need go 1 step left evry 3 second
  5. after 19 repeat 2 steep motor ned go normal to de end of lane.

here is code for first motor :

#include <Stepper.h>

const int stepsPerRevolution = 45;  // change this to fit the number of steps per revolution
// for your motor

// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);

void setup() {
  // set the speed at 60 rpm:
  myStepper.setSpeed(40);
  // initialize the serial port:
  Serial.begin(9600);
}

void loop() {
  // step one revolution  in one direction:
  Serial.println("clockwise");
  myStepper.step(stepsPerRevolution);
  delay(500);

  // step one revolution in the other direction:
  Serial.println("counterclockwise");
  myStepper.step(-stepsPerRevolution);
  delay(500);
}

in this code i need pause on start and pause after 70% left 1 second ? can i do this with l298 modul ?
and can i put somthing to repeat this 19 time ?

http://imgur.com/a/Eprbr link of my sketch

For the future please post your program using the code button </>

so it looks like this

. See How to use the Forum

To do the sort of thing you are describing it will be important not to use delay() because that blocks the Arduino from doing other things. Have a look at how millis() is used to manage timing without blocking in Several things at a time

Also, I don’t think the Stepper library is suitable as the command myStepper.step(stepsPerRevolution); also blocks until it completes. Either use the AccelStepper library or write your own non-blocking code as in the second example in my code link above.

And have a look at Planning and Implementing a Program for some ideas about how to plan your program without everything getting tangled up. It would be a very good idea to write down a list of the actions that need to happen with one action on each line.

If all this makes you think that what you want to do is non-trivial then you would be correct. But that does not mean it will be very difficult - it just needs careful thought.

…R

soo somthing like this for start ?

start 2 motor left
move 2 motor to senzors
check senzor
pause 2 motor 3 second
move 1 motor to 70% point if senzor detect somthing
pause 1 motor 1 second
move 1 motor to 100 % point
pause 1 motor 1 second
move 2 motor 1 step left
pause 2 motor 3 second

That is the sort of thing I had in mind.

Does each of your actions complete before the next one starts? I suspect not

...R

not, i dont know what next to do, how to move this motor left to senzor ? ,i looking accel stepper library now

#include <AccelStepper.h>

#define relayPin 2    //     pin for pump          
#define dirPin 3      //                     
#define stepPin 8    //Step Output on pin 8
#define stepPin 9    //Step Output on pin 9
#define stepPin 10   //Step Output on pin 10
#define stepPin 11   //Step Output on pin 11

#define maxSpeed 4000
#define shaftSpeed 4000

const int steps = 200;                             
AccelStepper stepper(1, dirPin, stepPin);


void setup()
{
    Serial.begin(9600);
    pinMode(relayPin, OUTPUT);
    pinMode(dirPin, OUTPUT);
    pinMode(stepPin, OUTPUT);
    stepper.setMaxSpeed(maxSpeed);
    stepper.setSpeed(shaftSpeed); 
}

void loop()
{
    suckair();
}

void suckair()
{
   for (int i = 0; i < 19; i++)  // suck 19 time
  {
  pumpOn();
  pumpOff();
  rotate();
  }
}

void rotate()
{
  stepper.moveTo(0);  //rotate back to zero ????
  stepper.setSpeed(shaftSpeed);
  
}

void pumpOn()
{
  digitalWrite(relayPin, HIGH);
  delay(1000);            // pause 1 second for suck
}

void pumpOff()
{
  digitalWrite(relayPin, LOW);
  delay(1000);    //pause 1 second for blow or turn of
}

somthing like this for motor 1 ?

marinac94:
not, i dont know what next to do, how to move this motor left to senzor ? ,i looking accel stepper library now

Then the first thing you need to do is write down (in similar fashion to Reply #5) what you really want to happen.

It is just a waste of time trying to write code before you have a clear understanding of what you want the code to do.

Most of the time for developing a program (maybe 70% of the time) is used up in the planning and thinking phase. To a beginner that may seem like a waste of time when you are anxious to start DOING something. But figuring out what needs to happen before you start writing code will get you to a working program very much faster. If you start at the wrong end then you will spend even more time re-writing your code when you find you have run into a dead-end that can't work or can't be extended to take in another feature.

...R

tnx, i will try step by step , i know what my project need to doo, but problem is i dont know what code to do ..

marinac94:
i know what my project need to doo,

Getting the concept out of your head and onto paper (or your text editor) is an essential step IMHO.

When I do that for my projects I always discover bits and pieces that were not obvious in what seemed like a simple concept in my head. Computers are extraordinarily stupid and you have to get your thinking down to their level.

...R

ok this is your way , my code need to do all of this, now i need to found code on internet for all of this steps. did i need define sensor input ? like i defined step motor inputs?

#include <AccelStepper.h>


// Motor pin definitions( motor 1)
#define motorPin1  8     // A1-input1 
#define motorPin2  9     // A2-input2 
#define motorPin3  10    // B1-input3 
#define motorPin4  11    // B2-input4  
// Motor pin definitions( motor 2)
#define motorPin1  4     // A1-input1 
#define motorPin2  5     // A2-input2 
#define motorPin3  6     // B1-input3 
#define motorPin4  7     // B2-input4  

// Initialize with pin sequence IN1-IN3-IN2-IN4 for motor 1 and motor 2 ( l298 shield)
void setup(){
  
}
void loop() {
  
}

void move2motortosenzor() {} //need start to move motor in one direction as long as the sensors not reach , then stop the motor and wait 3 second

void move1motorleft() {}  // when motor 2 come to sensor,motor 1 need move automatic left. 

void pause1motorleft() {}  //when motor 1 reache position of 70% pause this motor for 1 second.

void vacumPumpOn() {}   //suck air 1 second

void move1motorright() {}  //move motor 1 right

void pause1motorright() {} // when motor 1 come to start position in this case 0 or 100%  pause motor for 1 second

void vacumPumpOf () {} // blow air or turn of vacum pump

void move2motor1stepleft() {} //after vacum pump turn off, move motor 2   1 second

void pause2motorleft() {} // pause again motor 2 for 3 second and repead all 19 time

void pause2motortoDeEnd() {} // after 19 time move motor to to de end of line

here is code for step 1 i gues

#include <AccelStepper.h>

// Motor pin definitions( motor 1)
#define motorPin1  8     // A1-input1 
#define motorPin2  9     // A2-input2 
#define motorPin3  10    // B1-input3 
#define motorPin4  11    // B2-input4  

// Initialize with pin sequence IN1-IN3-IN2-IN4 for motor 1 and motor 2 ( l298 shield)
void setup(){
  epper.setMaxSpeed(1000);
  stepper.setAcceleration(1000);
}
void loop() {
  void move2motortosenzor();

}
void move2motor4second() {} //need start to move motor in one direction 4 second, then stop the motor and wait 3 second


stepper.runSpeed();
  stepper.moveTo(4000);
  stepper.run();
  stepper.stop();
  //stepper.runToPosition();
  delay(3000);
}
  if (stepper.distanceToGo() == 0 && motorMoving == true) {
   motorStoppedMillis = millis();
   motorMoving = false;
}
if (millis() - motorStoppedMillis >= 4000){
   // set new destination for the motor
   motorMoving = true;
}

arduino get e Error compiling for board Arduino/Genuino Uno. ? why

marinac94:
arduino get e Error compiling for board Arduino/Genuino Uno. ? why

This is not a guessing show - tell us what the error is. Post the full error message.

...R

Arduino: 1.8.3 (Windows 7), Board: “Arduino/Genuino Uno”

C:\Users\Lo_OLzoR\Desktop\zavrsni\zavrsni.ino:1:26: fatal error: AccelStepper.h: No such file or directory

#include <AccelStepper.h>

^

compilation terminated.

exit status 1
Error compiling for board Arduino/Genuino Uno.

This report would have more information with
“Show verbose output during compilation”
option enabled in File → Preferences.

FULL EROR

i reinstal AccelStepper library and dont have old erro but i have nov so many new erors, where is problem ?

#include <AccelStepper.h>



// Motor pin definitions( motor 1)
//#define motorPin1 8 // A1-input1 
//#define motorPin2 9 // A2-input2 
//#define motorPin3 10 // B1-input3 
//#define motorPin4 11 // B2-input4 


int STEPS = 0;
Stepper stepper(STEPS, 8, 9, 10, 11);

// Initialize with pin sequence IN1-IN3-IN2-IN4 for motor 1 and motor 2 ( l298 shield)
void setup(){
  
int motorSpeed = 1000;
int motorAccel = 1000;

//need start to move motor in one direction as long as the sensors not reach , then stop the motor and wait 3 second
int motorStoppedMillis = 0;

stepper.moveTo(4000);
stepper.run();
stepper.stop();
//stepper.runToPosition();
delay(3000);
if (stepper.distanceToGo() == 0 && motorMoving == true) {
motorStoppedMillis = millis();
motorMoving = false;
}
if (millis() - motorStoppedMillis >= 4000){
// set new destination for the motor
motorMoving = true;
}}
}
void loop() {}

error: ‘Stepper’ does not name a type
‘stepper’ was not declared in this scope
‘motorMoving’ was not declared in this scope if i change this to (moveTo ) i get new erors …

Stepper stepper(STEPS, 8, 9, 10, 11);

You are still using code that was appropriate for the simple Stepper library.

Have you studied and tried the AccelStepper examples so you can learn how to use the new library?

…R

fisrt for define i used this code

//#define motorPin1  8     // A1-input1 
//#define motorPin2  9     // A2-input2 
//#define motorPin3  10    // B1-input3 
//#define motorPin4  11    // B2-input4  
//
AccelStepper stepper2(AccelStepper::FULL4WIRE, 8, 9, 10, 11);

but i get this eror 'stepper' was not declared in this scope

marinac94:
but i get this eror 'stepper' was not declared in this scope

It was a struggle, but I managed to avoid using bad language. How do you expect help when you don't post the full program?

And you did not answer my question in Reply #17

...R