Unable to run 28BYJ-48 stepper motor using relay and ds1302

I want to run 28BYJ-48 stepper motor in specific time using ds1302 clock module and using single channel relay. But the stepper motor does not rotates as the relay is triggered. Here is my code below please help me to solve it. Thank u in advance…

#include <AccelStepper.h>
#include <DS1302.h>
#define HALFSTEP 8
#define swt 10
#define Relay 9
DS1302 gRtc (2,3,4);
Time gRtcTime;
// Motor pin definitions
#define motorPin1 5 // IN1 on the ULN2003 driver 1
#define motorPin2 6 // IN2 on the ULN2003 driver 1
#define motorPin3 7 // IN3 on the ULN2003 driver 1
#define motorPin4 8 // IN4 on the ULN2003 driver 1
const int OnHour = 19;
const int OnMin = 33;
const int OffHour = 19;
const int OffMin = 34;
// Initialize with pin sequence IN1-IN3-IN2-IN4 for using the AccelStepper with 28BYJ-48
AccelStepper stepper1(HALFSTEP, motorPin1, motorPin3, motorPin2, motorPin4);

void setup() {
stepper1.setMaxSpeed(1000.0);
stepper1.setAcceleration(100.0);
stepper1.setSpeed(200);
stepper1.moveTo(20000);
stepper1.runToPosition();
gRtc.halt(false);
gRtc.writeProtect(false);
Serial.begin(9600);
pinMode(swt,INPUT_PULLUP);
pinMode(Relay, OUTPUT);
digitalWrite(Relay, HIGH);
}//–(end setup )—

void loop() {
rly();
if( Relay == LOW){
stpr();
}
}
void stpr(){
if (stepper1.distanceToGo() == 0){
stepper1.moveTo(-stepper1.currentPosition());
}
stepper1.run();

while (digitalRead(swt) == 0 ) {
stepper1.setCurrentPosition(0);
}

}

void rly(){
Serial.print(gRtc.getDOWStr());
Serial.print(" “);
Serial.print(gRtc.getDateStr());
Serial.print(” – ");
Serial.println(gRtc.getTimeStr());
delay (1000);
Time t = gRtc.getTime();
if(t.hour == OnHour && t.min == OnMin){
digitalWrite(Relay,LOW);
Serial.println(“LIGHT ON”);
}
else if(t.hour == OffHour && t.min == OffMin){
digitalWrite(Relay,HIGH);
Serial.println(“LIGHT OFF”);
}
}

A schematic showing how you have all this connected, including the relay, might give the forum people a chance to help. What do you expect the relay to do and is the relay working the way you expect?

The specifications of the relay might be important, also. Is it just a relay or is it on a circuit board with other components.

Paul

I have set time to trigger relay and the relay triggers in given time and the the uln2003a stepper motor driver gets on but the stepper motor does not rotates. Also i have found that after uploading code before the triggering relay as i connect power to stepper motor it rotates. My main plan is to rotate the motor as the relay triggers

Here’s the OP’s code slightly re-formatted for ease of reading, with { and } on their own lines and ctrl-T’d:

#include <AccelStepper.h>
#include <DS1302.h>
#define HALFSTEP 8
#define swt 10
#define Relay 9
DS1302 gRtc (2, 3, 4);
Time   gRtcTime;
// Motor pin definitions
#define motorPin1  5     // IN1 on the ULN2003 driver 1
#define motorPin2  6     // IN2 on the ULN2003 driver 1
#define motorPin3  7     // IN3 on the ULN2003 driver 1
#define motorPin4  8     // IN4 on the ULN2003 driver 1
const int OnHour = 19;
const int OnMin = 33;
const int OffHour = 19;
const int OffMin = 34;
// Initialize with pin sequence IN1-IN3-IN2-IN4 for using the AccelStepper with 28BYJ-48
AccelStepper stepper1(HALFSTEP, motorPin1, motorPin3, motorPin2, motorPin4);

void setup()
{
  stepper1.setMaxSpeed(1000.0);
  stepper1.setAcceleration(100.0);
  stepper1.setSpeed(200);
  stepper1.moveTo(20000);
  stepper1.runToPosition();
  gRtc.halt(false);
  gRtc.writeProtect(false);
  Serial.begin(9600);
  pinMode(swt, INPUT_PULLUP);
  pinMode(Relay, OUTPUT);
  digitalWrite(Relay, HIGH);
}//--(end setup )---

void loop()
{
  rly();
  if ( Relay == LOW)
  {
    stpr();
  }
}//loop

void stpr()
{
  if (stepper1.distanceToGo() == 0)
  {
    stepper1.moveTo(-stepper1.currentPosition());
  }
  stepper1.run();

  while (digitalRead(swt) == 0 )
  {
    stepper1.setCurrentPosition(0);
  }
}//stpr

void rly()
{
  Serial.print(gRtc.getDOWStr());
  Serial.print(" ");
  Serial.print(gRtc.getDateStr());
  Serial.print(" -- ");
  Serial.println(gRtc.getTimeStr());
  delay (1000);
  Time t = gRtc.getTime();
  if (t.hour == OnHour && t.min == OnMin)
  {
    digitalWrite(Relay, LOW);
    Serial.println("LIGHT ON");
  }
  else if (t.hour == OffHour && t.min == OffMin)
  {
    digitalWrite(Relay, HIGH);
    Serial.println("LIGHT OFF");
  }
}//rly
#define Relay 9

if ( Relay == LOW)
  {
    stpr();
  }

9 can never == LOW

You want

if (digitalRead( Relay) == LOW)
  {
    stpr();
  }

still the relay gets triggered and uln2003a gets on but the stepper motor does not rotates

In the first reply, you were asked to provide a schematic how everything is connected. Please do so and don't forget every power and ground connection.

You can draw on paper, take a photo and post it here.