Arduino and Servo for telescope dust cover removal

I've got a 270 degree servo, 20Kg, DSSERVO RDS3218 I want to use to remove the dust cover off a remote telescope using an Arduino Uno. The cover will be moved over the servo until it's laying flat on the top of the telescope. I don't think the servo actually moves 270 degrees but that's sort of immaterial. What I need it to do is remove the cover then wait up to six to eight hours to put it back in position. My guess is setting one of the analog pins to look for 5V by having a switch on the observatory dome that is activated when the dome begins to close. First problem I have being a noob to Arduino coding is the void loop where I get nothing but back and forth nonstop.
Here's my start at coding it:

#include <Servo.h>

Servo servo;

void setup() {

servo.attach(2); //use Pin 2

servo.write(0);

delay(2000);

}

void loop() {
}

servo.write(180);

delay(1000);

servo.write(0);

}

How do I get it to just move the 270 degrees and stop and wait for an unspecified time? The Arduino is run off a 5V power supply so power isn't a problem.
How do I code in for the Arduino to look for a 5V signal on a pin then close the cover? In the long run I want to have two identical systems for two telescopes of different diameter. but only one in use at a time. Any help appreciated.

Lenny

someSwitchState = digitalRead(someSwitchPin);
if (someSwitchState == LOW) {
... move your servo
}

I left out state detection and pin initialization. I don't understand your other questions. Can you explain better what components you have, how they are connected (diagram would be better).

Why would you use an analog pin for a switch? They're digital. An 8 hour delay looks like

delay(8L * 60 * 60 * 1000);

But it's not clear whether you want to just wait 8 hours, or wait for a switch closure, or both?

A picture is worth a thousand words: Automatic Telescope Cover with built in Technolight Flat Panel - A YouTube vid of what I want to build.
The thing is in the remote observatory the shutter on the dome opens. I open the telescope cover. I want it to just stop and wait for the shutter to close at some point during the night/early morning. I just picked one of the analog pins (what do I know?) and putting 5V on it as the signal to close the cover. In reality the cover could be open for a few hours or most of the night so the Arduino has to wait. Perhaps someone has a better idea. The Arduino weighs nothing and neither does the servo. The cover weighs more. Laid back in the 270 degree position it doesn't get effected by any breeze that happens to get in the observatory.

Please don't link me to yet another YouTube video. It is not a picture. Just provide the information that we need, in the thread if it is not impossible.

Also you wouldn't normally use an analog signal to read a switch. That's digital. On and Off. You didn't respond to that, which I already mentioned. You didn't answer my last question, either. It's going to be difficult to help you if you don't provide answers.

I did provide code to do the function that you have explained so far. Have you investigated or tried using it?

Can you summarize your needs succinctly so that it will be easier to translate into code? Something like, "the door should remain open until either the switch is activated, or 8 hours has elapsed"?

O.k. back to basics. Have you tested your servo to check that it will move the cover? Your original test code will do for that.

Then you need to wire a switch so it gives 5V in one condition and 0V (gnd) in the other. You would normally use a microswitch for that. Do you have one? Have you tested that to see that you can tell what position it's in?

With those two things done you're 95% there.

Steve

Yes the Arduino will move the servo. But the void loop keeps it going back and forth. Can't have that. I want it to start in the "0" closed position then open 270 degrees (or near it)

Yes I have a microswitch...several in fact. Have not tested it yet. Yes, I can put the switch on a multimeter and determine which position it's in. As I said before first thing I'd like to do is stop the loop. Thanks.

Forget the programmer speak. Just explain exactly what you need to happen, and under what conditions. In English.

If you just need help programming for a micro switch, there are applicable example sketches in the Digital section of the IDE example sketch tab. I also provided code in reply #2, you haven't commented on it at all.

It's hard to make recommendations for programming a system that doesn't exist yet. Not unless there is a full specification (which you haven't provided).

No you don't want to stop the loop. If you completely stop the loop it will no longer be reading the switch so it will never notice when it changes.

I think what you want is for the servo to initialise at position A, then move to some other position B, wait until a switch changes to some specific value and then move the servo to position A. Correct?

So the cover has opened and some time later closed. Does it really need do this only once? If not what causes it to open again?

Steve

That is correct. I want the servo to initialize at position A 0 degrees (closed) and open to position B 270 degrees (open) and stay there until the signal from the switch or other source says go back to position A 0 degrees closed.
What is happening is I'm starting a astronomy CCD imaging session that will run as long as the weather conditions allow. If the session times out then the observatory shutter (the opening in the dome) will be commanded to close. Another variable is the weather sensor will notice that clouds or rain have appeared and order the shutter to close and home the telescope. Either case can happen at any time of the night Therefore the order to close the telescope cover has to come from some sensor to the Arduino. The only two components are the Uno and the servo. I have two microswitches which I can use but then it has to be read somehow by the Arduino which is four feet away. Maybe a Wifi signal?

See my reply to Slipstick . If you can't follow what I'm after then I don't know what to say. I provided the little code I have so far in my first post and have outlined what the system is required to do over an extended period of time. I have not placed the switch into the system because I don't know how it's connected to the Arduino or even if using a switch is the best thing to do.

4 ft of wire connecting a switch to the Uno is not a problem. Just a twin cable with one wire from one side of the switch to any digital pin and the other wire to the Uno GND connection. Then use the normal technique to read the switch.

But then how do I have the Arduino wait until hours have passed? Set pin X low, an If/then statement?

See reply #2.

OK That makes sense now. I'll wire that up as a test fixture and try it out. Thanks.

Yes, the important thing is to get started. Then come back with what you have, it will be something concrete that we can offer specific advice on.

Here's the latest cut at my program but something isn't right:

#include <Servo.h>
#include <TN_SwitchState.h> //include this library
Servo servo; //Set Servo to servo

void setup()
{
const int Switch_Pin(9); //5V switch connects to this pin

servo.attach(2); //servo attached to pin 2

pinMode(Switch_Pin, HIGH); //set pin mode for switch

servo.write(0); //set servo state at 0

delay(2000);

}

void loop()

{

servo.write(180); //move servo to 270 degrees

int SwitchState = 0; //set switchstate as no voltage

SwitchState = digitalRead(Switch_Pin);

//Set SwitchState to what is the status of pin 9

if (SwitchState == LOW) //If 5V present then

servo.write(0); //move the servo to closed position

}

What is it?
By the way, did you read the documentation and/or look at the examples of the 'TN_SwitchState' library that you included?

Yes I did. several different ways to read a switch.

SwitchState = digitalRead(Switch_Pin);

gives me an error message "Switch_Pin not declared in this scope"

You're taking guesses at C++ syntax, and at Arduino syntax. That is not ever likely to succeed. Look at the digital and servo examples in the IDE to see how it's done.

This will at least compile:

#include <Servo.h>
Servo servo; //Set Servo to servo
const int Switch_Pin = 9; //switch connects to this pin

void setup()
{
  pinMode(Switch_Pin, INPUT_PULLUP); //set pin mode for switch
  servo.attach(2); //servo attached to pin 2
  servo.write(180); //set servo position at 180

}

void loop()

{
  //Set SwitchState to what is the status of pin 9
  int SwitchState = digitalRead(Switch_Pin);

  if (SwitchState == LOW) { //If 0V present then
    servo.write(0); //move the servo to closed position
    while (1);
  }
}

This assumes you used the wiring in reply #11.

OK I'll try this. I had it the other way around but cutting the 5V works too. Going from 0 to 5V instead of 5V to 0. Thanks.