RTC module is not working with out opening the serial monitor IDE

Hello im trying to develop fish feeding machine at standard time .
I connected the RTC module and some servo motors to arduino and tried running the below code .
This is working fine only when Serial monitor IDE is opened .
This is not working if IDE is not open

[color=#741b47]#include <Wire.h>

#include <ds3231.h>

#include <Servo.h> 

int servoPin = 9;

int temp = 20;  //every day at 8 

Servo Servo1;





 

struct ts t; 

 

void setup() {

  Serial.begin(9600);

  Wire.begin();

  DS3231_init(0);

  Servo1.attach(servoPin);

  

 
/*----------------------------------------------------------------------------

  In order to synchronise your clock module, insert timetable values below
!

 
----------------------------------------------------------------------------*/

  t.hour=7; 

  t.min=19;

  t.sec=40;

  t.mday=06;

  t.mon=01;

  t.year=2021;

  DS3231_set(t); 

}

 

void loop() {

  DS3231_get(&t);

  Serial.print("Date : ");

  Serial.print(t.mday);

  Serial.print("/");

  Serial.print(t.mon);

  Serial.print("/");

  Serial.print(t.year);

  Serial.print("\t Hour : ");

  Serial.print(t.hour);

  Serial.print(":");

  Serial.print(t.min);

  Serial.print(".");

  Serial.println(t.sec);

   

  delay(1000);

  if(temp == t.min)

  {

    Servo1.write(0);     

    Servo1.write(90);   

    Servo1.write(180);

    delay(1000); 

    return; 

  }

    

  

}[/color]

Can you please suggest me some way to solve my issue .

When you open the serial monitor, it resets the Arduino. Apart from that there should be no difference between having serial hooked up to the monitor and not.

Try running without the monitor and press the reset button. What does it do?

Also, how do you know it's failing?

I waited till the if condition executes . but could not see the servo motors working .
If i ope the IDE then when if condition is reached servo motors started running

Yaa with the reset its working fine :slight_smile:

What model of Arduino do you have?

In the above code after the reset only once its is working fine
and again it is not working . Im not getting the reason for it .

I am using Arduino UNO

Hello im trying to develop fish feeding machine at standard time .

I connected the RTC module and some servo motors to the arduino .
My aim of this project is for every defined time i.e 10’oclock the servo motors has to move .
When i open the serial monitor the RTC module is working fine but when i connected to the external power supply the servo motors are not moving at 10’o clock .
I am using ARDUINO UNO
NOt sure the reasom for it

Attachig the code

#include <Wire.h>

#include <ds3231.h>

#include <Servo.h>

int servoPin = 9;

int temp = 10; //every day at 10

Servo Servo1;

struct ts t;

void setup() {

Serial.begin(9600);

Wire.begin();

DS3231_init(0);

Servo1.attach(servoPin);

/*----------------------------------------------------------------------------

In order to synchronise your clock module, insert timetable values below !

----------------------------------------------------------------------------*/

t.hour=8;

t.min=33;

t.sec=10;

t.mday=27;

t.mon=01;

t.year=2021;

DS3231_set(t);

}

void loop() {

DS3231_get(&t);

Serial.print("Date : ");

Serial.print(t.mday);

Serial.print("/");

Serial.print(t.mon);

Serial.print("/");

Serial.print(t.year);

Serial.print("\t Hour : ");

Serial.print(t.hour);

Serial.print(":");

Serial.print(t.min);

Serial.print(".");

Serial.println(t.sec);

delay(1000);

if(temp == t.hour)

{

Servo1.write(0);

Servo1.write(90);

Servo1.write(180);

delay(1000);

return;

}

}

Please edit your post and add
** **[code]** **
before your code and
** **[/code]** **
after your code.

Also please get rid of unneeded empty lines; use them to separate blocks of code, not after every statement.

Please follow the advice on posting code given in posting code

In particular note the advice to Auto format code in the IDE and to use code tags when posting code here as it prevents some combinations of characters in code being interpreted as HTML commands such as italics, bold or a smiley character, all of which render the code useless

@saimanjusha

TOPIC MERGED.

Could you take a few moments to Learn How To Use The Forum.

Other general help and troubleshooting advice can be found here.
It will help you get the best out of the forum.

The usual reason for servo problems is lack of power. How are yours wired up?

I am using the 9V battery for powering the arduino and related peripherals

One of those square PP3 ones?

@OP

Can you provide a link or the type number of the Servo you are using?

One your servo has moved then it can’t move again and is stuck at 180 deg, and the instruction will keep on repeating for a whole hour at 10 o’clock trying to move it on , but once at 180 it can’t move on .

It would help you to put a few print statements into your loop so you can see what is happening and help you debug it .

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