Hello. I am new on arduino. I thought it is so easy, but it isn't. I am useing Arduino UNO and Adafruit Motor Shield V1. I have a problem by control stepper motor by potentiometr. I want the motor to increase speed as the value on the potentiometer increases. At the moment the motor turns at one speed only when moving the potentiometer. I check many code's and I programed on visuino but neither works just I want.
#include <AFMotor.h>
AF_Stepper stepper1(100, 2);
int analogPin = 0; // Pin analogowy
int val = 0; // variable to store the value read
int prepos = 0;
int pos = 0; //0 to 224 .
void setup()
{
stepper1.setSpeed(200); // Obroty
Serial.begin(9600);
}
void loop() {
prepos = pos;
val = analogRead(analogPin); // read the input pin
pos = map (analogRead(analogPin), 0, 1023,0, 200);
if (pos != prepos){
int diststep = pos;
if (diststep > 0) {
stepper1.step(diststep, FORWARD, DOUBLE);
}
}
}
Mayby who know how to connect stepper motor and potentiometr in visuino to adafruit motor shield because this connection in the attachment does not work.
Read the forum guidelines to see how to properly post code and some good information on making a good post.
Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.
You can go back and fix your original post by highlighting the code and clicking the </> in the menu bar.
That is a stepper motor shield. Usually "motor shield" handles DC motors. Bad description of the seller.
The picture You posted is not readable no matter what I try to magnify it.
In a project like this make test code verifying that reading the pot works and You understand it.
The second part would be running the stepper.
I would like You to post a link to the stepper shield datasheet. I didn't find it directly.
Please, also provide schematics showing pin names and power supplies.
I advise You to use serial monitor and Serial.print in the code to tell how the execution is going on. That was my life line being thrown into advanced multi million systems for many years.
Please post a data sheet or a link to where you got your stepper motor. That ancient motor shield is not an appropriate driver for a modern bipolar stepper motor.