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 RTC combined with servo device
  • 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 8 replies
  • Subscribers 392 subscribers
  • Views 2229 views
  • Users 0 members are here
  • Design
Related

RTC combined with servo device

Former Member
Former Member over 10 years ago

Hello,

I have a project and part of it involve an RTC clock and a servo. see attachment below.

I already built the circuit but I am completely lost with the sketch.

The objective of the project is :

After every 3 hours the servo automatically rotate 60 degrees.

Hope you could help me in the sketch.

Thanks in advance!

 

image

Attachments:
image
  • Sign in to reply
  • Cancel

Top Replies

  • Robert Peter Oakes
    Robert Peter Oakes over 10 years ago +1
    Can you show us what you have so far Have your already tried getting the servo to work using the standard servo library, same question for the RTC What is the model of the servo, I would normally recommend…
  • Robert Peter Oakes
    Robert Peter Oakes over 10 years ago in reply to Former Member +1
    You can make it change at what ever interval you like and as far as you like within its limits just write the program based on what info I provided and then share your results, and we can help further…
Parents
  • Robert Peter Oakes
    0 Robert Peter Oakes over 10 years ago

    So first things first (btw, you don't say what to do if and when the servo reaches 180deg or 360, do you stop, reset to zero, something else ?

     

    Ignore the RTC initially and simply setup an LONG variable to hold the current system time (mills() )

    every 60 seconds (60,000 mills) move the servo

     

    #define interval 60000

    #define changeAngle 60

    #define maxAngle 180

    #define minAngle 0

     

    long mytimer = 0;

    int myAngle = 0;

     

    setup()

    {

    ...

    mytimer = mills();

    }

    loop()

    {

    ...

    if (mills() - myvariable > interval)

         {

         myAngle += changeAngle

         if (myAngle >= maxAngle)  myAngle = minAngle; // protect servo and sanity image

         myservo.write(myAngle);

         mytimer = mills();                // setup timer for next loop

         }

    // now do other stuff

    }

     

    This is not tested , I simply put it from head to page as I thought of it so you may need to do some work on it but it shows you the basics of how to get what you want, now its up to you

    once you have this running, it will be a simple matter of changing the mills() to use the RTC and changing the values of the interval

     

    ... in setup and loop simply is where your other code may go, it is of course not valid in the real code

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 10 years ago in reply to Robert Peter Oakes

    in fact yes, since a servo can rotate only 180 degrees after 180 degress i wanted it to return to zero.


    ok yes so do you think every 1 minutes it can change 60 degrees?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Robert Peter Oakes
    0 Robert Peter Oakes over 10 years ago in reply to Former Member

    You can make it change at what ever interval you like and as far as you like within its limits

     

    just write the program based on what info I provided and then share your results, and we can help further

     

    Peter

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Reply
  • Robert Peter Oakes
    0 Robert Peter Oakes over 10 years ago in reply to Former Member

    You can make it change at what ever interval you like and as far as you like within its limits

     

    just write the program based on what info I provided and then share your results, and we can help further

     

    Peter

    • Cancel
    • Vote Up +1 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