"Smart" roller blind programing help

Hello, I wasn’t sure where to put this but I figured this would be close enought.

So I am trying to make my roller blind go up and down automagically. For this task I am using an Arduino clone, rtc 3231 and the BYJ48 Stepper Motor+driver.

My problem is that I can’t make the code work. What i want is for the arduino to pull up or down the rollerblind at a predetermined time.
Right now the problem is that the arduino starts to pull up/down the roller blind but won’t stop afer the 19500 steps and continues to do so until i unplug the arduino.

Ive tried to add digitalWrite(upp,HIGH); at both the beginning and end of the loop() segment, but it hasnt worked.

Thanks in advance for any help you can give me!

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

const int stepsPerRevolution = 2048;
Stepper myStepper = Stepper(stepsPerRevolution, 8, 10, 9, 11);
int upp = 12; 
int uppval = 20;
int ned = 13;  
int nedval = 0;   


RTC_DS3231 rtc;
 
void setup() {
 pinMode(upp, INPUT);
 pinMode(ned, INPUT);
 digitalWrite(upp, HIGH);
 digitalWrite(ned, HIGH);
 myStepper.setSpeed(10);
Serial.begin(9600);

delay(1000); 
  if (! rtc.begin()) {
    Serial.println("Couldn't find RTC");
    while (1);
  }
  if (rtc.lostPower()) {
    Serial.println("RTC lost power, lets set the time!");
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  }
}

void loop() {


 uppval = digitalRead(upp);
 nedval = digitalRead(ned);

    DateTime now = rtc.now();
    Serial.print(now.hour(), DEC);
    Serial.print(':');
    Serial.print(now.minute(), DEC);
    Serial.print(':');
    Serial.print(now.second(), DEC);
    Serial.println();

 
 if (uppval == 0 ){myStepper.step(-19900);} // 2Rotationer ned
 else {delay(100);}

 if (nedval == 0 ){myStepper.step(19900);} // 2Rotationer ned
 else {delay(100);}

delay(800);


  if (now.hour() == 07){ if (now.minute() == 20){ if (now.second() == 0){digitalWrite(ned,LOW); }}} //up something wrong with up/down but it works.
   else {digitalWrite(ned,HIGH);}

  if (now.hour() == 17){ if (now.minute() == 27){ if (now.second() == 0){digitalWrite(upp,LOW);}}} //up something wrong with up/down but it works.
   else {digitalWrite(upp,HIGH);}

}

One obvious issue is you have ned and upp configured as INPUT but you are doing digital writes to them!

Also, how is everything wired?

Defining a pin as INPUT and then setting it HIGH turns on the PULLUP resistors. The way to do that now is pinMode(pin, INPUT_PULLUP);

Try changing:
const int stepsPerRevolution = 2048;
to
const int stepsPerRevolution = 64;

The reason is that motor has a step angle of 5.625 degrees. 360/5.625 = 64 steps per revolution.

PickyBiker:
Defining a pin as INPUT and then setting it HIGH turns on the PULLUP resistors. The way to do that now is pinMode(pin, INPUT_PULLUP);

Try changing:
const int stepsPerRevolution = 2048;
to
const int stepsPerRevolution = 64;

The reason is that motor has a step angle of 5.625 degrees. 360/5.625 = 64 steps per revolution.

You are correct but I assumed he wanted to use those as outputs.

Good catch on the motor!

Hi, The reason that ned and upp (swedish for up and down) are INPUTS is because I have buttons connected to them to "manually" raise and lower the roller blind.
Reading your feedback gave me an idea, im going to try and add myStepper.step(-19900) in the if tag.

EDIT: So it worked perfectly. Sometimes the best solution is the easiest one.

Thanks for the help!

JustAnotherCreator:
Hi, The reason that ned and upp (swedish for up and down) are INPUTS is because I have buttons connected to them to "manually" raise and lower the roller blind.

Just so you understand... using a digitalWrite with an input DOES NOT set the input value, it only modifies whether the internal pullup resistor is enabled or not and is not the recommended way of enabling/disabling the internal pullup.

The following is from the digitalWrite reference:

"If the pin is configured as an INPUT, digitalWrite() will enable (HIGH) or disable (LOW) the internal pullup on the input pin. It is recommended to set the pinMode() to INPUT_PULLUP to enable the internal pull-up resistor. See the Digital Pins tutorial for more information."

Yes, I see that I will have to do more reading before starting a new project. Can I just ask if i understand this correctly. You use the INPUT_PULLUP resistor when you are going to for example check if a button is pressed or not?

JustAnotherCreator:
Yes, I see that I will have to do more reading before starting a new project. Can I just ask if i understand this correctly. You use the INPUT_PULLUP resistor when you are going to for example check if a button is pressed or not?

If you have an input that is active LOW (i.e., LOW means "active", or in the case of a button "pressed") and the "not active" state is a no connect. When there is no connection to the input the pullup resistor holds the input HIGH until the button is pressed (LOW).

For the above to work correctly you should have one terminal of your button connected to GND and the other connected to the input. That way when you press the button the input is connected to GND and reads LOW. When the button is not pressed there is no connection to the input, hence the need for the pullup resistor.

Pullups illustrated