auto open/close blinds arduino code i need help

hi i`m having trouble understanding how to store the values if the blinds are open don’t do anything ect…

i`m using this code which open the blinds or starts the motor for 5 seconds then stops.
but its on a loop so after time limit set it starts motor for 5 more seconds rotating the blinds to a closed position (full rotation)

int LDR = 0;                                //analog pin to which LDR is connected, here we set it to 0 so it means A0
int LDRValue = 0;


int light_sensitivity = 200;  //This is the approx value of light surrounding your LDR
void setup()
  {
    Serial.begin(9600);            //start the serial monitor with 9600 buad
    pinMode(13, OUTPUT);     //we mostly use13 because there is already a built in yellow LED in arduino which shows output when 13 pin is enabled
    pinMode(12, OUTPUT);
    pinMode(8, OUTPUT);
    pinMode(7, OUTPUT);
    
    }
 
void loop()
  {
    LDRValue = analogRead(LDR);          //reads the ldr’s value through LDR which we have set to Analog input 0 “A0?
    Serial.println(LDRValue);                  //prints the LDR values to serial monitor
    delay(50);                                                //This is the speed by which LDR sends value to arduino
 
    if (LDRValue > light_sensitivity) 
      {
        openblind:
        digitalWrite(13, HIGH);
        digitalWrite(8, HIGH);
        delay(6000);
        digitalWrite(13, LOW);
        digitalWrite(8, LOW);
        delay (50000);
    
    }  
 else if (LDRValue < light_sensitivity) 
 closeblind:
      {        
        digitalWrite(12, HIGH);
        digitalWrite(7, HIGH);
        delay (6000);
        digitalWrite(12, LOW);
        digitalWrite(7, LOW);
        delay (50000);
      }
      }

any help would be Great i could insert a extra pin and add relay to break connection to motor until light changes but would prefer programing to do it

What i want is if ldr value > 200 put pins 13,8 high for 5 seconds then 13,8 low to stop motor and dont do anything until light levels go < 200 then put pins 12,7 high for 5 seconds then 12,7 low stop motor
i`m using pnp and npn transistors, to change direction of currant + - -+
thankyou in advance im new to this programing be gentle :slight_smile:

Why not have a simple variable like “blindsOpen” that maintains the state you last put the blinds into, and doesn’t change try to put the blinds into a state they’re already in?

which open the blinds or starts the motor for 5 seconds

I don’t see that in your code.

Please remember to use code tags when posting code.

guess its because i don’t know what your talking about :confused:
I have looked through examples and your tube cant find the anwser i want
is there a way of doing it and if there is can you point me in the right direction so i can read and work it out thankyou

The very simple way is,

if (condition_for_closing_blind)
{
  if (blindOpen)
  { 
    // run sequence to close blind
    blindOpen = false;
  }

I’ll leave you to figure out the other part.
Bonus marks for not using delay().

Your motor is going to run all the time just because your deadzone is 1 value wide. An ADC can easily flip between 2 values the input voltage is close to between, it's analog.

Why turn for 5 seconds? Why not until the light level is right, which may take 2 seconds. Given the narrow "happy range" the shades may never be just right.

Maybe use some pins for motor endstop sensors so you don't overdrive the motor and strip the coupling?

The reason i set it to turn motor on for 5 seconds was because it opens the blinds to a perfect position
the program reads a ldr (light sensor resistor) which measures light level when its greater than 200 it turn on pins 13,8 which send power to npn (negative positive negative) transistor <—pin 13 allowing negative voltage to pass through it (a switch) that turns on a pnp transistor (positive negative positive) pin 8 turns on a second npn (negative positive negative) so now i have + and - to motor it gets a little complicated but you get the picture

i would liked to have done it using programing
i`m new to Arduino and don’t know what the last guy was on about :confused:
but i will be looking into your idea of adjusting blinds to a certain light level

i have now added pin 6 high to the program which turns on a relay breaking the circuit to the motor and is working perfect does not turn off until light level drops

using the relay only took me ten mins to make and fit :slight_smile: trying to program Arduino over a week and loads of headaches :confused: