Im in trouble. I want to control stepper motor 28BYJ-48 with HC-05 on Arduino UNO. I'm using below algorithm, which I found on the net and adjusted to my needs. Im using RobotRemo android app. Steering element is the slinder in range [0;100]. The issue is: When I launch Arduino and connect HC-05, diod TX is blinking and HC-05 sending to microcontroler coordinates of slider. When I move the slider first time, motor works, but after this HC-05 dont send anymore coordinates of slider, it stopped refreshing.
Connection of HC-05:
HC-05 Arduino
VCC->5V
GND->GND
TXD->RX
RXD->TX
Serial monitor:
20:11:10.678 -> s50
20:11:10.758 -> s50
20:11:10.828 -> s51
20:11:10.863 -> s51
20:11:10.946 -> s55
20:11:11.012 -> s55
20:11:11.058 -> s81 - when motor start working, refreshing is stopped
#include <Stepper.h>
#define STEPS 32
#define IN1 11
#define IN2 10
#define IN3 9
#define IN4 8
Stepper stepper(STEPS, IN4, IN2, IN3, IN1);
void setup() {
Serial.begin(9600);
}
char cmd[100];
byte cmdIndex;
void exeCmd() {
if (cmd[0] == 's') {
unsigned int val = atof(cmd +1);
Serial.println(cmd);
if( (val > 40) && (val < 60) )
{
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, LOW);
}
else
{
while (val >= 60)
{
int speed_ = map(val, 60, 100, 5, 500);
stepper.setSpeed(speed_);
stepper.step(1);
}
while (val <= 40)
{
int speed_ = map(val, 40, 0, 5, 500);
stepper.setSpeed(speed_);
stepper.step(-1);
}
}
}
}
void loop() {
if (Serial.available())
{
char c = (char)Serial.read();
delay(3);
if (c == '\n') {
cmd[cmdIndex] = 0;
exeCmd();
cmdIndex = 0;
} else {
cmd[cmdIndex] = c;
if (cmdIndex < 99) cmdIndex++;
}
}
}