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
-Sharp2y0A02
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() {
Serial.begin(9600);
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;
myStepper.step(stepsPerRevolution);
myStepper.setSpeed(300);
}
if (val < 200)
{
int stepsPerRevolution = 200;
myStepper.step(-stepsPerRevolution);
myStepper.setSpeed(300);
}
}
[/code]
toStepper.ino (1.02 KB)