Stepper Motor with Speech recognizer

Hi Guys,
I have Problem with my Code and im pretty sure you should be able to help me. Its not really complicated. Im trying to control a stepper motor with the grove speech recognizer and its working so far. My only Problem is that it won't stop turning in one direction once i gave the signal. Here is my code:

#include "Stepper.h"
#include <SoftwareSerial.h>
#define SOFTSERIAL_RX_PIN 2
#define SOFTSERIAL_TX_PIN 3

#define STEPS 32 // Number of steps per revolution of Internal shaft
int Steps2Take; // 2048 = 1 Revolution
SoftwareSerial softSerial(SOFTSERIAL_RX_PIN,SOFTSERIAL_TX_PIN);
/-----( Declare objects )-----/
// Setup of proper sequencing for Motor Driver Pins
// In1, In2, In3, In4 in the sequence 1-3-2-4

Stepper small_stepper(STEPS, 8, 10, 9, 11);

void setup()
{
softSerial.begin(9600);
softSerial.listen();
}

void loop()
{
int cmd;
if(softSerial.available())
{
cmd = softSerial.read();

}

if(cmd==15){   //I removed the command list here I used "Start"
              small_stepper.setSpeed(500); //Max seems to be 700
                  Steps2Take  =  2048;  // Rotate CW
                  small_stepper.step(Steps2Take);
                  delay(2000); 
        
}

if(cmd==14){
                small_stepper.setSpeed(500);
                  Steps2Take  =  -2048;  // Rotate CCW
                  small_stepper.step(Steps2Take);
                  delay(2000); 
           
}

}/* --end main loop -- */

Hope you guys have a clue but i kind of got the feeling that it can't be that hard.
Thanks in advance :slight_smile:

Because you never reset the value of cmd, it likely picks up the same value each iteration of loop

okay thank you very much. I trie it with just setting cmd to another value but it won't work... can u give me a more precise solution? How do i reset the Value?

cmd = 0;

You have no idea how much I hate that phrase.

Hey sry to get on ur nerves again i did it like that: `#include "Stepper.h"
#include <SoftwareSerial.h>
#define SOFTSERIAL_RX_PIN 2
#define SOFTSERIAL_TX_PIN 3

#define STEPS 32 // Number of steps per revolution of Internal shaft
int Steps2Take; // 2048 = 1 Revolution
SoftwareSerial softSerial(SOFTSERIAL_RX_PIN,SOFTSERIAL_TX_PIN);
/-----( Declare objects )-----/
// Setup of proper sequencing for Motor Driver Pins
// In1, In2, In3, In4 in the sequence 1-3-2-4

Stepper small_stepper(STEPS, 8, 10, 9, 11);

void setup()
{
softSerial.begin(9600);
softSerial.listen();
}

void loop()
{
int cmd;
if(softSerial.available())
{
cmd = softSerial.read();

}


if(cmd==15){   //I removed the command list here I used "Start"
              small_stepper.setSpeed(500); //Max seems to be 700
                  Steps2Take  =  2048;  // Rotate CW
                  small_stepper.step(Steps2Take);
                  delay(2000); 
                  cmd = 0;
}

if(cmd==14){
                small_stepper.setSpeed(500);
                  Steps2Take  =  -2048;  // Rotate CCW
                  small_stepper.step(Steps2Take);
                  delay(2000);
                  cmd = 0; 
           
}

}`

but it isn't working what am i doing wrong??

14 and 15 are both non-printing ASCII control characters - why on Earth did you chose those values?

You also forgot the code tags, and didn't explain what "isn't working" means.

I got this script out of a tutorial Video and thaught i could rewrite and adapt it to use it with my stepper motor. just to explain where these characters come from. What would you suggest to use in stead?
And by writing not working i mean that my Solution didn't change anything to the fact that the motor doesn't stop spinning so i obviously wasn't able to reset the value. thanks for your patience.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.