Automated curtain with ds3231, arduino uno and nema 17

Hi, I am pretty new to this but I am trying to make my curtain go up and down at specific times using the rtc module ds3231. all the components work on their own. my idea is that I connect the rtc module, stepper driver and relay module to the arduino uno. from the relay I connect the stepper motor because it needs 12v and the arduino cant provide that voltage.

any tips to make it work or do I need more components?

The code I have done is this:

#include <DS3231.h>
#include <Stepper.h>
#include "RTClib.h"

int Relay = 4;

RTC_DS3231 rtc;

char weekDays[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

const int OnHour = 7; //SET TIME TO ON RELAY (24 HOUR FORMAT)
const int OnMin = 00;
const int OffHour = 7; //SET TIME TO OFF RELAY
const int OffMin = 30;

//const int OnHourAfternoon = 17;
//const int OnMinAfternoon = 00;
//const int OffHourAfternoon = 18;
//const int OffMinAfternoon = 40;


void setup() {
  Serial.begin(9600);
  rtc.begin();
  pinMode(Relay, OUTPUT);
  digitalWrite(Relay, LOW);   
}


bool ifWeekend(int day) {
  if (day == 6 || day == 0) {
    return (true);
  } else {
    return (false);
  }
}

 DateTime t = rtc.adjust(DateTime(F(__DATE__),
F(__TIME__)));

void loop() {
  DateTime now = rtc.now();
  Serial.print(t.hour);
  Serial.print(" hour(s), ");
  Serial.print(t.min);
  Serial.print(" minute(s)");
  Serial.println(" ");
  delay (1000);
  
  if(t.hour == OnHour && t.min == OnMin){
    digitalWrite(Relay,HIGH);
    Serial.println("LIGHT ON");
    }
    
    else if(t.hour() == OffHour && t.min == OffMin){
      digitalWrite(Relay,LOW);
      Serial.println("LIGHT OFF");
    }

  if(OnHour >= 7.00 and Onmin <= 7.30) up()
  if(t.hour >= 18.00 and t.min <= 18.30) down()
}

void up() {
  // step one revolution in the other direction:
  Serial.println("counterclockwise");
  myStepper.step(-stepsPerRev);
  delay(1000);
}

void down() {
  // step one revolution  in one direction: 
  Serial.println("clockwise");
  myStepper.step(stepsPerRev);
  delay(1000);
}
1 Like

This project comes up regularly.
Post a schematic.

A stepper motor needs a stepper motor driver, not a relay. Post the stepper data sheet if you want help choosing a driver.

I have a steppar motor driver

This project does not need a stepper motor. Stepper motors are used in 3D printers, laser cutters, CnC routers etc because highly accurate and repeatable movements are needed. Do you need to control the height of your curtain with sub-millimetre accuracy?

Stepper motors have many disadvantages. They are complex, expensive, inefficient and low torque compared to other types of motor of similar size.

I suggest you consider changing to a geared DC motor.

Alright thanks for the tip but i haven't found any good geard motors, can you link a good motor?

I cannot recommend any particular motor.

You say you cannot find any geared DC motors that are "good". What criteria are you using?

the criteria I have is that it will be easy to use/code and also I already have worked with stepper motor so I kinda knew what I do

Any DC motor will be easier to use/code because they are so much simpler. For curtains you do not need speed control, only direction control. An H-bridge module or a pair of relays is all that is required to control it. Plus, of course, limit switches to sense when the curtains are fully open or closed, which you would need with any kind of motor.

To know what is a "good" motor for you, you need to know something about the torque or force required to move the curtains. How will you measure that?

If you have worked with stepper motors before, how is it you thought you could control a stepper motor with a relay?

ive worked with it and i kinda knew what I did with a stepper motor but i use the stepper motor for my blinds, not curtains, a miss of mine.

Pololu has a good line of geared DC brushed motors and also motor drivers.

Choose a motor that has the required torque then pick a driver that can handle the motor rated voltage and stall current.

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