A simple way to control multiple servos, for inexperienced people to get animatronics etc going. Full source code is below edns.co.nz/rob... Updated code with full sequence control and homing control See version 3
This is awesome! Thanks for posting it! I have been wanting to make a 3 axis Halloween Skull and now I am one step closer. Now I need to build the platform and movements. I hope to tweak your code to get the head to move loft to right, and and down and hopefully tilt. Thanks again for sharing it I greatly appreciate it.
Thank you thank you thank you! Froma complete novice you've helped me gain knowledge. I have some questions. I'm making an xwing and want the wings to open up and r2d2's head to swivel. I used your servo version one code and I want to add more positions. Thanks to you my servo is moving 10° and back to close but I want it to hold in the 10°position for a few seconds before it closes again, also i want it so start off slow ,speed up and slow before it gets to 10° everything i try to add more steps the the animation it doesn't work and I'm not sure why
Thank you for this awesome tutorial! May I ask some beginner question here? Does it damage the servos if they hold the position for a longer time? Why I'm asking: I am about to program a robot owl, and it should ideally hold a particular position after a movement is done. If I simply detach the servos, gravity would do its job. (Your cat is so cute!!)
Servo's are well known to burn out if left "holding" something. The best thing to do with your owl is to counterbalance it if you can. This way it will hold position with no power.
@@Robonza thank you for your reply! Counterbalancing will be a problem, but I can program it to end each movement in a stable position (and then detach). I didn't know it was an issue with servos.
@@katalinkristof6383 Some high quality servos might deal with it. I guess like a lot of things its a gamble on how long it will last. Detached servos will last the longest
HI. I want to program 4 to 6 servos to do stuff individually. I have a servo driver pca9685. Im trying to make something with these motors and a couple of lights and sound. I do not want batteries. I want to be able to plug this thing in the wall with only one cord not 2. Looks like though I need 2 seperate power supplies. I cant find anything online. Something I buy? A hack? Thanks
Very well explained. Although could you explain the circuit wiring. I can assume how the servos are attached to PWM pins, but I notice a capacitor there. What is it for and how exactly is it wired, and is it essential or is it just like a protection thing
The capacitor is there to avoid servo noise getting into the micro power supply and glitching it. It is standard practice. Just about all circuits need power supply capacitors. I have noticed a lot of builders miss this.
I really appreciate the tutorial. I now have 4 servos wired up but I want to make it to where when i click the button then the code is executed and then returned to home position before executing the rotation. Can you help me?
Would this code work with an Arduino uno? I'm trying to move a robotic arm with 6 servos with an arduino uno, I have an external power supply that provides 7.5 V but I keep getting these weird glitches where only 2 of the 6 servos move. I believe it's because my code has them moving at the same time, however this code allows them to move simultaneously right?
I’m having the same issue trying to run 3 servos from a battery. I’m trying to run the servos and the nano all off 4xAA batteries. I suspect I’m maxing out the current draw of the battery and that is causing issues. What’s more weird is when I hit the reset button 2 of the 3 servo move but it’s rarely the same 2. Like it seems random. One time they all moved but then one of them started spasming and twitching a bit. I’m gonna try swapping for a bigger capacitor, and if not putting more batteries in parallel to try to increase the max current output
@@Robonza thank you for getting back to me so quickly. I think I have all the files: robonza_servo.ver3.ino, servo0.cpp, servo1.cpp, servo2.cpp, servo.h
Did you open the INO file using Arduino? TICK_TIME' is clearly in servo..h so that means the h file is not visible to your sketch. Its not an issue with my code.
been searching the internet for days and still havnt found an answer. I want to make several servos move with if statements. like, if a servo position is at 70, i want another servo to go to 30....if that makes sense....anyone have any answers?
its impossible to run thing simultaneously. What it does do is make things tidy and easy to maintain. One rule I try to follow is make my main loop under one page when possible as it makes it easy to read and fix in 5 years time when you forgot how it works.
@@Robonza Then how can you control the servos simultaneoulsy without constantly skipping back and foward between them? I watched the video multiple times and downloaded the code to read it but i'm still kinda lost...
Let me preface this by saying I am not a coder. I an a one time user at the copy and paste level of knowledge. I found this script for moving model railroad turnout servos. But it is only for one turnout. I have 6 on my layout. Would you be so kind as to give me the code to have this work for 6 turnouts and for each turnout, instead of only having 2 position indicator LEDs, I would like to have 2 other LEDS that would be used for a signal light. They would change with when the position LEDs change. Thank you for the time, help and patience. Gary G #include // original nscaler control of 1 turnout. // constant variables used to set servo angles, in degrees const int straight = 90; const int divergent = 110; // constant variables holding the ids of the pins we are using const int divergent_led = 6; const int straight_led = 7; const int buttonpin = 8; const int servopin = 9; // servo movement step delay, in milliseconds const int step_delay = 70; // create a servo object Servo myservo; // global variables to store servo position int pos = straight; // current int old_pos = pos; // previous void setup() { // set the mode for the digital pins in use pinMode(buttonpin, INPUT); pinMode(straight_led, OUTPUT); pinMode(divergent_led, OUTPUT); // setup the servo myservo.attach(servopin); // attach to the servo on pin 9 myservo.write(pos); // set the initial servo position // set initial led states digitalWrite(straight_led, HIGH); digitalWrite(divergent_led, LOW); } void loop() { // start each iteration of the loop by reading the button // if the button is pressed (reads HIGH), move the servo int button_state = digitalRead(buttonpin); if(button_state == HIGH){ // turn off the lit led if(pos == straight){ digitalWrite(straight_led, LOW); } else { digitalWrite(divergent_led, LOW); } old_pos = pos; // save the current position // Toggle the position to the opposite value pos = pos == straight ? divergent: straight; // Move the servo to its new position if(old_pos < pos){ // if the new angle is higher // increment the servo position from oldpos to pos for(int i = old_pos + 1; i = pos; i--){ myservo.write(i); // write the next position to the servo delay(step_delay); // wait } } // turn on the appropriate LED. if(pos == straight){ digitalWrite(straight_led, HIGH); } else { digitalWrite(divergent_led, HIGH); } } }// end of loop