Go Down

Topic: Impossible to set an initial position for my Servo  (Read 285 times) previous topic - next topic

zerhorace

Hi !

I'm a bit lost ... After reading and applying a lot of answers from the forum, it's still impossible to set an initial position for my servo : Servo PDI 6225MG 300 (it can rotate up to 295°)


This Servo works fine, I've used it for lots of projects but I can't set an initial position, at the start the Servo doesn't want to move.
Do you have any idea why ?

Code: [Select]

#include <Servo.h>
int val = 0;
int pot;
Servo moteur;
int bouton;

void setup() {
  moteur.write(100);
  moteur.attach(9);
  pinMode(2, INPUT);
  Serial.begin(9600);

}

void loop() {
}

slipstick

That technique works with all the servos I've tried. Does the servo go to the correct position if you do the write(100) immediately AFTER the attach(9)?

Perhaps it's a power or wiring problem. That servo looks like it will need a lot of initial current to get it to start moving, so it mustn't be powered from the Arduino 5V and it should not be connected through a breadboard.

Steve


zerhorace

Like that ?
Code: [Select]
#include <Servo.h>
int val = 0;
int pot;
Servo moteur;
int bouton;

void setup() {
  moteur.attach(9);
  moteur.write(100);
  pinMode(2, INPUT);
  Serial.begin(9600);

}

void loop() {
}


outsider

You did your setup() function backward from the way @slipstick showed you, look again:
Code: [Select]
void setup() {
  moteur.write(100);
  moteur.attach(9);
  pinMode(2, INPUT);
  Serial.begin(9600);
}

Do you have a pulldown resistor (10k) on pin 2? Where is servo power coming from?

Go Up