Notifications
Clear all

Linear actuator with DM542, 28BYJ-48, and Arduino

Page 2 / 2

BBall Auto
(@bball-auto)
Active Member
Joined: 2 months ago
Posts: 13
Topic starter  

@will

I would like to add in a button push below at the beginning of the void loop section that initiates the first carriage movement.  The place is highlighted in bold below. 

The Code:

/* Going to use the stepper library with most basic back and forth. Right now i'm using a delay, but hope
* to move next to using a button to initiate move in one direction with delay that then comes back home to wait
* for next button push.
* Using the 2 wires setup w DM542 and UNO (pulse+ to Dig 3, Direction+ to Dig 2)
*/

#include <Stepper.h>

//Creating a variable (perhaps the IDE vernacular is something else) that defines the number of steps per revolution

const int stepsPerRev = 1600;

//Going to define a variable for the number of full turns to make
const int numRevs = 5;

// i'm using format from example sketches from stepper library & setting pin 2 & 3
//
Stepper myStepper = Stepper(stepsPerRev,2,3);

void setup() {
// Setting speed in RPMs
myStepper.setSpeed(250);

}

void loop() {

// I hope to insert a trigger to start this first rotation based on a button push here

// First let's go one loop in one direction:
myStepper.step(numRevs * stepsPerRev);
delay(5000);

// Now the other direction;
myStepper.step(-numRevs * stepsPerRev);
delay(5000);

}


ReplyQuote
Will
 Will
(@will)
Reputable Member
Joined: 3 months ago
Posts: 368
 

@bball-auto

I'm going to let you experiment with buttons (see Arduino examples in Digital > Button). 

Besides the button declaration and setup, you'll need to declare a boolean value

bool  isRunning;

and in setup, set it to false.

isRunning = false;

in your loop() you'll need to check isRunning, if it's true then run your normal code. If it'a false then check the button to see if it's down.

If the button is down, then change isRunning to true.

If the button is NOT down then just keep looping.

 


ReplyQuote
Will
 Will
(@will)
Reputable Member
Joined: 3 months ago
Posts: 368
 

@bball-auto

I went back to read the original requirements and I think I got confused, so please check these statements to see if I now (correctly) understand what's supposed to happen ...

 

- you drag the carriage over to the left side of the apparatus and apply power to the Arduino

- in the Arduino setup() it resets the servo on the carriage to zero degrees.

- it then waits for button #1 and, when pressed goes all the way to the left and then stops

- if button #1 is pushed again, the carriage reverses direction and goes back to the other end of the rail

- button #2 will only be pressed when the carriage is stationary at either end of the rail

- pressing button #2 just traverses from one side of the servo to the other (0-180 degrees)

- the stepper and the servo will never be operating at the same time.

 

Am I stating something incorrectly or missing any salient detail ?


ReplyQuote
BBall Auto
(@bball-auto)
Active Member
Joined: 2 months ago
Posts: 13
Topic starter  

@will

I've simplified.  All i want to do now is the following:

1. If carriage is not at left start mark, place it there. 

2. Arduino sits waiting on button to be pushed. 

3. At button push, carriage moves from left side to right side. 

4. A delay occurs (the code currently has a 5 second delay)

5.  Carriage moves back to the left.

6.  The cycle sits waiting for button to be pushed again to repeat cycle. 

just need to figure out how to do that button in the code where i have it in bold. 

 


ReplyQuote
Will
 Will
(@will)
Reputable Member
Joined: 3 months ago
Posts: 368
 

@bball-auto

1) you'll need to do that by hand before you power on. The Arduino will lose any position it may have had after you shut it off.

So, I take it that you've totally eliminated (or totally automated) the servo motion ? This is important because if you need to look for that button then you'll need to take individual steps; if not then you can step the whole distance at once.

Show me your button testing function too, please.


ReplyQuote
BBall Auto
(@bball-auto)
Active Member
Joined: 2 months ago
Posts: 13
Topic starter  

@will

I have eliminated the servo.  And i'm never going to push the button until the entire carriage to right, followed by pause, followed by carriage to left sequence has occurred.  So i'm hoping i can use the existing code i've got (not individual steps) and just trigger the entire sequence with a button push. 


ReplyQuote
Will
 Will
(@will)
Reputable Member
Joined: 3 months ago
Posts: 368
 

@bball-auto

OK, show me the code you're using to check the button. I'd like you to do that part because I'm getting the feeling that if I feed you the entire sketch, then you won't be learning anything.

So, show me how you test for a button push and I'll show you how to put it in the loop.


ReplyQuote
BBall Auto
(@bball-auto)
Active Member
Joined: 2 months ago
Posts: 13
Topic starter  

i'm reading some stuff on buttons now.  i'll see what i can learn from that.  Thanks


ReplyQuote
Page 2 / 2