Arduino help

dushan90

Active member
  • Jan 22, 2008
    811
    50
    28
    Diagon Alley
    Machan heat wenne motor eka HOLD wena nisa....ethakota current eka supply wenawa, motor eka ekama position eke hold karan innawa....ethakota thama rath wenne....
    ema nowenna nam free run wena widihata NO CURRENT wenna one...ema karana widihak balamu...
    Machan oya stepper ekata use karana library eka mokadda?
    Stepper.h kiyala ekak nemeida?
    Ow. stepper.step(0) dunnama e position eke hold karan innawa ekai heat wenne.


    Stepper.h library eka thama use karanne. Man euwa code eke udinma eka include karala thiyenne. Man hithanne ubata eka miss wenna athi.
     

    apikaluda?

    Active member
  • May 9, 2013
    438
    102
    43
    Ow. stepper.step(0) dunnama e position eke hold karan innawa ekai heat wenne.


    Stepper.h library eka thama use karanne. Man euwa code eke udinma eka include karala thiyenne. Man hithanne ubata eka miss wenna athi.


    E kella nane machan code eke:rofl:


    Machan circuit eka gahala thiyena widiha poddak sketch karala mekata daanna puluwannam...eke awulakda kiyala balanna
     

    dushan90

    Active member
  • Jan 22, 2008
    811
    50
    28
    Diagon Alley
    Machan circuit eke aulak nan


    Code:
    #include<Stepper.h>
    
    const int StepperStepPin = 4;
    const int StepperDirectionPin = 5;
    const int StepperMaxRPM = 900;
    const int ForwardLimitSwitchPin = 2;
    const int ReverseLimitSwitchPin = 7;
    const int LimitSwitchActivated = LOW;
    
    Stepper stepper(200, StepperStepPin, StepperDirectionPin);
    
    void setup() {
       pinMode(ForwardLimitSwitchPin, INPUT_PULLUP);
       pinMode(ReverseLimitSwitchPin, INPUT_PULLUP);
       stepper.setSpeed(StepperMaxRPM);
       
       
    }
    
    void loop() {
       // Step forward until the limit switch is activated
       while (digitalRead(ForwardLimitSwitchPin) != LimitSwitchActivated) {
           stepper.step(1);
       }
       // Step reverse until the limit switch is activated
       while (digitalRead(ReverseLimitSwitchPin) != LimitSwitchActivated) {
           stepper.step(-1);
       }
    }


    Meka aulak nathuwa wada karanna vidihak na neda?
     

    apikaluda?

    Active member
  • May 9, 2013
    438
    102
    43
    Machan circuit eke aulak nan


    Code:
    #include<Stepper.h>
    
    const int StepperStepPin = 4;
    const int StepperDirectionPin = 5;
    const int StepperMaxRPM = 900;
    const int ForwardLimitSwitchPin = 2;
    const int ReverseLimitSwitchPin = 7;
    const int LimitSwitchActivated = LOW;
    
    Stepper stepper(200, StepperStepPin, StepperDirectionPin);
    
    void setup() {
       pinMode(ForwardLimitSwitchPin, INPUT_PULLUP);
       pinMode(ReverseLimitSwitchPin, INPUT_PULLUP);
       stepper.setSpeed(StepperMaxRPM);
       
       
    }
    
    void loop() {
       // Step forward until the limit switch is activated
       while (digitalRead(ForwardLimitSwitchPin) != LimitSwitchActivated) {
           stepper.step(1);
       }
       // Step reverse until the limit switch is activated
       while (digitalRead(ReverseLimitSwitchPin) != LimitSwitchActivated) {
           stepper.step(-1);
       }
    }
    Meka aulak nathuwa wada karanna vidihak na neda?


    Ow machan...ekath emanam thamai:oo:mama balannam poddak hithala:rofl:
     

    apikaluda?

    Active member
  • May 9, 2013
    438
    102
    43
    Machan issellama buttons thuna balanna wei wage weda karana widiha awulda kiyala...ekata me code eka use karanna....
    Stepper eke okkoma one nam galawala ain karanna (reccommended). Code eke wisthara daala tiyenawa karana widihai balanna ona dewalui...e tika balala reply eka denna...apita meka iseella karala balanna thibbe...awulak ne den balamu....





    // Code is to check the correct operating conditions of the three buttons
    // ******REMOVE ALL CONNECTION TO STEPPER AND CONNECT ONLY THE PUSH BTN, 2 LIMIT SWITCHES*******
    //
    // connections are to be done as follows:
    // PUSH BUTTON > PIN 6
    // FORWARD LS > PIN 2
    // REVERSE LS > PIN 7
    //
    // THEN:
    // check for the following conditions using Serial Monitor
    //1) push only push button and check the states of all three buttons
    //2) push only Forward LS and check the states of all three buttons
    //3) push only Reverse LS and check the states of all three buttons
    //4) push (push button + Forward LS) and check the states of all three buttons
    //5) push (push button + Reverse LS) and check the states of all three buttons
    //6) push (Forward LS + Reverse LS) and check the states of all three buttons
    //7) push (push button + Forward LS + Reverse LS) and check the states of all three buttons

    //==========================================================================================
    const int ForwardLimitSwitchPin = 2; //forward LS pin
    const int ReverseLimitSwitchPin = 7; // reverse LS pin
    const int buttonPin = 6; // the number of the pushbutton pin (choose the correct pin here)


    void setup() {
    pinMode(ForwardLimitSwitchPin, INPUT_PULLUP); //declare two LS as inputs
    pinMode(ReverseLimitSwitchPin, INPUT_PULLUP);
    pinMode(buttonPin, INPUT); //declare push button signal as an input
    Serial.begin(9600); //Serial Monitoring ON
    Serial.println("Push button state\t\tForward LS State\t\tReverse LS State");
    }

    void loop() {
    Serial.print(digitalRead(buttonPin);
    Serial.print("\t\t\t\t\t\t\t\t");
    Serial.print(digitalRead(ForwardLimitSwitchPin));
    Serial.print("\t\t\t\t\t\t\t\t");
    Serial.println(digitalRead(ReverseLimitSwitchPin));
    }
    //==========================================================================================
     
    Last edited:

    dushan90

    Active member
  • Jan 22, 2008
    811
    50
    28
    Diagon Alley
    On karapu gaman mehema yanawa
    Code:
    Push button state        Forward LS State        Reverse LS State
    1                                1                                1
    0                                1                                1
    0                                1                                1
    0                                1                                1
    0                                1                                1
    0                                1                                1
    1                                1                                1
    1                                1                                1
    1                                1                                1
    1                                1                                1
    0                                1                                1
    0                                1                                1
    0                                1                                1
    0                                1                                1
    0                                1                                1
    0                                1                                1
    1                                1                                1
    1                                1                                1
    1                                1                                1
    1                                1                                1
    1                                1                                1
    On karala tikakin push button eka press kalama
    Code:
    Push button state        Forward LS State        Reverse LS State
    1                                1                                1
    0                                1                                1
    0                                1                                1
    0                                1                                1
    0                                1                                1
    0                                1                                1
    1                                1                                1
    1                                1                                1
    1                                1                                1
    1                                1                                1
    0                                1                                1
    0                                1                                1
    0                                1                                1
    0                                1                                1
    0                                1                                1
    0                                1                                1
    0                                1                                1
    0                                1                                1
    0                                1                                1
    0                                1                                1
    0                                1                                1
    0                                1                                1
    0                                1                                1
    On karala tikakin FLS press kalama
    Code:
    Push button state        Forward LS State        Reverse LS State
    0                                1                                1
    0                                1                                1
    0                                1                                1
    0                                1                                1
    0                                1                                1
    1                                1                                1
    1                                1                                1
    1                                1                                1
    1                                0                                1
    0                                0                                1
    0                                0                                1
    0                                0                                1
    0                                0                                1
    0                                0                                1
    0                                0                                1
    On karala tikakin RLS press kalama
    Code:
    Push button state        Forward LS State        Reverse LS State
    1                                1                                1
    0                                1                                1
    0                                1                                1
    0                                1                                1
    0                                1                                1
    0                                1                                1
    0                                1                                1
    0                                1                                1
    1                                1                                0
    1                                1                                0
    1                                1                                0
    1                                1                                0
    0                                1                                0
    Push button + FLS
    Code:
    Push button state        Forward LS State        Reverse LS State
    1                                1                                1
    1                                1                                1
    1                                1                                1
    1                                1                                1
    0                                0                                1
    0                                0                                1
    0                                0                                1
    0                                0                                1
    0                                0                                1
    0                                0                                1
    0                                0                                1
    0                                0                                1
    0                                0                                1
    Push button + RLS
    Code:
    Push button state        Forward LS State        Reverse LS State
    1                                1                                1
    1                                1                                1
    1                                1                                1
    1                                1                                1
    1                                1                                1
    0                                1                                1
    0                                1                                1
    0                                1                                1
    0                                1                                0
    0                                1                                0
    0                                1                                0
    0                                1                                0
    0                                1                                0
    0                                1                                0
    0                                1                                0
    0                                1                                0
    FLS + RLS
    Code:
    Push button state        Forward LS State        Reverse LS State
    1                                1                                1
    0                                1                                1
    0                                1                                1
    0                                1                                1
    0                                1                                1
    1                                1                                1
    1                                1                                1
    1                                1                                1
    1                                0                                0
    1                                0                                0
    1                                0                                0
    0                                0                                0
    0                                0                                0
    0                                0                                0
    0                                0                                0
    0                                0                                0
    0                                0                                0
    0                                0                                0
    1                                0                                0
    1                                0                                0
    1                                0                                0
    Push Button + FLS + RLS
    Code:
    Push button state        Forward LS State        Reverse LS State
    0                                1                                1
    1                                1                                1
    1                                1                                1
    0                                1                                1
    0                                1                                1
    0                                1                                1
    0                                0                                0
    0                                0                                0
    0                                0                                0
    0                                0                                0
    0                                0                                0
    0                                0                                0
    0                                0                                0
    0                                0                                0
     

    apikaluda?

    Active member
  • May 9, 2013
    438
    102
    43
    On karapu gaman mehema yanawa
    Code:
    Push button state Forward LS State Reverse LS State
    1 1 1
    0 1 1
    0 1 1
    0 1 1
    0 1 1
    0 1 1
    1 1 1
    1 1 1
    1 1 1
    1 1 1
    0 1 1
    0 1 1
    0 1 1
    0 1 1
    0 1 1
    0 1 1
    1 1 1
    1 1 1
    1 1 1
    1 1 1
    1 1 1


    Machan push button eke awulak thiyenawa. Mata penne button eka open (off mode - not pushed) ekedi FLOAT wenawa....e kiyanne button eka 0-1 value athare float wenawa. ethakota board eken e value eka round-off, e kiyanne agaya 0 or 1 kiyana aasanna agayata watayanawa. ekai push button value eka 0 - 1 athare maaru wenne.

    Machan ekata lesima de board eke internal pull-up resistor eka ON karana eka, eka karanne pinMode(buttonPin, INPUT_PULLUP); kiyala code eka wenas kalama hari.
    Code eka wenas kalama mehemai:


    // Code is to check the correct operating conditions of the three buttons
    // ******REMOVE ALL CONNECTION TO STEPPER AND CONNECT ONLY THE PUSH BTN, 2 LIMIT SWITCHES*******
    //
    // connections are to be done as follows:
    // PUSH BUTTON > PIN 6
    // FORWARD LS > PIN 2
    // REVERSE LS > PIN 7
    //
    // THEN:
    // check for the following conditions using Serial Monitor
    //1) push only push button and check the states of all three buttons
    //2) push only Forward LS and check the states of all three buttons
    //3) push only Reverse LS and check the states of all three buttons
    //4) push (push button + Forward LS) and check the states of all three buttons
    //5) push (push button + Reverse LS) and check the states of all three buttons
    //6) push (Forward LS + Reverse LS) and check the states of all three buttons
    //7) push (push button + Forward LS + Reverse LS) and check the states of all three buttons

    //==========================================================================================
    const int ForwardLimitSwitchPin = 2; //forward LS pin
    const int ReverseLimitSwitchPin = 7; // reverse LS pin
    const int buttonPin = 6; // the number of the pushbutton pin (choose the correct pin here)


    void setup() {
    pinMode(ForwardLimitSwitchPin, INPUT_PULLUP); //declare two LS as inputs
    pinMode(ReverseLimitSwitchPin, INPUT_PULLUP);
    pinMode(buttonPin, INPUT_PULLUP); //declare push button signal as an input
    Serial.begin(9600); //Serial Monitoring ON
    Serial.println("Push button state\t\tForward LS State\t\tReverse LS State");
    }

    void loop() {
    Serial.print(digitalRead(buttonPin);
    Serial.print("\t\t\t\t\t\t\t\t");
    Serial.print(digitalRead(ForwardLimitSwitchPin));
    Serial.print("\t\t\t\t\t\t\t\t");
    Serial.println(digitalRead(ReverseLimitSwitchPin));
    }
    //==========================================================================================



    Machan den wede balanna....hariyata states enna oni...enawanam ape code eka eeta passe hadaganna puluwan lesiyenma
     
    Last edited:

    apikaluda?

    Active member
  • May 9, 2013
    438
    102
    43
    Elakiri...enam den code eka weda karanna one pothe widihata...meka run karala balanna machan...

    #include<Stepper.h>
    const int ForwardLimitSwitchPin = 2; //pins for two LS
    const int ReverseLimitSwitchPin = 7;
    const int StepperStepPin = 4; //pins for Stepper control
    const int StepperDirectionPin = 5;
    const int buttonPin = 6; //pin for the Pushbutton

    const int StepperMaxRPM = 100;

    bool ispushbuttonpressed = false; //boolean to store push button logic (used to build the logics)
    int buttonState = 0; //state of the push button
    int codeSection = 0; //use to check code only (remove it once code is finalized!)
    Stepper stepper(200, StepperStepPin, StepperDirectionPin); //initialize stepper

    void setup() {
    pinMode(ForwardLimitSwitchPin, INPUT_PULLUP);
    pinMode(ReverseLimitSwitchPin, INPUT_PULLUP);
    pinMode(buttonPin, INPUT_PULLUP); //declare push button signal as an input
    stepper.setSpeed(StepperMaxRPM);
    }

    void loop() {
    buttonState = digitalRead(buttonPin); //update push button state
    if (buttonState == 0) { //push button is pressed
    ispushbuttonpressed = true;
    } else {
    ispushbuttonpressed = false;
    }

    // Run if push button is pressed && LS1 is not pressed - LOOP 1
    if ((ispushbuttonpressed == true) && (digitalRead(ForwardLimitSwitchPin) != 0)) {
    while (digitalRead(ForwardLimitSwitchPin) != 0) {
    stepper.step(1); //stepper steps forward
    }
    ispushbuttonpressed == false; //re-set to avoid motor turning backward once reached S2
    }
    // Run if push button is pressed && LS2 is not pressed - LOOP 2
    else if ((ispushbuttonpressed == true) && (digitalRead(ReverseLimitSwitchPin) != 0)) {
    while (digitalRead(ReverseLimitSwitchPin) != 0) {
    stepper.step(-1); //stepper steps reverse
    }
    ispushbuttonpressed == false; //re-set to avoid motor turning forward once reached S1
    }
    }
     
    Last edited: