Stepper, limit switch and homing sequence. Problem with a false signal that triggers the loop

Hey Folks. First time here.

So I'm making a sculpture, it is set up at the World trade Center of Montreal right now, which is great! But it ... doesn't work and the art director is getting impatient, so I need someone's help.

It's pretty much a pulley system that lifts a jar that slowly pour sands on the floor. I'm using a Nema 23 stepper motor ( bipolar, jk57hs76 2804) and a TB6600 Driver.
On my prototype at home, everything worked (using the 5vdc and the driver that comes with the arduino kit) but when I installed the arduino on the main system, it does not work, or should I say, everything works, but something is interfeering.
I'm having a homing sequence in the Void Setup that pulls the cable down until the limit switch is pressed ( there's an object screwed on the cable that hits the switch at the desired lenght ) which then triggers the Void loop. I'm using the Serial buffer to send HIGH or LOW. The thing is, when I set it up, the pulley pulls the cable, but around 10 to 60 second (it's quite random) the TX on my arduino flashes even tho nothing thouches the switch and the loop begins. I'm seriously losing my mind over this.

Anyway here's my code:

#include <AccelStepper.h>
#define homing 9

AccelStepper stepper(AccelStepper::DRIVER,4,3);
long limit = 850000;
long initial_homing = -1;

void setup()
{
Serial.begin(9600);
pinMode(homing, INPUT_PULLUP);
stepper.setMaxSpeed(3600.0);
stepper.setAcceleration(100.0);
stepper.setSpeed(400);
stepper.runSpeed();

Serial.println(initial_homing);

while (digitalRead(homing)== LOW){
stepper.moveTo(initial_homing);
initial_homing++;
stepper.run();
delay(5);
}
stepper.setCurrentPosition(0);
initial_homing = 1;

while(digitalRead(homing)== HIGH){
stepper.moveTo(initial_homing);
initial_homing--;
stepper.run();
delay(5);
}

stepper.setCurrentPosition(0);
stepper.setMaxSpeed(3600.0);
stepper.setAcceleration(100.0);
stepper.setSpeed(400);
stepper.runSpeed();
Serial.println(initial_homing);

}

void loop()
{
stepper.moveTo(limit);
stepper.runToPosition();
delay(1000);
stepper.moveTo(0);
stepper.runToPosition();
delay(1000);
stepper.run();
}

I'm assuming the issue is either with the code or the wiring, but I want to be sure because I really don't understand what's wrong here.

Thanks folks.

Show us a good schematic of your circuit.

Show us a good image of your ‘actual’ wiring.

Give links to components.

In the Arduino IDE, use CTRL T to format your code then copy the complete sketch.
Use the </> button from the ‘reply menu’ to attach the copied sketch.

What is this all about initial_homing–;

Welcome to the world of real electronics. Your statement World trade Center of Montreal actually tells a lot. You need to treat your stuff as though it is in a very electrical noisy industrial environment. Shielding is very important, is your arduino in a grounded metal box? Is there appropriate transient protection on all the power supplies including the mains. Walk around a bit and see how others are doing this. We will all be able to help more when you post the schematic, not a frizzy thing, links to technical information on all the hardware devices connected and a picture of the actual setup, several if needed. I worked on an exhibit in the mid 90's and the electrical system was horrible noisy then.

#include <AccelStepper.h>
#define homing 9

AccelStepper stepper(AccelStepper::DRIVER,4,3);
long limit = 850000;
long initial_homing = -1;



void setup()
{
  Serial.begin(9600);
  pinMode(homing, INPUT_PULLUP);
  stepper.setMaxSpeed(3600.0);
  stepper.setAcceleration(100.0);
  stepper.setSpeed(400);
  stepper.runSpeed();
  
  Serial.println(initial_homing);
  
  while (digitalRead(homing)== LOW){
    stepper.moveTo(initial_homing); 
    initial_homing++;
    stepper.run();
    delay(5);
  }
  stepper.setCurrentPosition(0);
  initial_homing = 1;
    
  while(digitalRead(homing)== HIGH){
    stepper.moveTo(initial_homing);
    initial_homing--;
    stepper.run();
    delay(5);
    }
    
  stepper.setCurrentPosition(0);
  stepper.setMaxSpeed(3600.0); 
  stepper.setAcceleration(100.0);
  stepper.setSpeed(400);
  stepper.runSpeed();
  Serial.println(initial_homing);
     
}

void loop()
{
 stepper.moveTo(limit);
 stepper.runToPosition();
 delay(1000);
 stepper.moveTo(0);
 stepper.runToPosition();
 delay(1000);
 stepper.run();
}

I don't have a picture of the wiring and it's a bit far, I can have one tomorrow. it's pretty straight forward. Pulse+ and Dir+ goes to 3 and 4 and - goes to ground, the limit switch is 9 and GND. That being said, the limit switch has gator clips like that ( and I never thought much about it until now )


Could it create random interference?

stepper : https://abra-electronics.com/3d-printers-en/electronics-en/stepper-motors/nema-23/mot-57sth76-2804a.html

as for the initial_homing, I saw it over and over again in other sketch for homing sequence, I was basing myself from this tutorial: https://www.brainy-bits.com/post/homing-stepper-motors-using-the-accelstepper-library. I see it as a carrot on a stick, telling the motor to drives in one direction, and eventually it will hit the switch and go in the loop.
Is there a better way to do it?

driver: https://www.brainy-bits.com/post/homing-stepper-motors-using-the-accelstepper-library
(since im new here im limited to the numbers of link so here it is)

gilshultz: you're fidding me I never thought of this. I'll take some picture tomorrow but yeah everything is in the open. I'll get some casing then.

It's understood you're not a professional electrician but, this is what stuff looks like when done properly.

Field wiring (devices outside the cabinet) is landed on terminal strips. High voltage wiring is routed away from low/control voltages, wiring is - usually - secured by screw clamping, bundled and fixed to a surface and so on.

Don't forget to label the wires.

Alligator clips are for testing/troubleshooting/prototyping, not for permanent use.

1 Like

I’ve made up quite a few of those in my day; brings back memories.

Ok! I'll work on that right away. But just to be sure, there's no problem with the code then, I just need to make sure everything is shielded and grounded and it will work?

“But just to be sure, there’s no problem with the code then, . . .”

Those were your words up above. :wink:

Hi,
Keep all power wiring away from signal wiring.
How long are the wires between the controller and you input sensors?
If the limit switches have long wires, the internal pull_ups may be too weak, you may have to add 10K external pullup resistors.

Tom... :grinning: :+1: :coffee: :australia:

This is not an easy task, they offer college courses on this and the students still have problems. The picture shown by dougp is what our stuff looked like and sometimes we even still had to shield stuff to make it work properly. We were lucky and had all of our contactors and other power items in a separate shielded cabinet and all control was 24VDC. There are a lot of ways of doing this, and there is no one correct fix all solution. Most important be sure all the equipment grounds are solid, conduit has problems, especially with electronics, I always ran a seperate earth ground (Green [colors vary by country]) wire.

Ok. I went to the store and got myself a lot of equipement to insulate the whole thing. But let's talk about ground, because it's quite a mystery to me. My sculpture is made of metal, but it is standing on a wooden plinth, so I assume the only ground I'm getting is the one from the main outlet right? So I'm putting ground on the power supply, the question is, can my arduino share the same ground or should I try to get another source?

Also, thanks everyone I am quite amazed at how quick you were to help me out!

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