Moving Servos On The Hour W/ DS3231 RTC Module

Hi, new to the forum here, hopefully this is the correct sub-forum for this

I am trying to build a simple device that will open and close my window blinds at certain hours of the day using two servos and a DS3231 real time clock module. My code checks out as far as I can tell, doesn’t throw any errors, but when the time elapses that I programmed it to move the servos at, nothing happens. I checked all my connections and tried different servos just to make sure they weren’t duds, but still nothing. I confirmed the correct time is stored on the RTC by running the ReadTest example sketch as well. Any tips are appreciated. My code is attached.

#include <DS3231.h>

#include <Servo.h>

#include <Wire.h>

// Variable for real time clock
DS3231 rtc(SDA, SCL);

Time t;

//Servo object
Servo servo1;

int pos = 0;

void setup() {

  servo1.attach(9);
  Wire.begin();
  rtc.begin();

}

void loop() {

//Retrieve current time from RTC
t = rtc.getTime();

 //If time matches, move servos
 if (t.hour == 12 && t.min == 55 && t.sec == 00);
    { servo1.write(170); 
      delay(5000);
    }    
}

Please attach code the way adviced, using code tags, and the wiring diagram.

Try a simple test that doesn't reference the time to prove to yourself that you can get your servo to move. What's powering it?

I already have. I confirmed these servos function using the sweep example sketch. Right now they're on a bread board but once the code is worked out, they will be independently powered and run off a motor shield.

Wiring showing present powering.

This line has a semicolon that should not be there:

 if (t.hour == 12 && t.min == 55 && t.sec == 00);

As it is, it means that the servo move and delay should be executed on every iteration of loop. Since there's no movement, either the servo is already in position, or more likely I suspect, you have a power issue.

Most servo problems reported on this forum are caused by inadequate servo power supplies, such as trying to use the Arduino 5V output. Doing so can damage the Arduino, too.

Use a separate servo power supply 5-6V, capable of at least 1 Ampere per servo, and connect the grounds.

Also, breadboards are not intended for high current, and the tracks will burn when used with servos or other motors. Solder the servo power connections to the servo power supply, or use high quality power connectors.

OK,

I removed the breadboard from the equation and hooked up the servo to its own external 5V power supply, but still nothing. I know for certain this servo functions so it cant be power or defective servo.

I would show a wiring diagram like some are asking for but I dont know how to make one besides just attaching a picture from my phone.

Have you tried a simple sweep sketch?
One that doesn’t have unnecessary semicolons

What is this?

 //If time matches, move servos
 if (t.hour == 12 && t.min == 55 && t.sec == 00);

It makes the if-statement a NOP operation and the code lines below are executed every turn in loop.

Railroader:
What is this?

 //If time matches, move servos

if (t.hour == 12 && t.min == 55 && t.sec == 00);


It makes the if-statement a NOP operation and the code lines below are executed every turn in loop.

Pssst - reply #5

Telling 3 times looks like needed.

Removing the semi colon did not change anything.

And the code lines below that statement looping is intentional. So long as the time matches whatever I set it too, I want the servos to move every day at that time in order to open and close the window blinds.

Thats okey but when the servo has moved one time, to that position, what will happend later? It will be commanded to go for the same postion, where it is standing, over and over again.

robinhood3015:
Removing the semi colon did not change anything.

…is the wrong answer

TheMemberFormerlyKnownAsAWOL:
...is the wrong answer

I guess I don't understand what you're asking for.

I’m not asking for anything, I’m simply pointing-out a fallacy

Railroader:
Thats okey but when the servo has moved one time, to that position, what will happend later? It will be commanded to go for the same postion, where it is standing, over and over again.

That makes sense, it's still the rough draft. I'm just trying to get the first movement to occur at all so I can have proof of concept. Once that works I can alter the code so the servo runs backwards from its "closed" position to open the window blinds.

I just need to know why the servo is not responding on the time its programmed to. I have confirmed the RTC has accurate time, I confirmed the servo is functioning using a different sketch, and I have removed the bread board and given the servo it's own 5V power supply.

If I have all that, what am I missing?

There's not many things that can be wrong with a setup like that.

I'd be inclined to run sweep again to verify that the servo works with the wiring as you have it now. Then Run your code with the addition of a serial.print statement (and begin of course) that tells you when the servo should move.

How, when, is the servo moving back from its "close" position? Running that code again and again looks useless to me. The servo will be standing still in the close position.