moving sculpture

Hello, for a school project i am making a sculpture that reacts to the people around it.

to do this i will make a couple of arms controlled by a stepper motor that is controlled by an easy driver that is being controlled by a Sharp proximity sensor. i want that the closer you get, the harder stepper moves. for this i could use the speedcontrol example of arduino, but i want it to work together with multiple motors so i tried to create some if statements.

for example:

if you get a distance of 200, the motor moves on a medium speed.

this is the code i made. unfortunately i can't get my nema 17 motor to run it's maximum speed and there are still a lot of mistakes in there. maybe someone can help me create a good more efficient (but hopefully still easy) code!!

the tools that i am using are:
-arduino Uno
-easy driver
-42BTGHW811 stepper motor: 1.8 degrees per step. 3.1V rate voltage

int sensorpin = 0;           // analog pin used to connect the sharp sensor
int val = 0;                 // variable to store the values from sensor(initially zero)

#include <Stepper.h>
const int stepsPerRevolution = 200;  // change this to fit the number of steps per revolution
Stepper myStepper(stepsPerRevolution, 8, 9);

#define DIR_PIN 8
#define STEP_PIN 9

void setup() {
 pinMode(DIR_PIN, OUTPUT); 
 pinMode(STEP_PIN, OUTPUT); 


void loop() {
 { val = analogRead(sensorpin);       // reads the value of the sharp sensor
   Serial.println(val) ;
 if (val > 200)
    int stepsPerRevolution = 200;            
 if (val < 200)
   int stepsPerRevolution = 200;



toStepper.ino (1.02 KB)

You need to post a link to the datasheet for your stepper motor.
Tell us what stepper motor driver you are using.
Tell us what power supply you are using for the motor (volts and amps).

Please modify your post and use the code button </> so your code looks like this and is easy to copy to a text editor. See How to use the Forum

Stepper Motor Basics
Simple Stepper Code

It's probably a good idea to set the step speed BEFORE doing the steps rather than after.

There is no need to create a variable called stepsPerRevolution every place you use it. You already have a global variable of that name that contains the value you want.