Welcome to the Tweaking4All community forums!
When participating, please keep the Forum Rules in mind!
Topics for particular software or systems: Start your topic link with the name of the application or system.
For example “MacOS X – Your question“, or “MS Word – Your Tip or Trick“.
Please note that switching to another language when reading a post will not bring you to the same post, in Dutch, as there is no translation for that post!
not sure if anyone else will chime in. My experience with stepper motors is pretty much zero, but maybe I can assist in getting you in the right direction.
I assume you would to use a potentiometer (variable resistor) to set the speed?
Note: I have written an article once on how to use an LDR (light sensitive resistor), in which I do talk a little bit about a potentiometer as well. May be a good additional read.
In short: We will use A0 for reading the analog value of the potentiometer. We need to connect GND and +5V to the potentiometer as illustrated - you can swap +5 and GND on the potentiometer - it will just change its behavior from ascending to descending and vice versa (R1 and R2).
Next we need to read the value of pin A0 in our code:
int potentiometerValue;
...
potentiometerValue = analogRead(A0);
...
For this to be "responsive" (respond in a timely fashion) our code will need to read this value very frequently (in loop()).
Based on the value we get from A0, we need to slow down the original code. I see a few potential spots, and either way we will use the "delay()" function.
When the motor runs at its highest speed, you want a delay of "1". At its slowest speed this should be a higher value, but what that value should be, depends on your application of course. The value from the analog pin is between 0 and 1024. So this could translate to 0-1024 milliseconds delay for slowing down the rotation - which could be fine (1000 milliseconds = 1 second).
If you would like to use a different range, then you could use the "map" function, which takes an input value, inputrange and outputrange. So lets say you wanted a 0 - 199 range, derived from the values we just read (0-1023) then this could be done like so:
While trying to find you an answer, I did run into this stepper speed control example on the Arcuino website. You may want to look at that one since it is using a potentiometer and a stepper motor - it even has a nice library (stepper.h) which may mike life easier.
Their code:
/*
Stepper Motor Control - speed control
by Tom Igoe
*/
#include <Stepper.h>
const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution for your motor
// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);
int stepCount = 0; // number of steps the motor has taken
void setup() {
// nothing to do inside the setup
}
void loop() {
// read the sensor value:
int sensorReading = analogRead(A0);
// map it to a range from 0 to 100:
int motorSpeed = map(sensorReading, 0, 1023, 0, 100);
// set the motor speed:
if (motorSpeed > 0) {
myStepper.setSpeed(motorSpeed);
// step 1/100 of a revolution:
myStepper.step(stepsPerRevolution / 100);
}
}
Visualping Great website if you like to track website changes when changes occur (hourly, daily, weekly).
Start-is-Back Ultimate Start-button replacement for Windows 8 and 8.1 - Super cheap, but highly recommended.
Animizer Animizer.net provides complete online toolbox for animations (GIF and APNG) - Edit, Assemble, Split or Convert, it's all there.
OpenElec The ultimate XBMC distribution. No operating system required, comes completely in a compact form with Embedded Linux, for Intel, AMD, AppleTV, Raspberry Pi, etc.
RegExr Awesome website to play and experiment with regular expression!
Links Page These and more of our favorite links can be found on the Links Page.
New Downloads
ConnectMeNow4-v4.0.18-macOS-x86-64.dmgDate: 2024-04-24 - Size: 3.5 MBVersion 4 of ConnectMeNow - A tool for more convenient mounting of network shares under macOS. This is the Intel version which works on Intel and Apple Silicon Macs.
ConnectMeNow4-v4.0.18-macOS-arm64.dmgDate: 2024-04-24 - Size: 3 MBVersion 4 of ConnectMeNow - A tool for more convenient mounting of network shares under macOS. This is the Apple Silicon version (not suitable for Intel).
MiniWOL2 MacOS (64 bits Apple Silicon)Date: 2023-08-01 - Size: 1.2 MBminiWol is a simple, but effective application to send Wake On LAN to network devices. This is the signed 64 bit MacOS ARM (Apple Silicon) version.
MovieScanner2-2.2.3-Windows-32bit-setup.exeDate: 2023-04-12 - Size: 18.6 MBA small application that uses FFProbe to scan your video files and logs these details in a small database. This is the 32 bit Windows version.
MovieScanner2-2.2.2-Linux-GTK-64bits.tar.gzDate: 2023-04-11 - Size: 29.2 MBA small application that uses FFProbe to scan your video files and logs these details in a small database. This is the 64 bit Linux version for GTK.
MovieScanner2-2.2.2-Linux-QT5-64bits.tar.gzDate: 2023-04-11 - Size: 29.1 MBA small application that uses FFProbe to scan your video files and logs these details in a small database. This is the 64 bit Linux version for QT5.
Downloads Page Find these and more Downloads on the Downloads Page, where you will also find articles references, operating system requirements and categories.
Amazon Ads
Support us by doing your shopping at Amazon.com, either click the link, or click one of the links below …
You can also sponsor us through these Amazon offerings:
Please consider disabling your ad blocker for our website.We rely on these ads to be able to run our website.You can of course support us in other ways (see Support Us on the left).