servo motor init

Hello Arduino users

I'm simulating a barrier system

I would like my servo to stay at zero position on start ...
I mean : as I upload the code to the board : the servo moves to a position quickly then waits ...

here's the code I found :

//Tell the Arduino Ide to include the Servo.h library.
#include <Servo.h> 

const int TouchPin=2; //touch sensor sur D2

// create servo object to control a servo
// a maximum of eight servo objects can be created


// variable to store the servo position 

Servo myservo;
int pos = 0;    


void setup() {
    
    pinMode(TouchPin, INPUT);
   

// attaches the servo on pin 8 to the servo object
  myservo.attach(8);     //servo pin
  }

void loop() {
    int sensorValue = digitalRead(TouchPin);
    
    if(sensorValue==1) 
    
   {
 for(pos = 0; pos < 90; pos += 1) // goes from 0 degrees to 180 degrees
 {         // in steps of 1 degree
 myservo.write(pos);    // tell servo to go to position in
          // variable 'pos'
 delay(15);      // waits 15ms for the servo to reach
          // the position
 }
 {delay(5000);}
 for(pos = 90; pos>=1; pos-=1)  // goes from 180 degrees to 0 degrees
 {       
 myservo.write(pos);    // tell servo to go to position in
          // variable 'pos'
 delay(30);      // waits 15ms for the servo to reach
          // the position
 }
}}

thanks for your help

Try putting myservo.write(NNN); before myservo.attach(); where the NNN is the starting position you want.

...R