Arduino to motor to micrometer

Discussion in 'Electronics & Electrics' started by Lord Belial, Jul 26, 2018.

  1. Lord Belial

    Lord Belial Member

    Joined:
    Nov 25, 2002
    Messages:
    1,701
    Location:
    Perth
    Sorry if this is answered elsewhere but google-fu failed me. Am trying to use Arduino to control a motor that will be hooked up a manual lab stage (this one http://www.zolix.com.cn/en/prodcon_371_385_536.html) controlling one of the micrometers. This is an effort to get a cheap alternative to the motorised stages (about $4000).

    I have a freetronics experimenter's kit and have gone through all the exercises, which includes a little servo. Theoretically what I want to do seems easy but I need a motor that turns relatively slowly but fairly precisely. Even with code that increments the servo small amounts at a time it doesn't seem to be predictable. I also bought a little Tamiya motor+gearbox (https://www.jaycar.com.au/2-shaft-universal-motor-gearbox-set/p/YG2742) which seems to output at the speeds I want but I can't figure out how to hook up a transistor to have Arduino control it (tried directly powering it from the board but that's too weak). I have made a circuit using a transistor controlling a LED brightness (via PWM) but that doesn't seem to work for the motor. Do I need a motor shield?

    TLDR: how best to control a slow speed motor with arduino (for a dummy).
     
  2. aXis

    aXis Member

    Joined:
    Jun 27, 2001
    Messages:
    5,084
    Location:
    Kalgoorlie, WA
    100% this is the job for a stepper motor, which move in discrete steps rather than continuing to rotate at a speed. Typical ones have 200 steps per revolution and you can increase that about 4 - 16 times with microstepping.

    To drive the stepper motor you'll want a special stepper motor controller, these are very commonly available as an arduino compatible module for $5 - $10.

    Alternatively you can buy a RAMPS 1.4 kit which is an Arduino MEGA and then a large sheild which has 4 x stepper motor controllers onboard. These are on ebay for $20ish, it's ridiculous.
     
  3. OP
    OP
    Lord Belial

    Lord Belial Member

    Joined:
    Nov 25, 2002
    Messages:
    1,701
    Location:
    Perth
  4. aXis

    aXis Member

    Joined:
    Jun 27, 2001
    Messages:
    5,084
    Location:
    Kalgoorlie, WA
    It should work as a stepper motor kit but may not be ideal for you.

    - It's quite a small stepper motor with extra gear drive reduction, not sure if it has enough torque for you. It is effectively 4096 steps per output revolution, but is very slow at 2 seconds per revolution.
    - It's not a genuine stepper controller, just an array of transistors. You have to do a bunch of the stepping code yourself in software. Not too hard for someone with experience but will make things trickier for you.
     
  5. OP
    OP
    Lord Belial

    Lord Belial Member

    Joined:
    Nov 25, 2002
    Messages:
    1,701
    Location:
    Perth
  6. aXis

    aXis Member

    Joined:
    Jun 27, 2001
    Messages:
    5,084
    Location:
    Kalgoorlie, WA
    The controller you linked to is a quad H-Bridge drive. On those units you also have to implement the stepping sequence in software, and also have the correct type of stepper motor (usually bipolar). The motor you linked to is unipolar and could probably be made to work but would not be my first choice.

    If you dont mind blowing $10, try that first option you linked to. https://www.jaycar.com.au/arduino-compatible-5v-stepper-motor-with-controller/p/XC4458

    If you want to spend a bit more then these are great value, and they come with a more powerful arduino (MEGA) that is programmed the same way: https://www.ebay.com.au/itm/New-RAM...60-R3-CH340G-5x-A4988-2A-Drivers/161779736280
    And then get some NEMA style 4 lead stepper: https://www.ebay.com.au/itm/1-8-Deg...-Motor-For-3D-Printer-High-Quity/191880094916
     
    Last edited: Jul 27, 2018
  7. Dice

    Dice Member

    Joined:
    Feb 18, 2002
    Messages:
    164
    Location:
    Altona
    I have used a couple of a4988 drivers, an arduino nano, and nema stepper motors to control stepper mounted mirrors&laser combination.

    Very precise and predictable, and simple wiring/ software. The driver is around $1 on Aliexpress, the nano around $2.50, stepper motor $12. If you need more i/o then an uno or mega can be had for cheap too.

    From memory I supplied 12v to driver chip with a capacitor across 12VDC-GND, hooked 4 motor wires in (1A&1B, 2A&2B), and jumpered reset->sleep. There are two signals required from an arduino output - Direction and Step.
    I think Enable was also used to turn the chip on/off but not 100% on that one.

    You may want to add some form of limit switch so that the stepper can set to a known position on power-up - steppers don't have any form of encoding by default (open loop system). This may also prevent you breaking some valuable equipment, as steppers can have a surprising amount of torque.

    You may be able to use an L298N from jaycar, however I personally have not.
     
  8. OP
    OP
    Lord Belial

    Lord Belial Member

    Joined:
    Nov 25, 2002
    Messages:
    1,701
    Location:
    Perth
    Jesus, I need to do some reading because that last post is all Greek to me. I foolishly thought this would be a lot simpler than it is. Appreciate the input though, will re-read it once I've studied up :)

    Maybe I'll get that $10 cheapy from jaycar and learn the coding/wiring on it, bonus if it actually does what I need :D
     
  9. Dice

    Dice Member

    Joined:
    Feb 18, 2002
    Messages:
    164
    Location:
    Altona
    Sorry!

    the A4988 is a stepper motor driver - they're commonly used on the Ramps board that aXis was talking about, to control a 3d printer. It can be put on a breadboard by itself easily. Its just a small printed circuit board with a few bits and pieces on it.

    You set the direction you wish to turn (ie, put 5v on DIR for clockwise movement, or ground it for anticlockwise) by setting an arduino output High or Low.

    You then send a series for Step commands to the stepper driver - basically, a High followed by a Low means move one step.

    (The number of steps you need to move to turn a full circle depends on the motor and the driver, but it'll probably be around 200)
     
  10. aXis

    aXis Member

    Joined:
    Jun 27, 2001
    Messages:
    5,084
    Location:
    Kalgoorlie, WA
    I agree, those stepper drivers are easy to wire up and use. They also do a better job of driving the motor and have a microstepping feature that lets you move my smaller amounts. Not sure what precision you need with the micrometer but it may be handy.

    That said the Jaycar kit might be a cheap practice run to get the hang of steppers, then you can upgrade later.
     
  11. OP
    OP
    Lord Belial

    Lord Belial Member

    Joined:
    Nov 25, 2002
    Messages:
    1,701
    Location:
    Perth
    Not sure if there's a better place to post this but why is my for loop not ending? I wanted to experiment with pausing it after one rotation but it just keeps going. Have tried dropping the termination counter to 10 just to provoke it but doesn't stop.
    Code:
    int pin1 = 8; int pin2 = 9; int pin3 = 10; int pin4 = 11;
    int counter = 0;
    
    void setup() {
      pinMode(pin1, OUTPUT); pinMode(pin2, OUTPUT);
      pinMode(pin3, OUTPUT); pinMode(pin4, OUTPUT);
     }
    
    void loop() {
      for(counter = 0; counter = 4096; counter++){
      digitalWrite(pin1, HIGH); delay(2);
      digitalWrite(pin1, LOW); delay(2);
      digitalWrite(pin2, HIGH); delay(2);
      digitalWrite(pin2, LOW); delay(2);
      digitalWrite(pin3, HIGH); delay(2);
      digitalWrite(pin3, LOW); delay(2);
      digitalWrite(pin4, HIGH); delay(2);
      digitalWrite(pin4, LOW); delay(2);
      }
      delay(1000);
    }
    
    
    (there is probably a much more elegant way to do this but baby steps :))
     
  12. dakiller

    dakiller (Oscillating & Impeding)

    Joined:
    Jun 27, 2001
    Messages:
    7,577
    Location:
    Gippsland
    Your FOR loop is wrong, the counter = 4096 bit means that the loop never actually runs. That middle bit of the loop condition has to equal true for it to run. Use counter < 4096 instead.
     
  13. OP
    OP
    Lord Belial

    Lord Belial Member

    Joined:
    Nov 25, 2002
    Messages:
    1,701
    Location:
    Perth
    Ah cheers, this has been stuffing me up for ages! I read somewhere that the central part was the "terminating condition" and assumed it broke the loop once that was true.
     
  14. aXis

    aXis Member

    Joined:
    Jun 27, 2001
    Messages:
    5,084
    Location:
    Kalgoorlie, WA
    Yeah, a few more tips on that:
    1) A single equal "=" is an assignment. It sets one variable equal to another thing
    2) A double equal "==" is a comparison - compares two things and returns true or false.
    3) When you are testing two things, it's safer to use less than "<" / less than or equal "<=", because if something ever goes wrong with the variable value (eg memory error, cosmic ray bit flip etc) then it has more chance of still triggering the comparison when required.
     

Share This Page