0

I have three nema 23 steppers with one 8 channel relay(all the pins used) powering two dc motors and 4 IR sensors for feedback on the machine.

The problem is my machine is working fine for only 2 to 3 minutes until it just resets itself in the middle of the routine and crashes my whole system.

I am using 1/2 step microstepping with TB6600 stepper driver. Also my arduino is mega 2560, maybe thats the problem I don't know about.

Schematic

Here I am attaching the code

const int dirPin1=2;
const int stepPin1=3;
const int dirPin2=4;
const int stepPin2=5;
const int dirPin3=6;
const int stepPin3=7; 
int del=1;
void setup() {
 pinMode(2,OUTPUT);
 pinMode(3,OUTPUT);
 pinMode(4,OUTPUT);
 pinMode(5,OUTPUT);
 pinMode(6,OUTPUT);
 pinMode(7,OUTPUT);
 pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
pinMode(10,OUTPUT);
pinMode(11,OUTPUT);
pinMode(12,OUTPUT);
pinMode(13,OUTPUT);
pinMode(14,OUTPUT);
pinMode(15,OUTPUT);
pinMode(16,INPUT);
pinMode(17,INPUT);
pinMode(18,INPUT);
pinMode(19,INPUT);
digitalWrite(8,HIGH);
digitalWrite(9,HIGH);
digitalWrite(10,HIGH);
digitalWrite(11,HIGH);
digitalWrite(12,HIGH);
digitalWrite(13,HIGH);
digitalWrite(14,HIGH);
digitalWrite(15,HIGH);
 
}
void picker_up(){
  digitalWrite(8,HIGH);
  digitalWrite(9,HIGH);
  digitalWrite(10,LOW);
  digitalWrite(11,LOW);
  delay(570);
  digitalWrite(8,HIGH);
  digitalWrite(9,HIGH);
  digitalWrite(10,HIGH);
  digitalWrite(11,HIGH);
  delay(100);
}
void picker_down(){
  digitalWrite(8,LOW);
  digitalWrite(8,LOW);
  digitalWrite(10,HIGH);
  digitalWrite(11,HIGH);
  delay(320);
  digitalWrite(8,HIGH);
  digitalWrite(9,HIGH);
  digitalWrite(10,HIGH);
  digitalWrite(11,HIGH);
  delay(100);
}
void claw_close(){
  digitalWrite(12,LOW);
  digitalWrite(13,LOW);
  digitalWrite(14,HIGH);
  digitalWrite(15,HIGH);
  delay(100);
  digitalWrite(12,HIGH);
  digitalWrite(13,HIGH);
  digitalWrite(14,HIGH);
  digitalWrite(15,HIGH);
  delay(100);
}
void claw_open(){
  digitalWrite(12,HIGH);
  digitalWrite(13,HIGH);
  digitalWrite(14,LOW);
  digitalWrite(15,LOW);
  delay(100);
  digitalWrite(12,HIGH);
  digitalWrite(13,HIGH);
  digitalWrite(14,HIGH);
  digitalWrite(15,HIGH);
  delay(100);
}

void loop() {
  // put your main code here, to run repeatedly:
digitalWrite(dirPin1,HIGH);
digitalWrite(dirPin2,HIGH);
digitalWrite(dirPin3,LOW);
for(int i=0;i<=1200;i++){
  digitalWrite(stepPin1,HIGH);
  digitalWrite(stepPin2,HIGH);
  digitalWrite(stepPin3,HIGH);
  delay(del);
  digitalWrite(stepPin1,LOW);
  digitalWrite(stepPin2,LOW);
  digitalWrite(stepPin3,LOW);
  delay(del);
}
for(int i=1;i<=400;i++){
  digitalWrite(stepPin1,HIGH);
  delay(del);
  digitalWrite(stepPin1,LOW);
  delay(del);
}
delay(1000);
picker_down();
claw_open();
claw_close();
picker_up();
delay(2000);
digitalWrite(dirPin1,LOW);
digitalWrite(dirPin2,LOW);
digitalWrite(dirPin3,HIGH);
for(int i=1;i<=400;i++){
  digitalWrite(stepPin1,HIGH);
  delay(del);
  digitalWrite(stepPin1,LOW);
  delay(del);
}
for(int i=0;i<=1200;i++){
  digitalWrite(stepPin1,HIGH);
  digitalWrite(stepPin2,HIGH);
  digitalWrite(stepPin3,HIGH);
  delay(del);
  digitalWrite(stepPin1,LOW);
  digitalWrite(stepPin2,LOW);
  digitalWrite(stepPin3,LOW);
  delay(del);
}
delay(2000);
}

I am not getting why this is happening. Or do I need some more electronic components included in the machine and I know I could have used mosfets to control the motors but I am just way too lazy.

I used uno before this and it used to work fine, so should I just go back to using it?

Also I have modified the code to be compatible with the uno again so please bare with the pin numbers.

10
  • 1
    I don't believe there's any reasonable way to answer the question with the information provided. It could be literally anything. I would not recommend doing stepper driving "by hand" when there are libraries available. At the very least you'd need to include a schematic. May 17, 2021 at 13:52
  • 1
    I'm going out on a limb here with no schematic, but a common reason for resetting is low voltage caused by too much current draw. "I know I could have used mosfets to control the motors but I am just way to lazy." suggests a possible cause. Are your motors powered through the Arduino?
    – JRobert
    May 17, 2021 at 13:58
  • 1
    I am using external power sources for everything even the relay is not powered by the arduino mega May 17, 2021 at 14:33
  • add some debugging code
    – jsotola
    May 17, 2021 at 14:52
  • 1
    I actually thought of using a stepper motor library but the library accelstepper blocks every other actuator to make the stepper rotate which means my two motors that are running together will not work. @DaveNewton May 17, 2021 at 16:07

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.