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.This is a sketch of my work so you can esier understand my problem .
first i need 2 steep motor normal rotate to senzor and them i need pause 3 second.
1 steep motor start rotate left when he detect somthing on senzor
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.
2 steep motor after senzor detect container need go 1 step left evry 3 second
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 ?
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.
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
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.
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.
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
#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
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 ..