External power supply effect

My project is robot arm and I'm using steppers for motion and I have limitswitch for each stepper, two of the four limitswitch are sending wrong signals when I power the steppers ON using 12V external power supply.
When I power OFF the 12V the limitswitchs work perfectly!!!
What shall I do to solve that problem !!

Regards,

PLEASE, read the posting sticky.
http://forum.arduino.cc/index.php/topic,148850.0.html

More information is needed.

Use CTRL T to format your code.
Attach your complete sketch between code tags.
[code]Paste your sketch here[/code]

Show us a good schematic & image of your circuit wiring.
Posting images:

It is not coding or wiring problem to post my code or the circuit

I wrote a simple code that just print the limitswitchs status only if they are triggered and they work as expected when I power OFF the external power supply which is for stepper motors

But some of the limitswitchs when I power ON the external power supply they doesn't work correctly, I get triggered some times when it is not triggered in real life
If it is circuit problem, the rest limitswitchs must not work like the other two limitswitchs.
And if it is a codeing problem they will not work if the external power supply is OFF but they work

I think it is an electromagnetic field generated when the power supply is ON which is affecting the signals but I have no experience in such things.

ok sounds like you have no problem... we can't help you if you don't share what we need.

As mentioned, we can only help if you share information.

Would be nice to know if you are using N.O. or N.C. or how cables are affixed but alas.

Good luck.

Hey, leave the power on all time, there will be no problem.

This is interference, probably due to running the signal cables from the switches alongside the high
current motor wiring (bad idea).

You can mitigate easily by adding a 100nF capacitor to ground on each switch signal at the
Arduino input pin, to suppress interference spikes.

wolframore:
ok sounds like you have no problem… we can’t help you if you don’t share what we need.

Man I told you that I don’t have a problem with the code and wiring, just to not confuse you helping me, not because I don’t want to post them.

//EndStop
int EndStopX = 9;   //Pin
int EndStopY = 10;  //Pin
int EndStopZ = 11;  //Pin
int EndStopE = 12;  //Pin
void setup() {
  Serial.begin(250000);
  pinMode(EndStopX, INPUT);
  pinMode(EndStopY, INPUT);
  pinMode(EndStopZ, INPUT);
  pinMode(EndStopE, INPUT);
  
//starting commands
  Serial.println("Machine is ON");
  Serial.println();
}

void loop(){
  if(digitalRead(EndStopX)==1){
    Serial.print("X axis      ");Serial.println(digitalRead(EndStopX));
  }
  if(digitalRead(EndStopY)==1){
    Serial.print("Y axis      ");Serial.println(digitalRead(EndStopY));
  }
  if(digitalRead(EndStopZ)==1){
    Serial.print("Z axis      ");Serial.println(digitalRead(EndStopZ));
  }
  if(digitalRead(EndStopE)==1){
    Serial.print("E axis      ");Serial.println(digitalRead(EndStopE));
  }
}

this is my code

the connection is using breadboard contains 4* the circuit of the a4988 stepper driver
and 4* limit switch two pins connected to arduino power pins and the signal pin to the digital pins

thanks

MarkT:
This is interference, probably due to running the signal cables from the switches alongside the high
current motor wiring (bad idea).

You can mitigate easily by adding a 100nF capacitor to ground on each switch signal at the
Arduino input pin, to suppress interference spikes.

thank you man a lot I will try that, it may help me

try to separate the signal wires from the motor wires if it's induction issue. Using shielded wires may help.

If the switches are N.O. try N.C.

pinMode(EndStopX, INPUT); //Hum
Cannot see from your schematic, maybe use a good strong pullup.

Maybe add a reset function that monitors the external power supply and initializes things after a power up delay period.

Maybe add a soft start external power supply.

As mentioned add filtering on inputs, maybe some well placed ferrite beads are warranted.

Add shielded cabling.

Re-rout input cabling.

Maybe add decoupling capacitors to each I.C. we cannot see in the schematic.

The problem have been solved after adding 10uf capacitor over the signal pin of the limitswitchs
100uf made another problem so I tried 10uf
Thanks mr. MarkT and others

10 uF is large... might delay your sensor reading... I would try smallest possible. Have you tried 0.1uF?

No I didn't, I don't have one.
But it is working properly with 10uf

If you’re happy then so are we

larryd:
pinMode(EndStopX, INPUT); //Hum
Cannot see from your schematic, maybe use a good strong pullup.

@OP
Did you understand what larryd is trying to say here?
So do you have pull up resistors, and what value.

Floating pins (switches without pull up/down) pick up all sorts of interference.
Maybe you should start with only using the internal pull up (code).

pinMode(EndStopX, INPUT_PULLUP); // enable internal pull up

A cap from pin to ground (100n max) can be used in 'dirty' environments.
Stronger external pull up (1k resistor between pin and 5volt) is normally not needed, because you should have the "normally closed" endstop/safety switch wired between pin and ground.
Leo..

Man, don't you see he doesn't have a problem? That's why he's here asking for help.

By the way, 10uF may be slowly burning your microswitch contacts.

Are you using twisted pair for wiring? Are the wires for the motors and the limit switches all in the same cable?

But... I forgot. You have no problems. Nevermind.