Pages: [1] 2   Go Down
Author Topic: arduino+many servos+potentiometers  (Read 2136 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hello everybody...i am newbie here so i want your help for a project...sorry that my english is not so good...i want to make a robot arm where servos are controlled by potentiometers....exactly when i wire up 2 or more servos it doesnt work any of the servos...i used the classic servo knob exaple but when i wire up even the second servo doesnt move anything!! i will use 6 servos where the 2 of them i want the 2 servos to be manipulated by the same potentiometer and the rest of them to be manipulated by each potentiometers!!can you please help me cause i looked for but i did not find something usefull.....thanx ...
Logged

New Jersey
Offline Offline
Faraday Member
**
Karma: 65
Posts: 3638
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It sounds like you are trying to power the servos from the Arduino. The Arduino can't provide enough current to drive multiple servers, or even one depending on the servo's power requirement. You will need a separate power supply for the servos. Don't forget to connect the grounds together.
Logged

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 72
Posts: 7171
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Post your code so we can look at them for mistakes.
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

#include <Servo.h>
 
Servo myservo1;  // create servo object to control a servo
Servo myservo2;  // create servo object to control a servo
 
int potpin1 = 0;  // analog pin used to connect the potentiometer
int potpin2 = 2;  // analog pin used to connect the potentiometer
int val1;    // variable to read the value from the analog pin
int val2;    // variable to read the value from the analog pin
 
void setup() {
  myservo1.attach(9);  // attaches the servo on digital pin 9 to the servo object
  myservo2.attach(10);  // attaches the servo on digital pin 10 to the servo object
}
 
void loop()
{
  val1 = analogRead(potpin1);            // reads the value of the potentiometer (value between 0 and 1023)
  val1 = map(val1, 0, 1023, 0, 179);     // scale it to use it with the servo (value between 0 and 180)
  myservo1.write(val1);                  // sets the servo position according to the scaled value
 
  val2 = analogRead(potpin2);            // reads the value of the potentiometer (value between 0 and 1023)
  val2 = map(val2, 0, 1023, 0, 179);     // scale it to use it with the servo (value between 0 and 180)
  myservo2.write(val2);                  // sets the servo position according to the scaled value
 
 
  delay(15);                           // waits for the servo to get there
}


Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

now works perfectly!!! but i ll need to use 6 servos!! i think that i ll need new library..but i cant find it..can you help me??? and how has to  be the code after the entry of that library??
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 597
Posts: 33319
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
delay(15);                           // waits for the servo to get there
They are quick servos if they get to position that fast.

Quote
but i ll need to use 6 servos!
I have used that library for 8 servos.
Logged

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 72
Posts: 7171
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

now works perfectly!!! but i ll need to use 6 servos!! i think that i ll need new library..but i cant find it..can you help me??? and how has to  be the code after the entry of that library??


Good for you but it doesn't help anyone reading this thread if you didn't say what you did to make it work. Do everyone a favor an share what you changed. You'll be thanked.
Logged


Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 290
Posts: 25725
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
but i ll need to use 6 servos!!
Unless you really like typing and debugging, now is the time to learn about arrays and for loops.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 597
Posts: 33319
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Unless you really like typing
Problem nowadays is that copy and paste is so easy it reduces the incentive to learn how to program properly with loops.
When you had to punch your own cards, flip switches to toggle in a program, or even type it all into a keyboard, that was the incentive to make the code have as few lines as possible.
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 290
Posts: 25725
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Problem nowadays is that copy and paste is so easy it reduces the incentive to learn how to program properly with loops.
Until you forget, in the fourteenth iteration, to change the name of the variable, and spend the rest of the night wondering about the growing pile of hair in front of you   smiley-twist
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 72
Posts: 7171
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

This is how they learn programming nowadays, starting from copy paste and patch. If the OP has motive to learn more about programming, he will learn more about programming in more elegant ways most people learn from classes. If I didn't know programming and you told me to use arrays for stuff, I'd ask why? I was using discrete variables just fine. This is not a class where he has to demonstrate some skills with arrays to pass smiley
Logged


Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 290
Posts: 25725
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I'd ask why?
So that s/he doesn't come back here in three days time with a simple typo bug.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 72
Posts: 7171
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I'd ask why?
So that s/he doesn't come back here in three days time with a simple typo bug.

Assuming I still don't know programming, I'd have a hard time going from what works right now to what should work but needs code rewrite. I'd be unwilling to change but just keep doing what I know works to get more servos to move. It's a force of habit. Every day I step in my lecture hall, I can predict with utmost accuracy where each of my students is going to sit. I have no hope to change study habits of them but hope to change their interests in the topics I teach.
Logged


Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 597
Posts: 33319
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

But that is why you have to try. I had a hard time trying to persuade my students to use HEX, I said it would make things a lot easier. Some would not put in the small amount of work and kept on doing it the long way converting bit patterns back and forth. In other words they replaced ability with effort.

You can go a long way applying more and more effort but eventually it all falls in a heap. Unfortunately with an ever increasing percentage of students being taken on that happens more and more and so devalues the qualifications. We get it every year, it suites governments to reward effort and not ability because those are the sort of people who are easily manipulated. It has happened to the primary and secondary school population of teachers with the National Curriculum in the UK.
Logged

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 72
Posts: 7171
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Most kids don't like schools and aren't motivated to lift a finger to explore anything. They don't go to school because they want to learn or they meet difficulty and want answers. They are schooling but not learning. I think OP is motivated to learn, which is why the post. So let him see the ugly mess of not using arrays and he'll be very willing to listen, just my $0.02.
Logged


Pages: [1] 2   Go Up
Jump to: