5 Replies Latest reply on May 20, 2017 9:20 AM by awardautomation

    ROOKIE NEEDS HELP

    haydoc93

      HI all,

       

      I'm in the process of building a model crane,

      i'm using an arduino with a motor control IC to operate three motors separately along with a 10K potentiometer to adjust the rotational speed,

       

      !! What i'm having trouble with is !!

       

      I have  a 4P3T Slide switch that i want to wire up as FORWARD/OFF/REVERSE, but i have no idea what im doing i have a circuit diagram of this from the interwebs but still no clue on what to do,

      any help would be greatly appreciated

       

      THANK YOU!!!!!!!!!!SWITCH.jpg

        • Re: ROOKIE NEEDS HELP
          dougw

          There are 4 switches with 3 positions each where all 4 switches have an A position a B position and a C position.

          Since they are all on the same lever all 4 switches are in the A position at the same time or all in the B position or all in the C position.

          There is one switch in each corner and its 3 positions are represented by an A-B-C.

          The drawing shows which contacts are shorted in the A position with a solid line.

          The contacts that are shorted in the other 2 positions are shown with dotted lines.

          To reverse a single motor you need a 6 3-position switches, so it will be tricky to use this switch to independently reverse 3 motors.

          It can do 2 motors easily.

          Make the B position the OFF position.

          The wiper of switch 1 (the long contact in the drawing is the wiper contact) goes  to one motor terminal.

          The wiper of switch 2 goes to the second motor terminal

          The A terminal of switch 1 and the C terminal of switch 2 are connected to the PWM signal

          The C terminal of switch 1 and the A terminal of switch 2 are connected to ground.

          The same scheme on switches 3 and 4 will handle a second motor.

          5 of 5 people found this helpful
            • Re: ROOKIE NEEDS HELP
              ejlane

              That is an awful lot of extra hardware complication, if there's already an arduino providing full control.

               

              Is there a reason you're avoiding simply using the slide switch to provide an input to the arduino and then reversing the motors in software? You've already got plenty of processing power there, why not take advantage of it? It would just add a few microseconds here or there.

               

              Maybe I'm missing something, but at least how it sounded to me, I would just do that. You could also set it up so the whole thing was not powered on at all in the middle switch position, or have the arduino simply stop the motors and go into sleep mode, depending on the specifics of your project.

              2 of 2 people found this helpful
                • Re: ROOKIE NEEDS HELP
                  haydoc93

                  The idea is to use the arduino to swap the direction of the motors

                   

                  i have this code from an adafruit tutorial i was just going to expand on it for the other two motors

                   

                  /* Adafruit Arduino - Lesson 15. Bi-directional Motor */

                   

                  int enablePin = 11;

                  int in1Pin = 10;

                  int in2Pin = 9;

                  int switchPin = 7;

                  int potPin = 0;

                   

                  void setup() {  pinMode(in1Pin, OUTPUT);

                  pinMode(in2Pin, OUTPUT);

                  pinMode(enablePin, OUTPUT);

                  pinMode(switchPin, INPUT_PULLUP); }

                   

                  void loop() {  int speed = analogRead(potPin) / 4;

                  boolean reverse = digitalRead(switchPin);

                  setMotor(speed, reverse); }

                   

                  void setMotor(int speed, boolean reverse) {  analogWrite(enablePin, speed);

                  digitalWrite(in1Pin, ! reverse);

                  digitalWrite(in2Pin, reverse); }

                   

                  this is how they have set it up, i just want to use a 3 position switch so i had on/off/on or forward/off/reverse

                   

                  example.png

                  3 of 3 people found this helpful
                    • Re: ROOKIE NEEDS HELP
                      awardautomation

                      Hi Hayden
                      That L293D chip can already reverse the direction of your motor.
                      So your 3 position switch could be connected in place of your pushbutton.
                      That way the reversing would be done through the arduino program according to the position of the switch.


                      In this case you only need to use one pole, or one corner of the switch (lets say switch one)

                      You connect GND to the wiper of switch one (terminal B)

                      connect Arduino pin 7 to terminal A

                      connect Arduino pin 6 to terminal C

                       

                      Then modify you code so that:

                         it runs the motor in forward if pin 7 is pulled low,

                         runs in reverse if pin 6 is pulled low.

                         sets the speed to zero if neither pin is pulled low

                       

                      The code should look something like this

                       

                      /* Adafruit Arduino - Lesson 15. Bi-directional Motor */

                       

                      int enablePin = 11;

                      int in1Pin = 10;

                      int in2Pin = 9;

                      int forwardPin = 7;

                      int reversePin = 6;

                      int potPin = 0;

                       

                      void setup() {

                        pinMode(in1Pin, OUTPUT);

                        pinMode(in2Pin, OUTPUT);

                        pinMode(enablePin, OUTPUT);

                        pinMode(forwardPin, INPUT_PULLUP);

                        pinMode(reversePin, INPUT_PULLUP);

                      }

                       

                      void loop() {

                        int speed = analogRead(potPin) / 4;

                        boolean runForward = digitalRead(forwardPin);

                        boolean runBackward = digitalRead(backwardPin);

                       

                      if (runForward)

                      {

                        setMotor(speed, 0); // this should set in1Pin high and in2pin low

                      }

                      elseif (runBackward)

                      {

                        setMotor(speed, 1); // this should set in2Pin high and in1Pin low

                      }

                      else

                        setMotor(0, 0);  // the motor needs to be stopped - write the speed as zero

                      }

                      }

                       

                      void setMotor(int speed, boolean reverse)

                        analogWrite(enablePin, speed);

                        digitalWrite(in1Pin, ! reverse);

                        digitalWrite(in2Pin, reverse);

                      }

                      3 of 3 people found this helpful