28BYJ-48 stepper motor with ULN2003

Hello guys, please after running the codes below, the timer works perfectly but only LED lights A and B on the ULN2003 power up instead of all the four LED lights. Hence the motor does not spin at all. Please I am new to this so kindly help me solve this issue. Thank you

Arduino codes:

//This code is to use with DS1302 RTC module, it permits you to setup the actual time and date
//And you can visualize them on the serial monitor

#include <virtuabotixRTC.h> //Library used
#include <AccelStepper.h>

//Wiring SCLK -> 6, I/O -> 7, CE -> 8
//Or CLK -> 6 , DAT -> 7, Reset -> 8
//int Relay = 7;
virtuabotixRTC myRTC(5, 4, 2); //If you change the wiring change the pins here also

// Motor pin definitions:
#define motorPin1 12 // IN1 on the ULN2003 driver
#define motorPin2 11 // IN2 on the ULN2003 driver
#define motorPin3 10 // IN3 on the ULN2003 driver
#define motorPin4 9 // IN4 on the ULN2003 driver
#define MotorInterfaceType 8

byte OnHour = 14;
byte OnMin = 18;
byte OffHour = 14;
byte OffMin = 19;

void StartMotor(){
AccelStepper stepper = AccelStepper(MotorInterfaceType, motorPin1, motorPin3, motorPin2, motorPin4);
stepper.setMaxSpeed(1000);
stepper.setAcceleration(100);
stepper.setSpeed(3500);
stepper.runSpeed();

}

void setup() {

pinMode(MotorInterfaceType, OUTPUT);
digitalWrite(MotorInterfaceType, HIGH);

Serial.begin(9600);

// Set the current date, and time in the following format:
// seconds, minutes, hours, day of the week, day of the month, month, year
myRTC.setDS1302Time(50, 18, 14, 5, 9, 7, 2021); //Here you write your actual time/date as shown above
//but remember to "comment/remove" this function once you're done
//The setup is done only one time and the module will continue counting it automatically

}

void loop() {
//stepper.setSpeed(2500);
//stepper.runSpeed();
// This allows for the update of variables for time or accessing the individual elements.
myRTC.updateTime();

// Start printing elements as individuals
Serial.print("Current Date / Time: ");
Serial.print(myRTC.dayofmonth); //You can switch between day and month if you're using American system
Serial.print("/");
Serial.print(myRTC.month);
Serial.print("/");
Serial.print(myRTC.year);
Serial.print(" ");
Serial.print(myRTC.hours);
Serial.print(":");
Serial.print(myRTC.minutes);
Serial.print(":");
Serial.println(myRTC.seconds);
if (myRTC.hours == OnHour && myRTC.minutes == OnMin) {
digitalWrite(8, HIGH);
StartMotor();
Serial.println("MOTOR ON");
}
else if (myRTC.hours == OffHour && myRTC.minutes == OffMin) {
digitalWrite(8, LOW);

Serial.println("MOTOR OFF");
}
// Delay so the program doesn't print non-stop
delay(1000);
}

Hi @johnbaffoe .
Recommendations.
Read: How to get the best out of this forum
Use </> tags to post sketcks or printouts;
Post your scheme. Can be done freehand;
What products are you using in your project?
Which microcontroller you using in your project?
Arduino Uno/Mega/ESP....?
RV mineirin

Thank you very much @ruilviana for the insight. Well i'm using Arduino Uno board, a DS1302 timer, a relay module and a 28BYJ-48 stepper motor.

Codes:

[code]
//This code is to use with DS1302 RTC module, it permits you to setup the actual time and date
//And you can visualize them on the serial monitor
//This code is a modified version of the code provided in virtuabotixRTC library
//Refer to Surtrtech Youtube channel/Facebook page for more information


#include  <virtuabotixRTC.h>  //Library used
#include <AccelStepper.h>


//Wiring SCLK -> 6, I/O -> 7, CE -> 8
//Or     CLK -> 6 , DAT -> 7, Reset -> 8
//int Relay = 7;
virtuabotixRTC myRTC(5, 4, 2); //If you change the wiring change the pins here also

// Motor pin definitions:
#define motorPin1  12      // IN1 on the ULN2003 driver
#define motorPin2  11      // IN2 on the ULN2003 driver
#define motorPin3  10     // IN3 on the ULN2003 driver
#define motorPin4  9     // IN4 on the ULN2003 driver
#define MotorInterfaceType 8

byte OnHour  = 14;
byte OnMin  =  18;
byte OffHour  = 14;
byte OffMin  =  19;

void StartMotor() {
  AccelStepper stepper = AccelStepper(MotorInterfaceType, motorPin1, motorPin3, motorPin2, motorPin4);
  stepper.setMaxSpeed(1000);
  stepper.setAcceleration(100);
  stepper.setSpeed(3500);
  stepper.runSpeed();

}

void setup() {

  pinMode(MotorInterfaceType, OUTPUT);
  digitalWrite(MotorInterfaceType, HIGH);

  Serial.begin(9600);

  // Set the current date, and time in the following format:
  // seconds, minutes, hours, day of the week, day of the month, month, year
  myRTC.setDS1302Time(50, 18, 14, 5, 9, 7, 2021);  //Here you write your actual time/date as shown above
  //but remember to "comment/remove" this function once you're done
  //The setup is done only one time and the module will continue counting it automatically


}


void loop() {
  //stepper.setSpeed(2500);
  //stepper.runSpeed();
  // This allows for the update of variables for time or accessing the individual elements.
  myRTC.updateTime();

  // Start printing elements as individuals
  Serial.print("Current Date / Time: ");
  Serial.print(myRTC.dayofmonth);             //You can switch between day and month if you're using American system
  Serial.print("/");
  Serial.print(myRTC.month);
  Serial.print("/");
  Serial.print(myRTC.year);
  Serial.print(" ");
  Serial.print(myRTC.hours);
  Serial.print(":");
  Serial.print(myRTC.minutes);
  Serial.print(":");
  Serial.println(myRTC.seconds);
  if (myRTC.hours == OnHour && myRTC.minutes == OnMin) {
    digitalWrite(8, HIGH);
    StartMotor();
    Serial.println("MOTOR ON");
  }
  else if (myRTC.hours == OffHour && myRTC.minutes == OffMin) {
    digitalWrite(8, LOW);

    Serial.println("MOTOR OFF");
  }
  // Delay so the program doesn't print non-stop
  delay(1000);
}
[/code]

The first argument to the AccelStepper constructor is NOT a pin number. Someone is very confused using 8 both in place of "AccelStepper::HALF4WIRE" and as a pin number.

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