Servo Issue: Noobie question

Hi, I had a servo working on my Spark Core a few years ago, I just replaced it with a Photon and cannot get the servo to work.

The LED blinks perfectly but the servo doesn’t move. I have it attached to A0, 3v and GND as I had with Spark Core.

Below is my code snippet.

Any idea?

Thanks.

Phil

Servo myservo; 

int pos = 0;    
int startPos=45;
int endPos = 125;
bool swinging = false;
int queue = 0;



void setup()
{
 Serial.begin(9600);
 pinMode(D7, OUTPUT); // sets the pin as output
//  Spark.function("kitty", swingArm);
}


void loop()
{
     digitalWrite(D7, HIGH); // LED on
     
     myservo.attach(A0);
     myservo.write(endPos);  
     delay(300);
     
     myservo.write(startPos); 
     delay(1000);
     myservo.detach();
     
     digitalWrite(D7, LOW); // LED off
     delay (5000);

 
}

For a servo you need a PWM capable pin, A0 is not one of them on the Photon

See docs (which should be consulted first ;-))
https://docs.particle.io/reference/firmware/photon/#analogwrite-pwm-

1 Like

Wow… thanks for such a quick reply… I had no idea that the pins were different.

I checked that the actual pinouts were the same but not the PMW…

Much appreciated.

Phil

2 Likes