Strobe and stepper project.

Have a small test project based on an Arduino blog but not using the same sketch.

LED strip is fired via a TIP120 (mosfets on order) with its own 12 volt supply.
Stepper motor is a BYJ48 and power currently sourced from the UNO to an older stepper board

Gave a Pot to contol strobe speed and a pot to control stepper speed. (A1 and A0)
Have a problem where changing the strobe pot value interuppts (or seems to) the stepper speed.
Similar when using the stepper pot in that it changes the strobe value / rate.

Can anyone see where I made the mistake

This is only proto stage and I will be working up to a few changes to use a better stepper lib but I would like to at least get this smoothed out a little first to learn why.

Mine is below.

/*
 Stepper Motor Control - speed control + Strobe


 */

#include <Stepper.h>
 // The analog pins used to read the value from the potentiometers
 //  int analogPin0 = 0; // STEPPER 
 //  int analogPin1 = 1; // STROBE
  
  // Pin the LED strip is connected to
  int ledPin = 11;
   
  // How much time should the light stay on between delays, in ms
  long onTime = 250;
  
  // Minimum delay be in ms
  int minDelay = 1; // 1 is lowest as 0 is ON
   
  // Maximum delay be in ms
  int maxDelay = 150;
  
  // Initialize to 0 initially
  long strobeDelay = 0; 
                                      // 4096 ? or 2048 byj48 ?
const int stepsPerRevolution = 2048;  // set this to fit teps per revolution
                                      // for your stepper

// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 2,  4,  3,  5);
                                  // IN1,IN2,IN3, IN4
                                  
int stepCount = 0;  // number of steps the motor has taken

void setup() {
 pinMode(ledPin, OUTPUT); // Setup ledPin as an output.  
}

void loop() {

  // STROBE section
  // Use map(value, fromMin, fromMax, toMin, toMax) to convert the 0 to 1023 range
  
  strobeDelay = map(analogRead(A1), 0, 1023, minDelay, maxDelay);
  digitalWrite(ledPin, HIGH); // Switch the ledPin to HIGH, turn it on!
  delayMicroseconds(onTime); // Delay while on, for the given onTime.
  digitalWrite(ledPin, LOW); // Switch the ledPin to LOW, turn if off!
  delay(strobeDelay); // Delay while off, for given strobeDelay.

  // STEPPER section  
  // read the pot value and map
  
  int sensorReading = analogRead(A0);
  // map it to a range from 0 to 100:
  int motorSpeed = map(sensorReading, 0, 1023, 0, 255);// 100 0r 255
  // set the motor speed:
  if (motorSpeed > 0) {
    myStepper.setSpeed(motorSpeed);
    // step 1/100 of a revolution:
    myStepper.step(stepsPerRevolution / 100);
  }
}

Stepper motor is a BYJ48 and power currently sourced from the UNO to an older stepper board

Stepper motors take a LOT of current. The Arduino can supply a teaspoonful per minute compared to the gallons per second needed to move a stepper.

Does your stepper really have 2048 steps per revolution? 200 is more typical. A picture of a stepper motor is useless. Real data is needed.

I probably read this page wrong.

I also gave the type as a link too.

Hi,

The interection between the two analog inputs could be due to the fact that there is only one AtoD converter.

When you read A0 then A1, the input to the AtoD is switched from A0 to A1.

There is a small capacitor on the input to the AtoD and it needs to acquire the new input level when the input is switched.

The reading is faster and it will read the input before the input has equalised.

The trick is to read your input twice, and use the last value, the first is not used.

So your code modified to read analog twice is below.

/*
  Stepper Motor Control - speed control + Strobe


*/

#include <Stepper.h>
// The analog pins used to read the value from the potentiometers
//  int analogPin0 = 0; // STEPPER
//  int analogPin1 = 1; // STROBE

// Pin the LED strip is connected to
int ledPin = 11;

// How much time should the light stay on between delays, in ms
long onTime = 250;

// Minimum delay be in ms
int minDelay = 1; // 1 is lowest as 0 is ON

// Maximum delay be in ms
int maxDelay = 150;

// Initialize to 0 initially
long strobeDelay = 0;
// 4096 ? or 2048 byj48 ?
const int stepsPerRevolution = 2048;  // set this to fit teps per revolution
// for your stepper

// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 2,  4,  3,  5);
// IN1,IN2,IN3, IN4

int stepCount = 0;  // number of steps the motor has taken

void setup() {
  pinMode(ledPin, OUTPUT); // Setup ledPin as an output.
}

void loop() {

  // STROBE section
  // Use map(value, fromMin, fromMax, toMin, toMax) to convert the 0 to 1023 range
  int strobePot = analogRead(A1); //first analog read to allow input to stablise
  strobePot = analogRead(A1);
  strobeDelay = map(strobePot, 0, 1023, minDelay, maxDelay);
  digitalWrite(ledPin, HIGH); // Switch the ledPin to HIGH, turn it on!
  delayMicroseconds(onTime); // Delay while on, for the given onTime.
  digitalWrite(ledPin, LOW); // Switch the ledPin to LOW, turn if off!
  delay(strobeDelay); // Delay while off, for given strobeDelay.

  // STEPPER section
  // read the pot value and map

  int stepperPot = analogRead(A0); //first analog read to allow input to stablise
  stepperPot = analogRead(A0);
  // map it to a range from 0 to 100:
  int motorSpeed = map(stepperPot, 0, 1023, 0, 255);// 100 0r 255
  // set the motor speed:
  if (motorSpeed > 0) {
    myStepper.setSpeed(motorSpeed);
    // step 1/100 of a revolution:
    myStepper.step(stepsPerRevolution / 100);
  }
}

Hope it helps… Tom… :slight_smile:

Thanks a lot Tom.

Slightly better and a little more stable.
Gives me a good proof of concept.

Am also moving onto getting rid of the "delay" function and think I almost have it but right now your addition is doing fine.

Good heads up on the single AD it was something I had completely forgotten about.
Maybe a good reason to implement and encoder rather than a pot.