hi so i can get my code to run a motor in my case just switched it out for an led when the LDR hits 900 however i want to stop it running after 10 seconds how could i do this?
my code is not good but i just dont know what to do. we did this millis thing in class and i thought that would help but idk
type or paste cint LED =10;
int motorLED=9;
long starttime = 0;
long currenttime = 0;
long duration = 10000;
void setup()
{
Serial.begin(9600);
pinMode(LED,OUTPUT);
pinMode(A0, INPUT);
pinMode(motorLED,OUTPUT);
}
void loop()
{
int sensorvalue = analogRead(A0);
Serial.println(sensorvalue);
delay(5);
if (sensorvalue>=900)
{
starttime=millis();
digitalWrite(LED,255);
digitalWrite(motorLED,HIGH);
}
currenttime=millis();
if(currenttime-starttime>=duration)
{
digitalWrite(motorLED,LOW);
delay(10000);
}
else
{digitalWrite(LED,0);
}
}
Basically its an automatic blind and light system when it gets dark enough the lights will turn on and the motor will turn for x time then stop. Problem is because its in an if LRD >=900 which it will be for hours because its night time the the motor will always run because iys it keeps looping the if