int motorPin1 = 8;
int motorPin2 = 9;
int openTime = 6*60*60 + 30*60; // 6:30 AM in seconds
int closeTime = 18*60*60; // 6:00 PM in seconds
unsigned long currentTime;
unsigned long openTimeMillis = openTime*1000;
unsigned long closeTimeMillis = closeTime*1000;
unsigned long startMillis;
void setup() {
pinMode(motorPin1, OUTPUT);
pinMode(motorPin2, OUTPUT);
startMillis = millis();
}
void loop() {
currentTime = millis() - startMillis;
// check if it's time to open
if (currentTime >= openTimeMillis) {
// move the linear actuator out
digitalWrite(motorPin1, HIGH);
digitalWrite(motorPin2, LOW);
delay(10000);
// stop the motor
digitalWrite(motorPin1, LOW);
}
// check if it's time to close
if (currentTime >= closeTimeMillis) {
// move the linear actuator in
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, HIGH);
delay(10000);
// stop the motor
digitalWrite(motorPin2, LOW);
}
}
I have a linear actuator connected to pins 8 and 9 on an uno. I want it to retract at 6:30 am and Extend at 6:00 pm. also, what time is set when i power on the arduino currently? will it extend and retract at the proper times?
im kinda new to this, dont really know what im doing..
Ill get back to you in about 2 hours.... busy currently. It is for an automatic chicken door. I was going to use photoresistor but decided timed would be easier.
I would prefer to use a clock not a photoresistor. I have the actuator connected to 8 and 9 digital imput. That is it for connections.
Btw, i am currently only running it off a usb on my pc for testing. Final will be the dc connector connected to the solar charge controller.