Reading Servo Position Through Serial?

Hello I am kinda a noob at programming and electronics so bear with me, why can’t I simply Serial.println(Servo Position); to get the servo position in C? Here is my code and I am trying to get the servo position to output via serial, I don’t want to control the servo through the serial connections which is what Google gave me.

#include <Servo.h>

Servo servo1;
int pos = 0;

void setup()
{
  Serial.begin(9600);
  servo1.attach(9);
}

void loop()
{
  for(pos = 0; pos < 180; pos += 1)
  {                                 
    servo1.write(pos);            
    delay(15);                     
  }
  for(pos = 180; pos>=1; pos-=1)     
  {                               
    servo1.write(pos);           
    delay(15);    
  }
  Serial.println(pos);
  delay(1000);
}

why can't I simply Serial.println(Servo Position); to get the servo position in C?

You could, if you had a variable called "Servo Position".

The code you posted does something. What does it do?

PaulS:

why can't I simply Serial.println(Servo Position); to get the servo position in C?

You could, if you had a variable called "Servo Position".

The code you posted does something. What does it do?

Well it doesn't print to the serial terminal thats for sure, the code controls a servo by moving it between position 180 and 1 with a for loop to my understanding. I was using Serial.println(Servo Position); as an example, if you look at the code I called out to pos and variable pos exist but I am getting nothing via the terminal.

Without a servo actually attached, I get 0 in the Serial Monitor about every 6 seconds. Try your code without a servo attached. Do you get 0 every 6.4 seconds?

How about you just move your serial write statements to where the servos are actually being commanded to move?

#include <Servo.h>

Servo servo1;
int pos = 0;

void setup()
{
  Serial.begin(9600);
  servo1.attach(9);
}

void loop()
{
  for(pos = 0; pos < 180; pos += 1)
  {                                 
    servo1.write(pos);
    Serial.println(pos);
    delay(15);                     
  }
  for(pos = 180; pos>=1; pos-=1)     
  {                               
    servo1.write(pos);
    Serial.println(pos);
    delay(15);    
  }
 
  delay(1000);
}