element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • 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
  • 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
Arduino
  • Products
  • More
Arduino
Arduino Forum Stepper motor wiring help(and a few other small questions from an instructable)
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Suggested Answer
  • Replies 55 replies
  • Answers 1 answer
  • Subscribers 395 subscribers
  • Views 4480 views
  • Users 0 members are here
  • wiring
  • steppers
  • arduino
Related

Stepper motor wiring help(and a few other small questions from an instructable)

gub11
gub11 over 9 years ago

This instructable really interested me, Frameless Laser Harp - 4 , but i've never worked with steppers before.  the stepper i got has 4 wires, but the stepper in the instructable has 6.  on page 2 there is a wiring guide, but that wasn't very helpful to me, i didn't really understand what i'm supposed to do with the wires.  This is the stepper i have, https://www.sparkfun.com/products/10551?gclid=Cj0KEQiApruyBRCFqoDu1pbk9rkBEiQAF8EFdVmEBorGt6koPmFkaibEpRmZ94Z6r8BWhmTqAL… .  Any ideas?

  • Sign in to reply
  • Cancel

Top Replies

  • Robert Peter Oakes
    Robert Peter Oakes over 9 years ago in reply to gub11 +2 suggested
    reverse... to change direction lol now more seriously... then you wire up the stepper motor, if it is not going in the direction you expect for the command your giving then you can change the code or simply…
  • Robert Peter Oakes
    Robert Peter Oakes over 9 years ago +1
    Here is an excelent resource regarding steppers and how they work http://www.geckodrive.com/support.html I found this to be very helpfull in setting up my CNC project your stepper is a classic 4 wire …
  • Robert Peter Oakes
    Robert Peter Oakes over 9 years ago in reply to gub11 +1
    All Grounds (0V) should go together, the ground of the 12V, the 5V etc all are connected together at a common point the 5V goes to all those pins because it is 5V logic input to the chip and those pins…
  • Robert Peter Oakes
    0 Robert Peter Oakes over 9 years ago in reply to gub11

    There all about the CNC Project, if you simply go to https://youtube.com/c/thebreadboardca and look at the video list it may be easier to understand as the descriptions are there along with suitable images

     

    btw, the video is almost completed uploading and will be available in a few minutes https://youtu.be/pSJQWe5iGn0

     

    I will post a formal blog entry tomorow with code and everything and embed the video

     

    for now, here is the final code so you can try it and let me know if it works

     

    Enjoy


    #include <Stepper.h>
    
    
    const int stepsPerRevolution = 48;  // change this to fit the number of steps per revolution
    // for your motor
    
    
    // initialize the stepper library on pins 8 through 11:
    int motorPinA = 8;                      //Winding A.
    int motorPina = 9;                      //Winding a.
    int motorPinB = 10;                     //Winding B.
    int motorPinb = 11;                     //Winding b.
    int rpms = 300;                         // Revolutions per minute  for stepper 300/60 = 5 revs per second = 240 steps per second = about 25 scans per second
    Stepper myStepper(stepsPerRevolution, motorPinA, motorPina, motorPinB, motorPinb);
    
    
    int StepSize = 1;
    
    
    int LaserState = LOW;                    // The variable that stores the state of the laser beam.
    int sensor = 8 ;                         // Change this value to calibrate your harp's sensor
    int delaylaser = 3;                     // If you increase this, the laser will be brighter, but the harp will be less fluid
    int delaymotor = 3;                     // This variable affects the speed, and fluidity of the harp.
    
    int LaserPin =  7;                       // Tell the arduino that the laser is on pin 7
    
    int notes[] = {0x47, 0x40, 0x71, 0x70, 0x68, 0x66, 0x64, 0x53, 0x61 };
    int notesState[] = {0x0, 0x00, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 };
    int arraySize = sizeof( notes )/ sizeof( notes[0]);
    int cmd = 0x90;
    int VelocityOn = 0x7F;
    int VelocityOff = 0x00;
    
    
    void setup()
    {
      pinMode(LaserPin, OUTPUT);            // Setup for laser.
      pinMode(13, OUTPUT);                 // Setup for status led.
      Serial.begin(31250);                 //  Start a serial communication channel for MIDI
    
    
      myStepper.setSpeed(rpms);
    }
    
    
    void loop()
    {
    
    
      // we will do note 0 to keep things consistant at th end of the loop
      //SenseLaser(0)                               // note 1 (Array is zero based)
    
    
    for (int counter = 0 ; counter < arraySize ; counter++)
    {
      myStepper.step(1);                          // Step the stepper ++
      //delay(delaymotor);                          // Small pause, may not be needed ??
      SenseLaser(counter);                        // note counter
    }
    
    
    for (int counter = arraySize-1 ; counter >= 0  ; counter--)
    {
      myStepper.step(-1);                          // Step the stepper ++
      //delay(delaymotor);                          // Small pause, may not be needed now
      SenseLaser(counter);                        // note counter
    }
    
    
      // Back to top.
    }
    
    
    void SenseLaser(int index)
    {
      digitalWrite(LaserPin, HIGH);               // Turn on the laser for the 1st beam.
      delay(delaylaser);
    
    
      if (analogRead(0) > sensor )
      {
        noteOn(index);
      }
      else if (analogRead(0) < sensor )            // If the sensor does not get a signal:
      {
        noteOff(index);
      }
      digitalWrite(LaserPin, LOW);                // Turn off the Laser.
    }
    
    
    void noteOn( int pitchindex)     // Function to play the notes
    {
    
    
      if (  notesState[pitchindex] == 0) // If the sensor gets a signal, and the not is not playing:
      {
        Serial.write(cmd);
        Serial.write(notes[pitchindex]);
        Serial.write(VelocityOn);
        notesState[pitchindex]++;                          // Change the status variable to one.
        digitalWrite(13, HIGH);       // Switch on status led.
      }
    }
    void noteOff( int pitchindex)     // Function to play the notes
    {
      if (  notesState[pitchindex] > 0) // If the sensor does not get a signal, and the not is playing:
      {
      Serial.write(cmd);
      Serial.write(notes[pitchindex]);
      Serial.write(VelocityOff);
      notesState[pitchindex] = 0;                        // Change the status variable to 0.
      digitalWrite(13, LOW);       // Switch off status led.
      }
    }

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • gub11
    0 gub11 over 9 years ago in reply to Robert Peter Oakes

    Robert Peter Oakes

    The Code runs, but I'm having the same issue, the stepper is stepping, but with long pauses in between steps.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Robert Peter Oakes
    0 Robert Peter Oakes over 9 years ago in reply to gub11

    try putting this parameter to a smaller value like 50 or something

     

    int rpms = 300;


    this may see if the stepper is simply not fast enough, I dont have the chip or a stepper like yours to try so cant verify that


    I have plenty of large steppers but again, not he same as yours


    If you slow down the steps using the above parameter enough, you could place LEDs on the output of the arduino and ensure the sequence ir sight, I did that here and it looks good to me, You can also check the stepper connection from the chip to stepper with a DMM and verify the voltages are changing are of a correct value.  If you have two DMMs then you can verify the actual sequence is correct to the stepper windngs and that the voltages are reversing etc.

    outside of that, im not sure what else I can do as you have verified you wiring, the code now is correct as best I can see so unless your chip is getting really hot for some reason, it should be working


    Regards

    Peter

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Robert Peter Oakes
    0 Robert Peter Oakes over 9 years ago in reply to Robert Peter Oakes

    Ah, one thing I forgot to also mention and it may be important. ( I am so used to them being there I completly missed the fact they were not there)

     

    Decoupling capacitors on the supply rails near the chip for both the +5V and the 12V.

     

    I dont see any on your board and there essential for reliable operation

     

    looking at this circuit from TI it clearly shows them, and the value required

    image

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • gub11
    0 gub11 over 9 years ago in reply to Robert Peter Oakes

    I'll test that out when I get home, i think i have two .1μF at my bench from something else, so that's convenient.  If it helps, here is the datasheet for my stepper  http://cdn.sparkfun.com/datasheets/Robotics/ST-PM35-15-11C.pdf .  What do the capacitors do in this case, I mean I know what capacitors do in general, but why would they make a difference here?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • gub11
    0 gub11 over 9 years ago in reply to Robert Peter Oakes

    Robert Peter Oakes

    The capacitors I have at home are ceramic caps.  Would these work? HQ 1uF 50V Aluminum Radial Electrolytic Decoupling Capacitors Pack of 20 | eBay

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • gub11
    0 gub11 over 9 years ago in reply to gub11

    Robert Peter Oakes

    Those should work for the 1μF caps, but I can't find any .1μF decoupling caps, could you link me some?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Robert Peter Oakes
    0 Robert Peter Oakes over 9 years ago in reply to gub11

    yup, should be good

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Robert Peter Oakes
    0 Robert Peter Oakes over 9 years ago in reply to gub11

    try finding some 100nF instead, you should find thouse and they will do instead of the 0.1uF

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • gub11
    0 gub11 over 9 years ago in reply to Robert Peter Oakes

    Robert Peter Oakes
    I can't find any of those either, maybe i'm being too specific.  can u send me a link?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify 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