Go Down

Topic: Problem: switch randomly triggers (Read 463 times) previous topic - next topic

chasingsun

Please help me.

I used a arduino uno to controll a stepper motor. So everytime the button is push the motor rotate x amount of step forward then backward.

But for some reason sometimes it just rotate it self without pressing the button.

The button wiring is simple as this:
Ground to 1 pin on the button
5v----10k resister--- pin3--- button

Here is the code:
Code: [Select]


#define STEP 765


int smDirectionPin = 8; //Direction pin
int smStepPin = 9; //Stepper pin
int Stepping = false;

void setup(){
  /*Sets all pin to output; the microcontroller will send them(the7 pins) bits, it will not expect to receive any bits from thiese pins.*/
  pinMode(smDirectionPin, OUTPUT);
  pinMode(smStepPin, OUTPUT);
  pinMode(3, INPUT);
}
 
void loop(){
  delay(100);
  if (digitalRead(3) == LOW && Stepping == false)
  {
  digitalWrite(smDirectionPin, LOW);
  for (int i = 0; i < STEP; i++){
    digitalWrite(smStepPin, HIGH);
    delayMicroseconds(110);
    digitalWrite(smStepPin, LOW);
    delayMicroseconds(110);
  }
 
delay(50); //Pauses
 
  digitalWrite(smDirectionPin, HIGH); //Writes the direction to the EasyDriver DIR pin. (LOW is counter clockwise).
  /*Turns the motor fast 1600 steps*/
  for (int i = 0; i < STEP; i++){
    digitalWrite(smStepPin, HIGH);
    delayMicroseconds(110);
    digitalWrite(smStepPin, LOW);
    delayMicroseconds(110);
  }

  Stepping = false;
}

}



Does anyone know what is the mistake i have made. Very apperciate for any help. Thanks.

Southpark

#1
Nov 15, 2016, 01:58 am Last Edit: Nov 15, 2016, 01:59 am by Southpark
Did you try the special 'pullup' mode for the arduino pin configuration?

It's a software settable mode (lookup arduino 'pullup'). It allows the pin to be internally held at a logic high level (via an internal pullup resistor inside the arduino). It prevents false triggers due to noise and floating inputs etc.

If you're using an external pullup resistor already, then try a 1 kOhm pull-up resistor.

chasingsun

I have tried and it have the same problem. ;(

Southpark

Is the ground of your arduino connected to the ground of your stepper motor?

chasingsun

#4
Nov 15, 2016, 02:14 am Last Edit: Nov 15, 2016, 02:29 am by chasingsun
Sort answer : no

Long answer: the stepper motor is connect to a stepper motor driver .
The stepper motor driver connected directly to 240v ac. Should i ground the 240 ground to the arduino?

Btw. Arduino is using a 12v external power supply have two wire positive and negative.

Southpark

#5
Nov 15, 2016, 03:13 am Last Edit: Nov 15, 2016, 03:16 am by Southpark
Yep.Yep. Please try that. Connect the gnd of the arduino to the negative side ('gnd') of the stepper driver. Try that.

chasingsun

Thanks. I will try to do that tonight. And update on it asap.

After researching in seems to be like a floating problems.

Go Up