element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Design Challenges
  • Challenges & Projects
  • More
Design Challenges
Forum ROOKIE NEEDS HELP
  • Forum
  • Documents
  • Polls
  • Files
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Suggested Answer
  • Replies 5 replies
  • Answers 5 answers
  • Subscribers 7 subscribers
  • Views 894 views
  • Users 0 members are here
  • student
  • help!!
  • basic electronics
  • arduino projects
Related

ROOKIE NEEDS HELP

haydoc93
haydoc93 over 8 years ago

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!!!!!!!!!!image

  • Sign in to reply
  • Cancel

Top Replies

  • dougw
    dougw over 8 years ago +3 suggested
    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…
  • Former Member
    Former Member over 8 years ago in reply to dougw +3 suggested
    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…
  • awardautomation
    awardautomation over 8 years ago in reply to awardautomation +3 suggested
    you could of course write more elegant code by changing the setMotor function to have speed, forward and reverse parameters like this: setMotor(int speed, boolean forward, boolean reverse) { // you do…
  • dougw
    0 dougw over 8 years ago

    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.

    • Cancel
    • Vote Up +3 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • Former Member
    0 Former Member over 8 years ago in reply to dougw

    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.

    • Cancel
    • Vote Up +3 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • haydoc93
    0 haydoc93 over 8 years ago in reply to Former Member

    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

     

    image

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • awardautomation
    0 awardautomation over 8 years ago in reply to haydoc93

    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);

    }

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • awardautomation
    0 awardautomation over 8 years ago in reply to awardautomation

    you could of course write more elegant code by changing the setMotor function to have speed, forward  and reverse parameters

    like this:

    setMotor(int speed, boolean forward, boolean reverse)

    {

    // you do the rest

    }

    • Cancel
    • Vote Up +3 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube