Stepper Quesetion....Help Please

I’m a complete noob at arduino and I’m having problems stepping a motors. My program basically checks the arduino time and then steps the motor after every 5 seconds have past since the arduino time. I’m using a DS1307 rtc to sync the arduino time. Problem is the motor steps every 5 seconds and displays stepping. However when the serial port time passes a minute it does not step anymore of serial print my message eg when the seconds goes from 55 to 1 second it stops stepping. Opening and closing the serial port again makes it step again. Sorry if my code is messy. Any help is greatly appreciated.

/* THIS IS MY PROGRAM. SIGH..........................

#include <Stepper.h>
const int stepsPerRevolution = 200;  // 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);                                       
#include <Time.h>
#include <Wire.h>
#define DS1307_I2C_ADDRESS 0x68

int ledPin =  13;

// for RTC work
byte RTCsecond, RTCminute, RTChour, RTCdayOfWeek, RTCdayOfMonth, RTCmonth, RTCyear;

//my global variables
byte stepperMin, stepperSec;

void setup()
  pinMode(ledPin, OUTPUT); // show the status
  myStepper.setSpeed(2); //Motor RPM
  Serial.begin(9600); // for debugging
  Serial.flush(); // need to flush serial buffer, otherwise first read from reset/power on may not be correct
  Wire.begin(); // initialise i2c bus for DS1307 
  clkSync();  //sync rtc values to arduino

void  loop(){  

  getDateDs1307(&RTCsecond, &RTCminute, &RTChour, &RTCdayOfWeek, &RTCdayOfMonth, &RTCmonth, &RTCyear);
      myStepper.step(4); //activate stepper motor
       stepperSec=RTCsecond; //reinit variable to prepare for next loop


void digitalClockDisplay()
  // digital clock display of the time

void printDigits(int digits)
  if(digits < 10)

void setDateDs1307(byte RTCsecond,        // 0-59
byte RTCminute,        // 0-59
byte RTChour,          // 1-23
byte RTCdayOfWeek,     // 1-7
byte RTCdayOfMonth,    // 1-28/29/30/31
byte RTCmonth,         // 1-12
byte RTCyear)          // 0-99
  Wire.write(decToBcd(RTCsecond));    // 0 to bit 7 starts the clock
  Wire.write(decToBcd(RTChour));      // If you want 12 hour am/pm you need to set
  // bit 6 (also need to change readDateDs1307)

// Gets the date and time from the ds1307
void getDateDs1307(byte *RTCsecond,
byte *RTCminute,
byte *RTChour,
byte *RTCdayOfWeek,
byte *RTCdayOfMonth,
byte *RTCmonth,
byte *RTCyear)
  // Reset the register pointer

  Wire.requestFrom(DS1307_I2C_ADDRESS, 7);

  // A few of these need masks because certain bits are control bits
  *RTCsecond     = bcdToDec( & 0x7f);
  *RTCminute     = bcdToDec(;
  *RTChour       = bcdToDec( & 0x3f);  // Need to change this if 12 hour am/pm
  *RTCdayOfWeek  = bcdToDec(;
  *RTCdayOfMonth = bcdToDec(;
  *RTCmonth      = bcdToDec(;
  *RTCyear       = bcdToDec(;

// Convert normal decimal numbers to binary coded decimal
byte decToBcd(byte val)
  return ( (val/10*16) + (val%10) );
// Convert binary coded decimal to normal decimal numbers
byte bcdToDec(byte val)
  return ( (val/16*10) + (val%16) );

void clkSync()
    getDateDs1307(&RTCsecond, &RTCminute, &RTChour, &RTCdayOfWeek, &RTCdayOfMonth, &RTCmonth, &RTCyear);
    setTime(RTChour,RTCminute,RTCsecond,RTCmonth,RTCdayOfMonth,RTCyear); // Set the Arduino System To Value retrieved from DS1307


Moderator edit: SIGH. and there are some CODE TAGS

I will ask before anyone else does. Please edit your post and put your program(s) in code tags = # above the smileys. It makes it so much easier to read as does taking out excess blank lines.

When RTCsecond goes to 0 as the minute changes will it be bigger than stepperSec (55 at the time) + 5 ? You need to reset stepperSec to zero when it rolls over 60.

How do I reset it back to 0 as it rollsover to 60? Sorry I'm really dumb at arduino...........

If (stepperSec >= 60) 
  stepperSec = 0;

You already have one if in your code. This works the same way.

If tried the code u suggest but it still doesn't work............. Why?

If tried the code u suggest but it still doesn't work............. Why?

Because it is incorrect? We can't see your code.

Please post your whole code, including the resetting of stepperSec

And tell us which version of the IDE you are using. That comment after Serial.flush() is crap.