Hey there...
I'm fiddling with something as simple as the following.
If light is detected turn on motor power supply and run motor CW for 20sec then turn off motor power supply. If light is off turn on motor power supply and run motor CCW for 20sec then turn off motor power supply.
But don't know how to put it together... is it like this...?
https://ibb.co/FVMRp9q
As you can see I can run the motor without the LDR... But how can/will the code look when the LDR need to turn on the external power supply and run motor for 20sec and then turn it off again...? and I guess I need a resistor on this as well...?
//defines pins
const int stepPin = 6; //PUL -Pulse
const int dirPin = 7; //DIR -Direction
const int enPin = 8; //ENA -Enablevoid setup(){
//Sets the pins as Outputs
pinMode(stepPin,OUTPUT);
pinMode(dirPin,OUTPUT);
pinMode(enPin,OUTPUT);
digitalWrite(enPin,LOW);
}void loop(){
//Enables the motor direction to move
digitalWrite(dirPin,HIGH);
//time of rotation
for(int x = 0; x < 5000; x++){//Rotation speed
digitalWrite(stepPin,HIGH);
delayMicroseconds(300);
digitalWrite(stepPin,LOW);
delayMicroseconds(300);
}//delay before spinning
delay(6000);//Changes the rotations direction
digitalWrite(dirPin,LOW);
//time of rotation
for(int x = 0; x < 5000; x++) {//Rotation speed
digitalWrite(stepPin,HIGH);
delayMicroseconds(300);
digitalWrite(stepPin,LOW);
delayMicroseconds(300);
}//delay before spinning the other dir
delay(6000);
}
BTW im building a lift which will raise and lower my loudspeakers behind the sofa when the computer next to the sofa is on and off... will upload photos later on when the contraption is done... (tomorrow)

