Before getting started I want to say that I read every thread about this subject but could not find a suitable answer
So here I come in desperation, hoping someone might help !
So I have an Arduino Uno connected to WiFi through ESP module, which works perfectly fine. I’m able to do a lot of things with it but now I really need to control a Stepper Motor !
I’m using a 28BYJ-48 Stepper Motor with ULN2003 driver, which are fantastic and work absolutely fine with my Arduino.
My idea is to have a simple button on Blynk, and if I press it my motor will go forward. I want to start easy, I don’t care about it being able to stop or whatever ! If I get this to work I should be ok by my self for a more advanced use.
I’m using the Stepper library that, from what I understood is using Delay, which interrupt Blynk.run. So when I try to call a “go forward” function triggered by a blynk button, it all gets very messy and the motor will work at best for 3 seconds, then stop.
I’m making a robot so my Arduino is powered by a 5v battery, and I would like to keep only one Arduino in this robot.
A solution I heard about was to use a second Arduino, so the first triggers the second arduino and this way there is no mess with the delays. At this point I don’t know how to do that, and as I said if I can keep only one Arduino and one battery in this project it would be nice !
I have like 5 test codes so I won’t post them all here, I think everyone understood what I’m trying to achieve here
I will change my approach and use a simple dc motor instead, so there is no delay and no problem !
Also I have a little question : I used a servo in a previous project on blynk using serial connection with a computer and it was working like a charm.
Now that I use the esp, everytime there is a input (everytime I press something on my blynk app) the servo is twitching back and fort approximately 5 degres. If there is no input at all, it also does it every 10 seconds. I tried with 3 servos and it does that everytime. Any idea ?
It appears to be a minor conflict with shared hardware timers between the servo libraries, SimpleTimer and even Blynk running in he background.
I have been able to mitigate the issue by disconnecting the servos after any required movement. Here is a functional servo sweep routine that used timers instead of delays and detaches the servo when not moving:
//===== Servo Sweep Switch Function =====
BLYNK_WRITE(V0) // Switch Widget
{
SrvoButtonState = param.asInt();
if (SrvoButtonState == 1) {
myservo.attach(servoPin);
timer.setTimer(800L, Servo1, 1); // Run Servo1 loop every 800ms
} else
myservo.detach();
} // END Blynk Function
void Servo1() {
myservo.write(160);
timer.setTimer(800L, Servo2, 1); // Run Servo2 loop every 800ms
}
void Servo2() {
myservo.write(0);
Blynk.syncVirtual(V0); // Check if switch still activated
}
For any advanced use of steppers and servos, I would recommend external smart controllers that take the info from the MCU but handle all the timing and control of the motors themselves.