I have a problem with Servo library. This is my (very short XD) "code":

#include <Servo.h>

void setup() {
  Servo.attach(9, 554, 2400);

void loop() {

And it returns:

Arduino:1.6.5 (Windows 7), Board:"Arduino Mega or Mega 2560, ATmega2560 (Mega 2560)"

sketch_aug24a.ino: In function 'void setup()':
sketch_aug24a:4: error: expected unqualified-id before '.' token
sketch_aug24a.ino: In function 'void loop()':
sketch_aug24a:8: error: expected unqualified-id before '.' token
expected unqualified-id before '.' token

Like there is no included library. What can I do with it ?


Servo is a class not an object. You have to instantiate it, and then call the functions on the instance. For example:

#include <Servo.h>

Servo sv;

void setup() {
  sv.attach(9, 554, 2400);

void loop() {

(Unlike some other libraries, it's done this way so that you can use more than one servo at the same time. You'd make one instance for each servo you want to control.)

|improve this answer|||||
  • Oh, I get it :o Clever! – Nicolas Aug 24 '15 at 11:19
  • But I think, my servo is broken ;_;, dammit xd – Nicolas Aug 24 '15 at 11:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.