Hi guys, Clon here. I am doing a project which involves the use of a stepper motor (28BYJ-48 to be exact) to turn a thumb screw attached to a shock absorber. I am using Arduino UNO and a bluetooth module (HC-06). The problem that I have now is with the coding, I am not so sure where to start or even how to start.
The thumb screw can be to rotated 22 times/clicks (clockwise to tighten and anticlockwise to loosen), and each click is about 50 degree or it's motor step is approximately 284 steps. Let's say if I want to turn all the way to the 22nd click from origin, its 284*22 = 6248. But if afterwards I wanted to turn to the 17th click for example, how do I let the program know for sure how much steps to go back (cause the program doesn't really know it is at the 22nd click, right?).
Imagine you are in the elevator at ground floor (1), and you want to get to the 2nd floor which requires 284 motor steps. Once you reached 2nd floor, you want to go to the 3rd floor, that's another additional 284 steps. What if when you are at the ground floor, you want to go to the third floor directly? I can't just program ( if( x == '3' );, step(284); or even step(568); that would be make it go incremental. I want to make it absolute (with ground floor as reference point (0 steps)).
I hope you guys have some insight on this and please do ask if you can't understand it, I'm not a good descriptive writer. I understand that you guys are trying your best to help so here is the code that I previously modified from adafruit tutorial.
#include <Stepper.h>
int pin1 = 12;
int pin2 = 11;
int pin3 = 10;
int pin4 = 9;
int bluetooth;
Stepper motor(512, pin1, pin2, pin3, pin4);
void setup()
{
pinMode(pin1, OUTPUT);
pinMode(pin2, OUTPUT);
pinMode(pin3, OUTPUT);
pinMode(pin4, OUTPUT);
while (!Serial);
Serial.begin(9600);
motor.setSpeed(30);
}
void loop()
{
if (Serial.available()){
Serial.println("\n");
Serial.println("Press 1 for medium stiffness and press 2 to return to normal stiffness. \n Press 3 for high stiffness and press 4 to normal stiffness.\n");
bluetooth = Serial.read();
if(bluetooth == '1')
motor.step(2048);
if(bluetooth == '2')
motor.step(-2048);
if(bluetooth == '3')
motor.step(4096);
if(bluetooth == '4')
motor.step(-4096);
delay(500);
}
}
Current coding is when I input 1, the motor will turn 360 degree and 2 will turn -360 degree back to initial position. 3 will turn 720 degree and 4 will turn -720 degrees.
I think what I wanted to do is to make the steps system similar to an elevator system where you can choose the floor you want to go (the nth click you want) and I don't think this can be achieved with just numbers alone...
Here is the image of the thumb screw
