Arduinon Uno loses time sync

Hi i am running a very simple code in which an arduino uno is controlling a stepper motor and drives it a few steps after every 3 minutes. (for use in dithering of declination axis in Astrophotography). It works like a charm for the first 1.5 to 2 hours and then all of a sudden it loses its sync almost as if it has reset itself. the reset happens randomly and then the sync is off and the motor starts moving during camera exposures.
Please help
will post the code below.
Best Regards

When you get around to that, please also post hardware details. Please read:

@hassaanzaheer
Why did you post in the Uncategorised section of the forum when its title is plainly

DO NOT CREATE TOPICS IN THIS CATEGORY

Your topic has been moved to the Programming section of the forum

sorry first time posting here

...just now.

Hardware:
Arduino Uno (powered with a brick and with laptop usb) and a 28BYJ-48 stepper motor (5v) (powered thru the arduino board).

You must not have read the link I posted. Here is some text from it:

We need to know exactly what hardware you have. We need to know what Arduino board (or other brand, such as ESP32) you are using and exactly what other hardware you are connecting it to. The more details we have, the easier it is to help.

and

The language of electronics is a schematic or circuit diagram. Long descriptions of what is connected to what are generally useless. A schematic is a drawing of what connects to what; please make one and photograph it. We don't mind if it's hand drawn, scruffy and does not use the correct symbols. Please don't post Fritzing diagrams.

Also, it looks like you posted your code in quote tags, not code tags... after auto-formatting, you can see the code blocks better too:

#include <Stepper.h>

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

void setup() {
  // set the speed of the stepper motor
  myStepper.setSpeed(10);
  // RPM
}

void loop() {

  {
    delay(180000);
  }
  // rotate 10 steps in one direction
  for (int i = 0; i < 1; i++) {
    myStepper.step(-stepsPerRevolution / 45);

  }

  // wait for 3 minutes
  {
    delay(180000);
  }

  // return to the original direction
  for (int i = 0; i < 1; i++) {
    myStepper.step(stepsPerRevolution / 45);
  }

  {
    delay(180000);
  }
  // wait for 3 minutes

  // rotate 10 steps in the opposite direction
  for (int i = 0; i < 1; i++) {
    myStepper.step(stepsPerRevolution / 45);
  }

  {
    delay(180000);
  }
  // wait for 3 minutes

  // return to the original position
  for (int i = 0; i < 1; i++) {
    myStepper.step(-stepsPerRevolution / 45);

  }
}
1 Like

1 is not the same as 10.

Err...

yeah sorry initially the code was written for 10 steps. it was changed later on

i will try to make a diagram in the morning as for the board the supplier website states its an arduino uno R3 SMD board.

Why?

because the steps were too big.

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the < CODE/ > icon above the compose window) to make it easier to read and copy for examination

#include <Stepper.h>

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

void setup() {
  // set the speed of the stepper motor
  myStepper.setSpeed(10);
  // RPM
}

void loop() {
  
  {
   delay(180000);
  }
  // rotate 10 steps in one direction
  for (int i = 0; i < 1; i++) {
    myStepper.step(-stepsPerRevolution/45);
    
  }
  
  // wait for 3 minutes
  {
    delay(180000);
  }
  
  // return to the original direction
  for (int i = 0; i < 1; i++) {
    myStepper.step(stepsPerRevolution/45);
    }
    
  {
    delay(180000);
  }
  // wait for 3 minutes
  
  // rotate 10 steps in the opposite direction
  for (int i = 0; i < 1; i++) {
    myStepper.step(stepsPerRevolution/45);
    }
  
  {
    delay(180000);
  }
  // wait for 3 minutes
  
  // return to the original position
  for (int i = 0; i < 1; i++) {
    myStepper.step(-stepsPerRevolution/45);


  }
}

power the motor separately. The Arduino +5v line is for input or no more than an LED or two.

So, you're never going to update the comments?

...or simply delete the for loop?

... and the superfluous {} braces.

11 posts were split to a new topic: ESP32 Clock Accuracy