Dawn Abbot Dawn Abbot - 1 year ago 91
Node.js Question

Controlling a Stepper Motor with an Ardiuno and Node.js

My stepper motor is controlled using a L293d driver connected to an Ardiuno. The tutorial that I got my information from is here, https://learn.adafruit.com/wifi-control ... ino-sketch, but have changed the code to match for the stepper motor instead of a dc motor. Currently, I am just testing with serial input--no wireless yet.

I have everything working. When I press the forward button, the motor moves forward. However, it only rotates through one revolution. I am not sure how to change the code so that when I click the forward button it rotates forward continuously until I press the stop button. Does anyone know how to do this?

#include <SPI.h>
#include <aREST.h>
#include <Stepper.h>
#include <Wire.h>

aREST rest = aREST();

int inA1 = 12; // input 1 of the stepper
int inA2 = 11; // input 2 of the stepper
int inB1 = 10; // input 3 of the stepper
int inB2 = 9; // input 4 of the stepper

#define STEPS 512

Stepper motor(STEPS, inA1, inA2, inB1, inB2);

void setup() {
pinMode(inA1, OUTPUT);
pinMode(inA2, OUTPUT);
pinMode(inB1, OUTPUT);
pinMode(inB2, OUTPUT);

Serial.println(F("Hello, CC3000!\n"));


//Expose functions

void loop()



// Forward
int forward(String command) {
return 1;

int backward(String command) {
return 1;

Answer Source

Failed: Simple set motor.step(2147483647). 2147483647 is max value of int.

New attempt: try implement next logic. I'm not c-guru so below dirty code

int lastCommand = 0; // 0 - nothing; 1 - forward; 2 - backward; 3 - stop;
void forward () {
    lastCommand = 1;

void backward () {
    lastCommand = 2;

void stop() {
   lastCommand = 0;

void loop() {
    if (lastCommand == 1)
    if (lastCommand == 2)

If we push backward + forward + backward button and send to Serial 3 commands then motor execute all of them consistently. Imho it's a problem.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download