View unanswered posts | View active topics It is currently Sun Jul 21, 2019 10:47 am

 Page 1 of 1 [ 3 posts ]
 Print view Previous topic | Next topic
servo help
Author Message
Rookie

Joined: Fri May 01, 2015 3:26 pm
Posts: 1
servo help
Hi

I was wondering if anyone can help me. I am looking for code that will allow me to operate two servos.

I would like to have it operated by a reed switch.

Basic it would go like this.

reed switch activated, servo 1 would turn 90 degrees & stop, then after the first servo has finished, servo 2 would then turn 90 degrees & stop. When the reed switch is activated again. Servo 2 would rotate back 90 degrees & stop, then servo 1 would rotate back 90 degrees & stop. I would also need the servos to rotate at say 150ms per position

any help welcomed

ps I have an UNO

Fri May 01, 2015 3:29 pm

Joined: Thu May 24, 2012 12:15 pm
Posts: 722
Re: servo help
 steammad wrote:reed switch activated, servo 1 would turn 90 degrees & stop, then after the first servo has finished, servo 2 would then turn 90 degrees & stop. When the reed switch is activated again. Servo 2 would rotate back 90 degrees & stop, then servo 1 would rotate back 90 degrees & stop. I would also need the servos to rotate at say 150ms per position

You actually have most of what you need right here: all you need to do is put it in a psuedocode format, then fill in the psuedocode with actual code.

 Code:bool hasTurned90 = 0;   while(1==1)   {      if(reed switch is activated AND hasTurned90 is 0)      {         turn servo1 90 degrees         wait1Msec(amount of time to complete movement);         turn servo2 90 degrees         wait1Msec(amount of time to complete movement);         hasTurned90 = 1;      }      else if(reed switch is activated AND hasTurned90 is 0)      {         turn servo1 90 degrees (back)         wait1Msec(amount of time to complete movement);         turn servo2 90 degrees (back)         wait1Msec(amount of time to complete movement);         hasTurned90 = 1;      }   }

This is one way to do this code, and you may need to tweak it to fit what you want to do. There is a variable known as a state counter to see if the servos have turned already, and each if/else if statement checks to see if the variable is at a zero value (the servos are currently at a 0 degree position) or 1 (servos are at a 90 degree position).

Each servo will be turned to the correct position, with a wait1MSec command giving each time to reach their target value(s). You will need to determine the amount of time you want to give each servo to ensure that it reaches the target value before the next servo starts moving.

_________________
Check out our Blog! And our Facebook page!
Need help? Take a look at our updated help documentation and the ROBOTC Forums.

Mon May 11, 2015 2:21 pm
Rookie

Joined: Wed Nov 18, 2015 10:34 pm
Posts: 13
Location: Pakistan
Re: servo help
you should read this one out http://www.theengineeringprojects.com/2 ... oteus.html

_________________
You should also check The Engineering Projects because they have posted a lot of Arduino Projects and PIC Mirocontroller Projects and have also designed many new Proteus Tutorials and Engineering Projects. I hope you guys are gonna like them.

Wed Nov 18, 2015 10:39 pm
Display posts from previous:  Sort by
 Page 1 of 1 [ 3 posts ]

#### Who is online

Users browsing this forum: No registered users and 1 guest

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum

Search for:
 Jump to:  Select a forum ------------------ ROBOTC Applications    ROBOTC for LEGO MINDSTORMS       Third-party sensors    ROBOTC for CORTEX & PIC    ROBOTC for VEX IQ    ROBOTC for Arduino    Robot Virtual Worlds    Multi-Robot Communications    Issues and Bugs Competitions & Partners    Mini Urban Challenge    CS2N Robot Virtual Worlds Competitions       VEX Skyrise Competition 2014-2015       VEX Toss Up 2013-2014       FTC Block Party! 2013-2014    Competitions using VEX - BEST, TSA, VEX, and RoboFest!    FTC Programming    RoboCup Junior and Other ROBOT Competitions Virtual Brick Robotics Discussions    General Discussions    Project Discussions Off-Topic ROBOTC Forum & ROBOTC.net Suggestions/Feedback    ROBOTC Forums Suggestions/Comments    ROBOTC.net Suggestions/Comments       NXT Programming: Tips for Beginning with ROBOTC       VEX Programming: Tips for Beginning with ROBOTC    2013 Robotics Summer Of Learning       VEX Toss Up Programming Challenge       FTC Ring It Up! Programming Challenge    International Forums       Spanish Forums          ROBOTC for MINDSTORMS          ROBOTC for VEX       French Forums          ROBOTC pour Mindstorms          ROBOTC pour IFI VEX       Japanese Forums （日本語のフォーラム）       German Forums    2015 Spring Carnival Event    PLTW (Project Lead The Way)    Robotics Merit Badge    2014 Robotics Academy Summer of Learning