Hello. I am new to arduino. I need help programming a timer for a servo motor. I have a ventilation hole that I want my sevo motor to open that hole every 60 minutes and keep it open for 5 minutes and then close it again and so every 60 minutes. The start would be every time it received power, meaning not at a specific time but from the start of the power supply
what type of servo motor is it?
SG 90 micro
Do you know how to use the servo library?
Also, you can use the delay function or the millis function for waiting in between servo movements.
I have no idea. Can you do a short tutorial?
Google;
arduino servo tutorial
Tom..
Based on this example, something like this then:
(Compiles, NOT tested!)
#include <Servo.h>
Servo myservo; // create servo object to control a servo
#define WAIT_TIME 3600 //time between openings in seconds
#define OPEN_TIME 300 //duration vent is kept open in seconds
uint32_t oldtime, second_count;
uint8_t pos = 0; // variable to store the servo position
void setup() {
myservo.attach(9); // attaches the servo on pin 9 to the servo object
oldtime = millis();
second_count = 0;
myservo.write(pos); //initialise servo to 'close' position (TBC)
}
void loop() {
if (millis() - oldtime >= 1000) { //enter if statement approx every 1000ms
++second_count; //increment counter
if (second_count == WAIT_TIME) {
pos = 180;
myservo.write(pos); //got to 'fully open' positon (TBC)
}
else if (second_count == WAIT_TIME + OPEN_TIME) {
pos = 0;
myservo.write(pos); //got to 'fully close' positon (TBC)
second_count = 0; //reset second counter
}
oldtime = millis();
}
}
that should at least get you started!
as for the rest, as other ppl here has advised, do some online self-learning!
hope that helps...
I will try to test it and refine it if necessary. Thank you
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.