Nema17 relay input & 2 micro Switches & A4988

Hi guys, im loking for a guide to do the following with the following:
1x Nema17
1x A4988
1x Relay Controlled by other means (Normally Closed)
2x Micro switches (1 generally closed, 1 generally open)

A4988 Dir Pin = 2
A4988 step Pin = 3
A4988 enablePin = 4

External Relay = 10 (Normally Closed)
Microswitch 1 = 11 (Normally Closed held closed)
Microswitch 2 = 12

What im looking for is
when the External relay changes state to Normally open (it will latch open)
the Nema17 rotates and continues until it reaches the Microswitch 2 (Causing MS2 to Close)
When the relay changes back to Normally Open the Nema17 runs backwards until Microswitch 1 Closes

I cannot seem to find any code for this, although i am unsure what to search.

Any help apreciated

You won't find any code to do exactly what you want but it is made up of several elements that you can test separately then put together

  • can you read the state of an input ?
  • can you detect that the state of an input has changed ?
  • can you determine from the current state of the input that 2 switch contacts have become closed ?
  • can you rotate a stepper motor ?
  • can you change the stepping direction of a stepper motor ?
  • can you stop a stepper rotating when you detect a change of state of an input

I do have some code that doesnt work correctly, I was remiss in not posting the code:
I was also just looking to see if anyone had working code,.
The code i have was not seemng to take any notice of the switches.

It was from a project I found here, i will be back having a play on Tuesday, and will post the code i have

cheers, ill look at the code an try and break it down

If you want collaboration, a good place to start is to share your neat & clear schematic and code, then we can see what you have to work with.

it doesn’t have to work, just enough that we can see how and what you’re trying to do.

Cheers, i will fire it all back up Tuesday an enture in properly again

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.