SHARE
TWEET

Untitled

a guest Jul 18th, 2019 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Arduino MEGA+ A4988 stepper motor driver + L29383N+Stepper motor + dc motor + push button +3 limit switch //
  2. const int PB_PIN = 11; // push button pin
  3. const int LMT_1= 28; // Limit switch1 pin
  4. const int LMT_2= 29; // Limit switch2 pin
  5. const int LMT_3= 30; // Limit switch3 pin
  6. const int DIR_PIN=2; // Stepper moto dir pin
  7. const int STEP_PIN=3; // Stepper moto Step pin
  8. const int MOTA_A =7; // motor pin a
  9. Const in MOTA_B=8; // motor pin a
  10. Int buttonState=0;
  11.  
  12. Void setup(){
  13.     pinMode(PB_PIN,INPUT);
  14.     pinMode (LMT_1,INPUT);
  15.     pinMode (LMT_2,INPUT);
  16.     pinMode (LMT_3,INPUT);
  17.     pinMode (DIR_PIN,OUTPUT);
  18.     pinMode (STEP_PIN,OUTPUT);
  19.     pinMode (MOTA_A,OUTPUT);
  20.     pinMode (MOTA_B,OUTPUT);
  21. }
  22.  
  23. Void loop(){
  24.     buttonState=digitalRead(PB_PIN); //when push button pressed
  25.     if (buttonState == LOW) {
  26.         buttonState=digitalRead(LMT_1); //if motor is not on home point
  27.         if (buttonState == LOW) {
  28.             digitalWrite(DIR_PIN, HIGH);
  29.             digitalWrite(STEP_PIN, LOW);
  30.             buttonState=digitalRead(LMT_1); // when motor will come on home point
  31.             if (buttonState == HIGH) {
  32.                 breck
  33.             }
  34.         }
  35.         buttonState=digitalRead(LMT_1); // to move stepper motor forward
  36.         if (buttonState == HIGH) {
  37.             digitalWrite(DIR_PIN, LOW);
  38.             digitalWrite(STEP_PIN, HIGH);
  39.             buttonState=digitalRead(LMT_2); // stepper motor at second point
  40.             if (buttonState == HIGH) {
  41.                 digitalWrite(DIR_PIN, LOW);
  42.                 digitalWrite(STEP_PIN, LOW);
  43.                 digitalWrite(MOTA_A,HIGH); // run the dc motor
  44.                 digitalWrite(MOTA_B,LOW);
  45.                 dealy (10000);
  46.                 digitalWrite(MOTA_A, LOW); // off the dc motor
  47.                 digitalWrite(MOTA_B,LOW);
  48.                 digitalWrite(DIR_PIN, LOW); // stepper motor to move second 3rd point
  49.                 digitalWrite(STEP_PIN, HIGH);
  50.                 buttonState=digitalRead(LMT_3);
  51.                 if (buttonState == HIGH) { // stepper motor to back to home point
  52.                     digitalWrite(DIR_PIN, HIGH);
  53.                     digitalWrite(STEP_PIN, LOW);
  54.                     buttonState=digitalRead(LMT_1);
  55.                     if (buttonState == HIGH) {
  56.                         breck;
  57.                     }
  58.                 }
  59.             }
  60.         }
  61.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top