Running a set of servo commands only one time

I apologize but my lack of knowledge in this area is making it very hard to search and find the answer I need...and when i think i find an answer, I try to edit my code with what I do find and it will not compile.

In brief, my boiler will not fire when called upon by the thermostat. I need to manually lift a small plunger to have the boiler fire. I connected a wire to the plunger which runs to a servo that I have programmed to go from 0 to 180 degrees. When it turns, it pulls the wire over a pulley and the plunger raises resulting in the boiler firing. In order to control the board, I have the power supply plugged into a timer to cut on before I wake. Below is the code as I could piece together from multiple posts. When the board receives power, the program runs, pulling my wire along as the servo moves from 0 to 180 degrees. I have a delay of 45 minutes for the boiler to reach temperature before the servo returns from 180 to 0 effectively lowering the plunger back to its starting position. This is where I would like the program to end so that the timer can cut the board power and restart the cycle when the timer switches power back to the board.... I tried putting everything into the setup command but could not get it to compile, i tried an infinite loop at the end and couldn't get it to compile. I tried a void shutdown command...so I'm at a loss. Here is what i have, any help would be much appreciated. There may be a better way altogether. Also...Is there a limit to the delay I can put in, say if i wanted it longer than 45 minutes?

I also ordered a thermostat switch that could power on the board but i'm not sure that will help because the servo would not return to zero when the power was cut. At least it would automatically cut on via the thermostat and cut itself off via the end of the program.
Here is the code i have so far:

//code must include Servo.h library in order to work
#include <Servo.h>
Servo myservo;
//creates servo object to control a servo
int angle=0;
void setup()
{
myservo.attach(9); //attaches the servo on pin 9 to the servo object
}
void loop()
{
for (angle=0; angle<180; angle+=1)
//goes from 0 to 180 degrees in steps of 1 degree
{
myservo.write(angle); //directs servo to go to position in variable 'angle'
delay(20);//waits 20ms between servo commands
}
delay(2700000);
for (angle=180; angle>=1; angle-=1) //goes from 180 to 0 degrees
{
myservo.write(angle); //moves servo back in opposite direction
delay(20); //waits 20ms between servo commands
}
}

Thank you very much for your time and any advice you may be able to provide.

If I understand you right, moving the code which moves the servo from inside loop() up a bit to be inside setup() should do the trick.

Setup() runs once, loop() runs over and over....

EDIT... BUT... you really want to look at not using a 27 zillion millisecond delay, since that stops the board doing anything else in that time. Have a look at the BlinkWithoutDelay sketch in the IDE... file>examples...

I copied your code to my IDE and it compiles. Please share the errors that you received. There are better ways of delaying execution than delay(). Blink without delay example in the IDE (File, Examples, Digital). There is also no need for a delay in the loop where you move the servo unless you need it to moves slowly. Just tell it to go the 180 or whatever and give it time to get there.

Thank you for your replies. The code as I have it does compile. I just need it to not loop. I need it to go from 0 to 180 and hold with the board doing nothing for 45 minutes then return from 180 to 0 and do nothing more until power is cut and then supplied again for the program to run again.

JimboZA - if i move the movement code to the setup part... do i copy from the { before the for all the way to the last} and paste into setup... i tried to paste into setup but i could not get it to compile... I get differing errors as its expecting something i am missing.

You need to leave loop() with an intact pair of braces {}, thus, leave them behind when you cut and paste. The below compiles for me...

//code must include Servo.h library in order to work
 #include <Servo.h>
 Servo myservo;
//creates servo object to control a servo
 int angle=0;
 void setup()
 {
 myservo.attach(9); //attaches the servo on pin 9 to the servo object
 for (angle=0; angle<180; angle+=1)
//goes from 0 to 180 degrees in steps of 1 degree
 {
 myservo.write(angle); //directs servo to go to position in variable 'angle'
 delay(20);//waits 20ms between servo commands
 }
 delay(2700000);
 for (angle=180; angle>=1; angle-=1) //goes from 180 to 0 degrees
 {
 myservo.write(angle); //moves servo back in opposite direction
 delay(20); //waits 20ms between servo commands
 }
 }
 void loop()
 {
 }

BTW it's easier to read code if you tag it by selecting anf hitting the # icon above the :wink: :sweat_smile: icons; then it displays like mine.