Stepper motor with Limit switch Arduino basic usage




Schematic diagram Arduino with TB6560 Driver


TB6560  CLK+ to pin 5 on Arduino
TB6560 CW+ to pin 2 on Arduino
TB6560 EN+ to pin 8 on Arduino

TB6560 CLK- and CW- and EN-  to GND on Arduino



Schematic diagram Arduino with  Limit switch




Arduino Sketch


// defines pins numbers
const int stepPin = 5; 
const int dirPin = 2; 
const int enPin = 8;
const int limitPin = 7;
void setup() {

  pinMode(limitPin,INPUT);
  // Sets the two pins as Outputs
  pinMode(stepPin,OUTPUT); 
  pinMode(dirPin,OUTPUT);

  pinMode(enPin,OUTPUT);
  digitalWrite(enPin,LOW);
  
}
void loop() {
  
 if( digitalRead(limitPin) == HIGH){
    digitalWrite(stepPin,HIGH); 
    delayMicroseconds(500); 
    digitalWrite(stepPin,LOW); 
    delayMicroseconds(500); 
 }
  
}



ความคิดเห็น

แสดงความคิดเห็น