I'm trying to programme a servo motor to reach certain positions. I have a 360 degrees servo motor, so I can not use the Servo library and I can only control the speed. Therefore I want to regulate the time for the pulse. The setup is simple, 5 V, GND and pin 9 from the Arduino to the motor.

int servo1 = 9;

void setup{
    pinMode(servo1, OUTPUT);
void loop{
    digitalWrite(servo1, HIGH);
    digitalWrite(servo1, LOW);

Expected: I expect the code to run the servo motor at full speed for 5 seconds.

Actual: The motor runs at the first impulse and pauses for 10 seconds.

How can I improve the code to do what I expect?

  • what are your hardware connections and why are you reading an output pin?
    – Vaibhav
    May 31 '19 at 18:07
  • My hardware connections are the three wires from the servo directly to the Arduino. I wanted to see what signals were sent.
    – Ate8
    May 31 '19 at 18:21
  • Why do you think you cannot use the Servo library? With continuous rotation servos it generally works where 0 spins one way 180 spins the other and something close to 90 stops it.
    – Delta_G
    Jul 2 '19 at 20:48
  • Also, to control that servo you don't just set the pin HIGH. You have to send a specific pulse length that tells the servo how fast and what direction to rotate. It is the same sort of signal that tells a regular servo what angle to go to. That's why the Servo library is normally used to control these.
    – Delta_G
    Jul 2 '19 at 20:50

Look at how servo motors are typically controlled. As far as I know there are no servos that can just be "enabled to rotate" like you seem to expect. Usually a servo's position is set by applying a pulse of a specific length. This means you can apply a PWM signal with proper frequency. Then the duty cycle should be proportional to the servos position. From my experience timing is quite critical when controlling a servo, so going the way you do (timing a gpio's output state with delay()s) will not work well. You have to use the atmega's hardware modules (which already is the case when using the arduinos digital write) to achieve adequate timing.


Apply some impulse which you need your servo to work on

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.