Arduino Stepper with Potentiometer Speed Control

in #arduino5 years ago (edited)


For my 3D printed turntable I obviously need some way to turn the turntable, and preferably for video and scanning, some method to control speed.

Fortunately, I have a whole box full of those cheap and ubiquitous stepper motors, the 28YBJ-48 plus the ULN2003 driver board.

These guys are 5v DC, the boards accept 5-12v, but each 28YBJ-48 motor can draw up to 320mA, so while initially you can use 5v, we will use external power attached to the 5-12v in, and ground attached to our battery pack and our Arduino.

To control the motor the stepper attaches to the driver board with 4 data lines and power. Our Arduino connects four pins, (3, 5, 4 and 6) to IN1-IN4 on the ULN2003 controller board.

Our potentiometer supplies an analog signal which we attach to A0, 3v and ground.

Code

Also find the code at this Gist

//Arduino stepper library
#include <Stepper.h>

// different steppers have different
// amount of steps to do a full
// turn of the wheel.
#define STEPS 32

// connections need to be done carefully
// In1-In4 are added in the sequence 1-3-2-4
Stepper stepper(STEPS, 3, 5, 4, 6);

// the number of steps to take
int numSteps;

// Only serial to setup here
void setup() {

  Serial.begin(115200); // start serial
  
}


// loop runs constantly
void loop() {

  // full revolution
  numSteps = (STEPS * 64) /100;

  // max power is 1024
  stepper.setSpeed( getMotorSpeed() );
  
  // take the steps
  // you can reverse direction with -numSteps
  stepper.step(-numSteps);
 

}

int getMotorSpeed() {

    // read the sensor value:
  int sensorReading = analogRead(A0);
  Serial.println(sensorReading);
  
  // map it to a range from 0 to 1024:
  int motorSpeed = map(sensorReading, 0, 769, 0, 1024);
  
  // set the motor speed:
  if (motorSpeed > 0) {
    return motorSpeed;
  }

}
  

https://www.instagram.com/p/BpVQfrRnBfr/


Posted from my blog with SteemPress : https://makerhacks.com/arduino-28ybj-48-uln2003-stepper-speed-control/

Sort:  

Nice to see someone as crazy as I am, ROFLOL! I LOVE your design, and it pays to be hard headed.

It looks good, keep posting, I would love to see the final product.

:)

Looks nice. Sou you want to take 360 videos of an object I suppose?
Btw: Why do you attach the potentiometer to 3V instead of 5V? The Arduino Mega is on 5V and so if you attach the poti to 3V you loose 2/5 of your possible range. Or do you use a 3V analog reference?

(ok sorry I just checked the map() function and you just define the analig input to only go to max 769 of the maximal 1023. With a 5V supply you could get a finer scale, but I guess you can't set it so precise with your hand anyways.)


This post was shared in the Curation Collective Discord community for curators, and upvoted and resteemed by the @c-squared community account after manual review.

Coin Marketplace

STEEM 0.25
TRX 0.11
JST 0.033
BTC 63014.19
ETH 3071.72
USDT 1.00
SBD 3.83