2x stepper motors + a relay

Hello,

Is there anyway to use a relay + 2 stepper motors?
I cant control the output to the relay when the steppers are connected.
Im able to control the relay if i use the blink sketch.

-Victor

/* 
 Stepper Motor Control - one revolution
 
 This program drives a unipolar or bipolar stepper motor. 
 The motor is attached to digital pins 8 - 11 of the Arduino.
 
 The motor should revolve one revolution in one direction, then
 one revolution in the other direction.  
 
  
 Created 11 Mar. 2007
 Modified 30 Nov. 2009
 by Tom Igoe
 
 */
int relay = 12;
#include <Stepper.h>

const int stepsPerRevolution = 100;  // change this to fit the number of steps per revolution
                                     // for your motor

// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8,9,10,11);

Stepper YaxisStepper (stepsPerRevolution, 4,5,6,7); 

void setup() {
  // set the speed at 60 rpm:
  myStepper.setSpeed(25);
  YaxisStepper. setSpeed(25);
  
  // initialize the serial port:
  Serial.begin(9600);
  pinMode(relay, OUTPUT);
}

void loop() {
  // step one revolution  in one direction:
   Serial.println("clockwise");
  myStepper.step(stepsPerRevolution);
  YaxisStepper.step(stepsPerRevolution);
  delay(2000);
  digitalWrite(relay, HIGH);
  delay(2000);
  digitalWrite(relay, LOW);
   // step one revolution in the other direction:
  Serial.println("counterclockwise");
  myStepper.step(-stepsPerRevolution);
  YaxisStepper.step(-stepsPerRevolution);
  delay(10); 
}

stepper_oneRevolution2xstepper.ino (1.29 KB)

I cant control the output to the relay when the steppers are connected.

There is no reason why not.
Perhaps it is your power supply, lack of decoupling capacitors or no diode across the relay.

I don’t see any code in your sketch to turn on a relay.

/* 
 Stepper Motor Control - one revolution
 
 This program drives a unipolar or bipolar stepper motor. 
 The motor is attached to digital pins 8 - 11 of the Arduino.
 
 The motor should revolve one revolution in one direction, then
 one revolution in the other direction.  
 
  
 Created 11 Mar. 2007
 Modified 30 Nov. 2009
 by Tom Igoe
 
 */
int led = 2;
#include <Stepper.h>

const int stepsPerRevolution = 100;  // change this to fit the number of steps per revolution
                                     // for your motor

// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8,9,10,11);

Stepper YaxisStepper (stepsPerRevolution, 4,5,6,7); 

void setup() {
  // set the speed at 60 rpm:
  myStepper.setSpeed(25);
  YaxisStepper. setSpeed(25);
  
  // initialize the serial port:
  Serial.begin(9600);
  pinMode(led, OUTPUT);
}

void loop() {
  // step one revolution  in one direction:
   Serial.println("clockwise");
  myStepper.step(stepsPerRevolution);
  YaxisStepper.step(stepsPerRevolution);
  delay(2000);
  digitalWrite(led, HIGH);
  delay(3500);
  digitalWrite(led, LOW);
   // step one revolution in the other direction:
  Serial.println("counterclockwise");
  myStepper.step(-stepsPerRevolution);
  YaxisStepper.step(-stepsPerRevolution);
  delay(1000); 
}

The relay is called led (output2)

Change it "relay" and repost it if you want to talk about it.

/* 
 Stepper Motor Control - one revolution
 
 This program drives a unipolar or bipolar stepper motor. 
 The motor is attached to digital pins 8 - 11 of the Arduino.
 
 The motor should revolve one revolution in one direction, then
 one revolution in the other direction.  
 
  
 Created 11 Mar. 2007
 Modified 30 Nov. 2009
 by Tom Igoe
 
 */
int relay = 12;
#include <Stepper.h>

const int stepsPerRevolution = 100;  // change this to fit the number of steps per revolution
                                     // for your motor

// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8,9,10,11);

Stepper YaxisStepper (stepsPerRevolution, 4,5,6,7); 

void setup() {
  // set the speed at 60 rpm:
  myStepper.setSpeed(25);
  YaxisStepper. setSpeed(25);
  
  // initialize the serial port:
  Serial.begin(9600);
  pinMode(relay, OUTPUT);
}

void loop() {
  // step one revolution  in one direction:
   Serial.println("clockwise");
  myStepper.step(stepsPerRevolution);
  YaxisStepper.step(stepsPerRevolution);
  delay(2000);
  digitalWrite(relay, HIGH);
  delay(2000);
  digitalWrite(relay, LOW);
   // step one revolution in the other direction:
  Serial.println("counterclockwise");
  myStepper.step(-stepsPerRevolution);
  YaxisStepper.step(-stepsPerRevolution);
  delay(10); 
}

So are you saying with that code the relay does not switch but with the same code if you disconnect the motors it does?

Grumpy_Mike:
So are you saying with that code the relay does not switch but with the same code if you disconnect the motors it does?

Well, i can hear a small click from the relay, but there is not enough power to activate it.
Can this be solved by using an IC (TTL) to boost the power to the relay?

Victor97:

Grumpy_Mike:
So are you saying with that code the relay does not switch but with the same code if you disconnect the motors it does?

Well, i can hear a small click from the relay, but there is not enough power to activate it.
Can this be solved by using an IC (TTL) to boost the power to the relay?

Your answer is not clear. Do you hear the small click when the motors are connected? Does the relay work properly when the motors are not connected?

Can you post a diagram showing how the relay is connected. Draw a diagram and post a photo of it.

...R

[/quote]

Your answer is not clear. Do you hear the small click when the motors are connected? Does the relay work properly when the motors are not connected?

Can you post a diagram showing how the relay is connected. Draw a diagram and post a photo of it.

...R
[/quote]

I hear a small click when the motors are connected and when they arent.
When im using the blink sketch (motors connected) On output 2 the relay activates.

Normally an arduino does not have enough current to drive a relay. What relay is it and what are the coil requirements.
You do not wire it up like that anyway. The diode goes across the relay not in series with the signal.

Look at the first circuit on this page for how to correctly drive a relay.
http://www.thebox.myzen.co.uk/Workshop/Motors_1.html