Hi everyone,
Im trying to create a camera slider with 2 motors one for the rail, and the other to pan the camera, so far, im just struggling with the home position of the rail.
im currently using a 28BYJ-48 with drivers ULN2003 connected to pin 2 - 5, its powered with the 5V from the arduino Mega 2560, but its just to debug, i've a 9v supply.
a limit switch NO on pin 13, and to 5V.
its currently connected through bluetooth, the Wifi ESP-01 is not working with me, i need to investigate.
What i expected to do, its from the Blynk app, call the procedure on V6 while debug, stepper moving forward till reach the limit switch, set 0 move 200 and set 0 again.
what is happening, i've tried with While, For, and timers, but none of them could make move the motors, while using timers, the motor move say, 10 steps, and with while and for, the motor didn't move at all.
Used an LCD on the app, to get codes, and oversee the code, im getting the whole code ok, but the motor dont move.
also, the limit switch works, manually but works. (at least something works well)
as a reference, i have some code that the motor actually move, i set acceleration and speed with a slider, move to a 0 defined on the setup, and moving to 4096, continuous movement and all, but trying with the home procedure, it just dont work.
The version 6 its the recent, with for
// SoftwareSerial SwSerial(10, 11); // RX, TX
#define BLYNK_PRINT Serial
#include <BlynkSimpleSerialBLE.h>
#include <SoftwareSerial.h>
#include <AccelStepper.h>
// #include <BlynkTimer.h>
#include <SPI.h>
#define HALFSTEP 8
// Motor pin definitions
#define motorPin1 2 // IN1 on the ULN2003 driver 1
#define motorPin2 3 // IN2 on the ULN2003 driver 1
#define motorPin3 4 // IN3 on the ULN2003 driver 1
#define motorPin4 5 // IN4 on the ULN2003 driver 1
// Initialize with pin sequence IN1-IN3-IN2-IN4 for using the AccelStepper with 28BYJ-48
AccelStepper stepper1(HALFSTEP, motorPin1, motorPin3, motorPin2, motorPin4);
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "---";
SoftwareSerial SerialBLE(10, 11); // RX, TX
int Acceleration;
int Speeed;
int switch1 = 13;
WidgetLCD lcd(V8);
BlynkTimer timer;
void setup()
{
lcd.clear();
lcd.print(4, 0, "STARTING");
// Debug console
Serial.begin(9600);
SerialBLE.begin(9600);
Blynk.begin(SerialBLE, auth);
Serial.println("Waiting for connections...");
stepper1.setMaxSpeed(1000.0);
stepper1.setAcceleration(100.0);
stepper1.setSpeed(100);
stepper1.moveTo(20000);
stepper1.setCurrentPosition(0);
//stepper1.moveTo(stepper1.currentPosition());
pinMode(switch1, INPUT);
lcd.clear();
//timer.disable(HomeProd);
//Blynk.virtualWrite(V6, onState);
lcd.print(4, 0, "READY");
}
BLYNK_CONNECTED()
{
Blynk.syncVirtual(0);
Blynk.syncVirtual(1);
lcd.clear();
lcd.print(0, 0, Acceleration);
lcd.print(0, 1, Speeed);
}
BLYNK_WRITE(0)
{
lcd.clear();
lcd.print(0, 0, "Going 0");
stepper1.setAcceleration(Acceleration);
stepper1.setMaxSpeed(Speeed);
stepper1.moveTo(0);
}
BLYNK_WRITE(1)
{
lcd.clear();
lcd.print(0, 0, "Going 4096");
stepper1.setAcceleration(Acceleration);
stepper1.setMaxSpeed(Speeed);
stepper1.moveTo(4096);
}
BLYNK_WRITE(4)
{
lcd.clear();
lcd.print(0, 0, "Acceleration:");
Acceleration = param.asInt(); // Turn off if 0
lcd.print(0, 1, Acceleration);
}
BLYNK_WRITE(3)
{
lcd.clear();
lcd.print(0, 0, "Speed:");
Speeed = param.asInt(); // Turn off if 0
lcd.print(0, 1, Speeed);
}
BLYNK_WRITE(5)
{
stepper1.setMaxSpeed(200);
stepper1.setAcceleration(200.0);
stepper1.moveTo(1000000);
}
BLYNK_WRITE(6)
{
float Pos0;
Pos0 = 409.6;
float x;
x = 409.6;
for (int i = 1; i < 11; i++)
{
//stepper1.setMaxSpeed(1000);
//stepper1.setAcceleration(1000);
//stepper1.moveTo(Pos0);
//stepper1.run();
stepper1.moveTo(stepper1.currentPosition());
stepper1.run();
delay(4000);
lcd.clear();
lcd.print(1, 0, Pos0);
if (digitalRead(switch1) == HIGH)
{
lcd.clear();
lcd.print(1, 0, "Home Found");
stepper1.stop();
stepper1.setCurrentPosition(0);
stepper1.moveTo(200);
stepper1.setCurrentPosition(0);
exit(0);
}
else
{
Pos0 = Pos0 + x;
}
}
}
BLYNK_WRITE(7)
{
lcd.clear();
lcd.print(1, 0, "Motor Stop");
stepper1.stop();
}
BLYNK_WRITE(8)
{
stepper1.setMaxSpeed(200);
stepper1.setAcceleration(200.0);
stepper1.moveTo(-1000000);
}
void loop()
{
Blynk.run();
stepper1.run();
timer.run();
}
the version 5 used while
BLYNK_WRITE(6)
{
stepper1.setMaxSpeed(200);
stepper1.setAcceleration(200.0);
stepper1.moveTo(1000);
delay(2000);
while (digitalRead(switch1))
{
lcd.clear();
lcd.print(1, 0, "Moving Motor");
}
lcd.clear();
lcd.print(1, 0, "Home Found");
stepper1.stop();
stepper1.setCurrentPosition(0);
stepper1.moveTo(200);
stepper1.setCurrentPosition(0);
}
void loop()
{
Blynk.run();
stepper1.run();
timer.run();
}
The version 4 used timers
// SoftwareSerial SwSerial(10, 11); // RX, TX
#define BLYNK_PRINT Serial
#include <BlynkSimpleSerialBLE.h>
#include <SoftwareSerial.h>
#include <AccelStepper.h>
// #include <BlynkTimer.h>
#include <SPI.h>
#define HALFSTEP 8
BLYNK_WRITE(6)
{
stepper1.setMaxSpeed(200);
stepper1.setAcceleration(200.0);
stepper1.moveTo(1000000);
lcd.print(1, 0, "Starting Home 1");
HomeProd2();
}
void HomeProd2(){
timer.setInterval(1000, HomeProd);
}
void HomeProd()
{
if (digitalRead(switch1) == HIGH)
{
lcd.clear();
lcd.print(1, 0, "Moving motor");
}
if (digitalRead(switch1) == LOW)
{
lcd.clear();
lcd.print(1, 0, "Home Found");
stepper1.stop();
stepper1.setCurrentPosition(0);
stepper1.moveTo(200);
stepper1.setCurrentPosition(0);
timer.disable(HomeProd);
}
}
void loop()
{
Blynk.run();
stepper1.run();
timer.run();
}
Hope anybody could help me.
Best Regards, saludos

