element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Arduino Forum Servo Movement At Power Up Before Initialization
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Not Answered
  • Replies 15 replies
  • Subscribers 384 subscribers
  • Views 2508 views
  • Users 0 members are here
  • servo
  • arduino
Related

Servo Movement At Power Up Before Initialization

colporteur
colporteur over 1 year ago

I am experiencing a problem with the servos operations on this project that members helped me develop.

When the Mega is powered on the servo track to a position before going to the initialized position. The power on position for the servo is outside the range of motion for the animation. The movement has over extended some mechanical connections and caused breakage.

I went in search of a solution and found this post. It doesn't solve the problem but the discussion is an example of what I am experiencing. One of the suggestions is to relay control power. Only apply power to the servo after full initialization thereby avoiding the issue.

I'm curious if anyone has experienced a servo movement issue on power up and how they may have solved it.

  • Sign in to reply
  • Cancel

Top Replies

  • shabaz
    shabaz over 1 year ago +3
    Hi Sean, The power on position is really the position with no PWM applied. I can think of four potential solutions. (a) Ideally there would be a mechanical solution (i.e. as Frank mentions, to try…
  • colporteur
    colporteur over 1 year ago in reply to beacon_dave +3
    I successfully adjusted the physical connection on one servo today after determining "horn initialization position" I was fortunate since the horn works from 90 to 0. 90 being the start and the initialization…
  • genebren
    genebren over 1 year ago in reply to colporteur +3
    Hi Sean, I build a series of DMX driven decoders that come in 6 and 12 servo channels. These boards have a switchable power bus that provides up to 10 Amps of servo power. On power up, the servo power…
Parents
  • colporteur
    0 colporteur over 1 year ago

    image

    Equipment

    Servo
         SG92R
         SG90
         MG90S


    Nano (knock off)
         ATmega328P (old bootloader)
         ATmega168P

    Drawing represents a servo with a horn attached. At the lower end of the servo case is were the control cable connection is shown. The servo rotates counter-clockwise along the arch from 0 to 180 degrees (except when noted).

    Servo motors SG92R & SG90 can only be move by hand along the arc. Physical stops in the servo prevent it from being positioned outside the arc. The MG90S servo has no physical stops. It can be moved by hand outside the arc.

    If no default servo position is provided in void_setup (servoA.write(#); the servo horn will move to 90 when powered on. This happens for all three servos. The MG90S servo horn will move to 90 but if the horn is between 181-360 it may move counter-clockwise or clockwise to reach 90. If the horn is >200 the servo will move counter-clockwise. <200 the horn moves clockwise to reach 90.

    The code used for testing is provided.

    #include <Arduino.h>
    #include <Servo.h>
    
    uint8_t ServoA = 3;
    int buttonPin = 2;  // Button to trigger animation
    
    Servo servoA;  //initialize servo
    
    //debounce
    int counter = 0;
    int buttonState = 0;
    int lastButtonState = 0;
    
    int currentButtonState = 0;
    unsigned long lastDebounceTime = 0;
    unsigned long debounceDelay = 50;
    
    void setup() {
      pinMode(buttonPin, INPUT_PULLUP);
      //servoA.attach(ServoA, 544, 2400);
      //servoA.attach(ServoA, 544, 2400);
      //servoA.attach(ServoA, 544, 2400);
      //servoA.write(0);
    }
    
    void loop() {
      currentButtonState = digitalRead(buttonPin);
      if (currentButtonState != lastButtonState) {
        lastDebounceTime = millis();
      }
      if ((millis() - lastDebounceTime) > debounceDelay) {
        if (currentButtonState != buttonState) {
          buttonState = currentButtonState;
          if (buttonState == LOW) {
            servoA.write(0);
            delay(1000);
            servoA.write(180);
            delay(1000);
            servoA.write(0);
          }
        }
      }
      lastButtonState = currentButtonState;
    }
    

    Pushing a button the servo moves from 0 position to 180 and then back to 0 position. The servo is conditioned using the min/max default values servoA.attach(ServoA, 544, 2400); provided in the library. The button push is wrapped in a debounce routine.

    Lesson Learn:

    Set a default position for the servo in void_setup. This simple step will prevent the servo from moving to 90 position, especially if the position is outside the range of movement.

    Start by using servo library default min and max values servoA.attach(ServoA, 544, 2400); I've found that tweaking these values may improve the length of travel of the horn. On the MG90S & SG92R increasing the maximum value to 2450 increased the distance closer to 180. Decreasing the minimum value on the SG90 did not get it closer to 0. Posts on the internet suggests manufacture will provide these values. I had no success finding those specification sheets.

    • Cancel
    • Vote Up +3 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Reply
  • colporteur
    0 colporteur over 1 year ago

    image

    Equipment

    Servo
         SG92R
         SG90
         MG90S


    Nano (knock off)
         ATmega328P (old bootloader)
         ATmega168P

    Drawing represents a servo with a horn attached. At the lower end of the servo case is were the control cable connection is shown. The servo rotates counter-clockwise along the arch from 0 to 180 degrees (except when noted).

    Servo motors SG92R & SG90 can only be move by hand along the arc. Physical stops in the servo prevent it from being positioned outside the arc. The MG90S servo has no physical stops. It can be moved by hand outside the arc.

    If no default servo position is provided in void_setup (servoA.write(#); the servo horn will move to 90 when powered on. This happens for all three servos. The MG90S servo horn will move to 90 but if the horn is between 181-360 it may move counter-clockwise or clockwise to reach 90. If the horn is >200 the servo will move counter-clockwise. <200 the horn moves clockwise to reach 90.

    The code used for testing is provided.

    #include <Arduino.h>
    #include <Servo.h>
    
    uint8_t ServoA = 3;
    int buttonPin = 2;  // Button to trigger animation
    
    Servo servoA;  //initialize servo
    
    //debounce
    int counter = 0;
    int buttonState = 0;
    int lastButtonState = 0;
    
    int currentButtonState = 0;
    unsigned long lastDebounceTime = 0;
    unsigned long debounceDelay = 50;
    
    void setup() {
      pinMode(buttonPin, INPUT_PULLUP);
      //servoA.attach(ServoA, 544, 2400);
      //servoA.attach(ServoA, 544, 2400);
      //servoA.attach(ServoA, 544, 2400);
      //servoA.write(0);
    }
    
    void loop() {
      currentButtonState = digitalRead(buttonPin);
      if (currentButtonState != lastButtonState) {
        lastDebounceTime = millis();
      }
      if ((millis() - lastDebounceTime) > debounceDelay) {
        if (currentButtonState != buttonState) {
          buttonState = currentButtonState;
          if (buttonState == LOW) {
            servoA.write(0);
            delay(1000);
            servoA.write(180);
            delay(1000);
            servoA.write(0);
          }
        }
      }
      lastButtonState = currentButtonState;
    }
    

    Pushing a button the servo moves from 0 position to 180 and then back to 0 position. The servo is conditioned using the min/max default values servoA.attach(ServoA, 544, 2400); provided in the library. The button push is wrapped in a debounce routine.

    Lesson Learn:

    Set a default position for the servo in void_setup. This simple step will prevent the servo from moving to 90 position, especially if the position is outside the range of movement.

    Start by using servo library default min and max values servoA.attach(ServoA, 544, 2400); I've found that tweaking these values may improve the length of travel of the horn. On the MG90S & SG92R increasing the maximum value to 2450 increased the distance closer to 180. Decreasing the minimum value on the SG90 did not get it closer to 0. Posts on the internet suggests manufacture will provide these values. I had no success finding those specification sheets.

    • Cancel
    • Vote Up +3 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Children
No Data
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube