Arduino help

apikaluda?

Active member
  • May 9, 2013
    438
    102
    43
    Serial monitor eke output eka ave mehemai

    Code:
    Push button state        Forward LS State        Reverse LS State        Code Section
    1            1            1            3
    1            1            1            3
    0            0            1            3




    Machan meka poddak buttons pysically on/off condition ekath ekka match karala ewanawada ?
    e kiyanne push button eka push kalama Push button state (me welawe anith 2 btns off)
    LS1 on kalama eke state(anith ewa off)


    me widihata ewanna puluwanda buttons conditons walata ewaye state wenas wena widiha?
    Den amaaru nam heta hari awulak ne...mama ekath ekka code eke awula hoyaganna balannam
     

    apikaluda?

    Active member
  • May 9, 2013
    438
    102
    43
    Code eke widihatanam motor eka run wenna CodeSetion variable eke agaya 1/2 wenna one...1 weddi btns wala agayan (state eka) monada? 2 weddi btns wala agayan monada?
     

    apikaluda?

    Active member
  • May 9, 2013
    438
    102
    43
    Therune na ne


    E kiwwe machan motor eka run weddi codeSection kiyana eke agaya Serial Monitor eke 1 hari 2 hari wenna one....
    Kalin ewapu reply eke Serial Monitor eke codeSection eke agaya okkoma 3 thibbe (code eke widihata me condition eke motor eka OFF wela thibba wenna one). 1/2 waladi thamai forward hari reverse hari yanne
     
    Last edited:

    apikaluda?

    Active member
  • May 9, 2013
    438
    102
    43
    Machan Seril Monitor eke values display wena widiha therune nettan me pic eka balanna...code eke hariyata values column head ekath ekka align wela nethi nisai hariyata hoyanna beri...eka code eke hadanna puluwan...eka loku case ekak nemei...hebei eka echchara wedagath ne...enisa ekata ottu wenna oni ne.


    meka balanna values balana widiha therei (therune nettan)

    Serial Monitor.jpg
     

    apikaluda?

    Active member
  • May 9, 2013
    438
    102
    43
    Code eke Serial Monitoring wala logics wala awulak ahuwuna machan (motor eka run wena loops waladi variable states monitor wena eka atherila thibbe)...eka correct kala:rofl: Ganan ganna epa...code eka run karanne nethuwane mama liyanne:rofl:



    const int ForwardLimitSwitchPin = 2;
    const int ReverseLimitSwitchPin = 3;
    const int StepperStepPin = 4;
    const int StepperDirectionPin = 5;
    const int LimitSwitchActivated = LOW; // Limit switch grounds pin
    const int StepperMaxRPM = 100;
    const int buttonPin = 6; // the number of the pushbutton pin (choose the correct pin here)
    bool ispushbuttonpressed = false; // Boolean to store push button logic
    int buttonState = 0; //**correction
    Stepper stepper(200, StepperStepPin, StepperDirectionPin);
    int codeSection = 0; //use to check code only (remove it once code is finalized!)

    void setup() {
    pinMode(ForwardLimitSwitchPin, INPUT_PULLUP);
    pinMode(ReverseLimitSwitchPin, INPUT_PULLUP);
    stepper.setSpeed(StepperMaxRPM);
    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\t\tCode Section");
    }

    void loop() {
    buttonState = digitalRead(buttonPin); // read push button on-off
    if (buttonState == LOW) { //**LOW (not HIGH)
    ispushbuttonpressed = true;
    }
    // Step forward until the limit switch is activated (forward rotating when hits S1) - LOOP 1
    if ((ispushbuttonpressed == true) && (digitalRead(ForwardLimitSwitchPin) != LimitSwitchActivated)) { //**corrections added
    codeSection = 1;
    while (digitalRead(ForwardLimitSwitchPin) != LimitSwitchActivated) {
    stepper.step(1);
    Serial.print(buttonState);
    Serial.print("\t\t\t");
    Serial.print(digitalRead(ForwardLimitSwitchPin));
    Serial.print("\t\t\t");
    Serial.print(digitalRead(ReverseLimitSwitchPin));
    Serial.print("\t\t\t");
    Serial.println(codeSection);
    }
    ispushbuttonpressed == false; //re-set to avoid motor turning backward once reached S2
    }

    // Step reverse until the limit switch is activated (forward rotating when hits S2) - LOOP 2
    else if ((ispushbuttonpressed == true) && (digitalRead(ReverseLimitSwitchPin) != LimitSwitchActivated)) { //**corrections added
    codeSection = 2;
    while (digitalRead(ReverseLimitSwitchPin) != LimitSwitchActivated) {
    stepper.step(-1);
    Serial.print(buttonState);
    Serial.print("\t\t\t");
    Serial.print(digitalRead(ForwardLimitSwitchPin));
    Serial.print("\t\t\t");
    Serial.print(digitalRead(ReverseLimitSwitchPin));
    Serial.print("\t\t\t");
    Serial.println(codeSection);
    }
    ispushbuttonpressed == false; //re-set to avoid motor turning backward once reached S1
    }

    Serial.print(buttonState);
    Serial.print("\t\t\t");
    Serial.print(digitalRead(ForwardLimitSwitchPin));
    Serial.print("\t\t\t");
    Serial.print(digitalRead(ReverseLimitSwitchPin));
    Serial.print("\t\t\t");
    Serial.println(codeSection);
    }
     

    dushan90

    Active member
  • Jan 22, 2008
    811
    50
    28
    Diagon Alley
    Machan oka run kalama motor eka step by step wage (hena himin) rotate wenawa on karapu wele idan. ForwardLimitSwitch press kalama e speed eken ma anik paththata rotate wenawa. ReverseLimitSwitch eka wath Push button eken wath mokuth wenne na.
     

    dushan90

    Active member
  • Jan 22, 2008
    811
    50
    28
    Diagon Alley
    Monitor eke enne mehema
    Code:
    Push button state        Forward LS State        Reverse LS State        Code Section
    
    0            1            1            1
    0            1            1            1
    0            1            1            1
    0            1            1            1
    0            1            1            1
    0            1            1            1
    0            1            1            1
    0            1            1            1
    0            1            1            1
    0            1            1            1
    0            1            1            1
    0            1            1            1
    0            1            1            1
    0            1            1            1
    0            1            1            1
    0            1            1            1
    0            1            1            1
    0            1            1            1
    0            1            1            1
    0            1            1            1
    0            1            1            1
    0            1            1            1
    0            1            1            1
    0            1            1            1
    0            1            1            1
    0            1            1            1
    0            1            1            1
    0            1            1            1
    0            1            1            1
    0            1            1            1
    0            1            1            1
    0            1            1            1
    0            1            1            1
    0            0            1            1
    1            0            1            2
    1            0            1            2
    1            0            1            2
    1            0            1            2
    1            0            1            2
    1            0            1            2
    1            0            1            2
    1            0            1            2
    1            0            1            2
    1            0            1            2
    1            0            1            2
    1            0            1            2
    1            0            1            2
    1            0            1            2
    1            0            1            2
    1            0            1            2
    1            0            1            2
    1            1            1            2
    1            1            1            2
    1            1            1            2
    1            1            1            2
    1            1            1            2
    1            1            1            2
    1            1            1            2
    1            1            1            2
    1            1            1            2
    1            1            1            2
    1            1            1            2
    1            1            1            2
    1            1            1            2
    1            1            1            2
    1            1            1            2
    1            1            1            2
    1            1            1            2
    1            1            1            2
    1            1            1            2
    1            1            1            2
    1            1            1            2
    1            1            1            2
    1            1            1            2
    1            1            1            2
    1            1            1            2
    1            1            1            2
    1            1            1            2
    1            1            1            2
    1            1            1            2
    1            1            1            2
    1            1            1            2
    1            1            1            2
    1            1            1            2
    1            1            1            2
    1            1            1            2
    1            1            1            2
    1            1            1            2
    1            1            1            2
    1            1            1            2
    1            1            1            2
    1            1            1            2
    1            1            1            2
    1            1            1            2
    1            1            1            2
    1            1            1            2
    1            1            1            2
    1            1            1            2
    1            1            1            2
    1            1            1            2
    1            1            1            2
    1            1            1            2
     1            1            1            2
    Issellama ReverseLimitSwitch eka, passe Push Button eka, anthimata ForwardLimitSwitch eka press kale.
     

    dushan90

    Active member
  • Jan 22, 2008
    811
    50
    28
    Diagon Alley
    Machan Seril Monitor eke values display wena widiha therune nettan me pic eka balanna...code eke hariyata values column head ekath ekka align wela nethi nisai hariyata hoyanna beri...eka code eke hadanna puluwan...eka loku case ekak nemei...hebei eka echchara wedagath ne...enisa ekata ottu wenna oni ne.


    meka balanna values balana widiha therei (therune nettan)

    View attachment 74783


    Meka read karana hati mata theruna machan
     

    apikaluda?

    Active member
  • May 9, 2013
    438
    102
    43
    Machan buttons press karaddi anik deka press nethuwa nikanma neda tibbe? kisima welawaka buttons dekak ekawara press kale ne neda?
     

    apikaluda?

    Active member
  • May 9, 2013
    438
    102
    43
    machan buttons wala connections harida manda....mama ekanam beluwe ne machan....eka poddak balanna wei wage mata pena widiata


    mokada logics walata wada outputs wenasne...:baffled:

    eka poddak balamu api issella...mamath balannam
     

    dushan90

    Active member
  • Jan 22, 2008
    811
    50
    28
    Diagon Alley
    Ammatasiri wenawa... Arduino eke pin 3 wada na kiyahanko!!! Man dan eka 7 walata maru kala. Dan nan directions maru wenawa. Button ekai limit switches 2i wada machan.
     

    dushan90

    Active member
  • Jan 22, 2008
    811
    50
    28
    Diagon Alley
    Code eka wenas kala machan mehema


    Code:
    #include<Stepper.h>
    
    const int ForwardLimitSwitchPin = 2;
    const int ReverseLimitSwitchPin = 7;
    const int StepperStepPin = 4;
    const int StepperDirectionPin = 5;
    const int LimitSwitchActivated = LOW; // Limit switch grounds pin
    const int StepperMaxRPM = 600;
    const int buttonPin = 6; // the number of the pushbutton pin (choose the correct pin here)
    bool ispushbuttonpressed = false; // Boolean to store push button logic
    int buttonState = 0; //**correction
    Stepper stepper(200, StepperStepPin, StepperDirectionPin);
    int codeSection = 0; //use to check code only (remove it once code is finalized!)
    
    void setup() {
    pinMode(ForwardLimitSwitchPin, INPUT_PULLUP);
    pinMode(ReverseLimitSwitchPin, INPUT_PULLUP);
    stepper.setSpeed(StepperMaxRPM);
    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\t\tCode Section");
    }
    
    void loop() {
    buttonState = digitalRead(buttonPin); // read push button on-off
    if (buttonState == LOW) { //**LOW (not HIGH)
    ispushbuttonpressed = true;
    }
    // Step forward until the limit switch is activated (forward rotating when hits S1) - LOOP 1
    if ((ispushbuttonpressed == true) && (digitalRead(ForwardLimitSwitchPin) != LimitSwitchActivated)) { //**corrections added
    codeSection = 1;
    while (digitalRead(ForwardLimitSwitchPin) != LimitSwitchActivated) {
    stepper.step(1);
    Serial.print(buttonState);
    Serial.print("\t\t\t");
    Serial.print(digitalRead(ForwardLimitSwitchPin));
    Serial.print("\t\t\t");
    Serial.print(digitalRead(ReverseLimitSwitchPin));
    Serial.print("\t\t\t");
    Serial.println(codeSection);
    }
    ispushbuttonpressed == false; //re-set to avoid motor turning backward once reached S2
    }
    
    // Step reverse until the limit switch is activated (forward rotating when hits S2) - LOOP 2
    else if ((ispushbuttonpressed == true) && (digitalRead(ReverseLimitSwitchPin) != LimitSwitchActivated)) { //**corrections added
    codeSection = 2;
    while (digitalRead(ReverseLimitSwitchPin) != LimitSwitchActivated) {
    stepper.step(-1);
    Serial.print(buttonState);
    Serial.print("\t\t\t");
    Serial.print(digitalRead(ForwardLimitSwitchPin));
    Serial.print("\t\t\t");
    Serial.print(digitalRead(ReverseLimitSwitchPin));
    Serial.print("\t\t\t");
    Serial.println(codeSection);
    }
    ispushbuttonpressed == false; //re-set to avoid motor turning backward once reached S1
    }
    
    Serial.print(buttonState);
    Serial.print("\t\t\t");
    Serial.print(digitalRead(ForwardLimitSwitchPin));
    Serial.print("\t\t\t");
    Serial.print(digitalRead(ReverseLimitSwitchPin));
    Serial.print("\t\t\t");
    Serial.println(codeSection);
    }
     

    apikaluda?

    Active member
  • May 9, 2013
    438
    102
    43
    Ammatasiri wenawa... Arduino eke pin 3 wada na kiyahanko!!! Man dan eka 7 walata maru kala. Dan nan directions maru wenawa. Button ekai limit switches 2i wada machan.


    :lol::lol::lol::lol: ekiyanne wede godada?? hithuwa widihata wedada? nettan thawa awul thiyenawada monaahari? kiyannako balanna:rofl::rofl:
     

    dushan90

    Active member
  • Jan 22, 2008
    811
    50
    28
    Diagon Alley
    Result eka mekai machan


    Code:
    Push button state        Forward LS State        Reverse LS State        Code Section
    
    0            1            1            1
    0            1            1            1
    0            1            1            1
    0            1            1            1
    0            1            1            1
    0            1            1            1
    0            1            1            1
    0            1            1            1
    0            0            1            1
    0            0            1            2
    0            0            1            2
    0            0            1            2
    0            0            1            2
    0            0            1            2
    0            0            1            2
    0            0            1            2
    0            0            1            2
    0            0            1            2
    0            0            1            2
    0            0            1            2
    0            0            1            2
    0            0            1            2
    0            0            1            2
    0            0            1            2
    0            0            1            2
    0            1            1            2
    0            1            1            2
    0            1            1            2
    0            1            1            2
    0            1            1            2
    0            1            1            2
    0            1            1            2
    0            1            1            2
    0            1            1            2
    0            1            1            2
    0            1            1            2
    0            1            1            2
    0            1            1            2
    0            1            1            2
    0            1            1            2
    0            1            1            2
    0            1            1            2
    0            1            1            2
    0            1            1            2
    0            1            1            2
    0            1            0            2
    1            1            0            1
    1            1            0            1
    1            1            0            1
    1            1            0            1
    1            1            0            1
    1            1            0            1
    1            1            0            1
    1            1            0            1
    1            1            0            1
    1            1            0            1
    1            1            0            1
    1            1            0            1
    1            1            0            1
    1            1            0            1
    1            1            0            1
    1            1            0            1
    1            1            0            1
    1            1            0            1
    1            1            0            1
    1            1            0            1
    1            1            0            1
    1            1            0            1
    1            1            0            1
    1            1            1            1
    1            1            1            1
    1            1            1            1
    1            1            1            1
    1            1            1            1
    1            1            1            1
    1            1            1            1
    1            1            1            1
    1            1            1            1
    1            1            1            1
    1            1            1            1
    1            1            1            1
    1            1            1            1
    1            1            1            1
    1            1            1            1
    1            1            1            1
    1            1            1            1
    1            1            1            1
    1            1            1            1
    1            1            1            1
     1            1            1


    Arduino eka on karapu gaman ma eka direction ekakata karakenna gaththa. Pin 2 eke button eka press kalama direction eka maru una. Pin 7 press kalama aye direction maru una. Pin 6 ekata mokuth une na.