Controlling two servos with two potentiometers simultaneously

Hi,

I want to try controlling two servos with two potentiometers simultaneously.
There is a Fritzing Starter Kit and a project for servo but only with one potentiometer and one servo:
http://fritzing.org/projects/analog-input-to-servo/

I edited that code and the result can be seen in my attachment.

When uploaded to Arduino UNO (smd) the program doesn't works althought everything is connected properly.

So where is the problem in the code?

Any advices will be appreciated!

Regards, from Pál

SantaKrisztianRobotkar.ino (1.56 KB)

Think you need to slow it down a little, so a longer delay. Furthermore add some debug statements what values are read.

It can also be a matter of power, if you unhook one servo does the other start working?

// Ketto szervo helyzetet vezerli potenciometerrel (valtoztathato ellenallas) 
// 2012, Copyright Santa Krisztian

#include <Servo.h> 

Servo szervo1;  // szervo1 objektum letrehozasa az egyik szervo vezerlesehez 
Servo szervo2;  // szervo2 objektum letrehozasa a masik szervo vezerlesehez

int potpin1 = 2;  // analog lab csatlakozik az egyik potenciometerhez
int potpin2 = 5;  // analog lab csatlakozik a masik potenciometerhez

int val1;    // valtozo, amely olvassa az egyik analog lab erteket
int val2;    // valtozo, amely olvassa a masik analog lab erteket

void setup() 
{ 
  Serial.begin(115200);
  szervo1.attach(9);  // az egyik szervot csatolja a 9-es labon a szervo1 objektumhoz
  szervo2.attach(11);  // az egyik szervot csatolja a 3-as labon a szervo2 objektumhoz
} 

void loop() 
{ 
  val1 = analogRead(potpin1);            
  val1 = map(val1, 0, 1023, 0, 179);     
  szervo1.write(val1);         
  Serial.print("Val1 = ");
  Serial.println(Val1);
                                
  
  val2 = analogRead(potpin2);            
  val2 = map(val2, 0, 1023, 0, 179);     
  szervo2.write(val2);   
  Serial.print("Val2 = ");
  Serial.println(Val2);               
  delay(200);                          
}

) the program doesn't works

I don't know why you didn't post your code, and I don't want to download to my phone, but how are you powering this?

What does "doesn't work" mean to you?

Edit: easy - val1 and val2 have not been defined.

robtillaart:
Think you need to slow it down a little, so a longer delay. Furthermore add some debug statements what values are read.

It can also be a matter of power, if you unhook one servo does the other start working?

// Ketto szervo helyzetet vezerli potenciometerrel (valtoztathato ellenallas) 

// 2012, Copyright Santa Krisztian

#include <Servo.h>

Servo szervo1;  // szervo1 objektum letrehozasa az egyik szervo vezerlesehez
Servo szervo2;  // szervo2 objektum letrehozasa a masik szervo vezerlesehez

int potpin1 = 2;  // analog lab csatlakozik az egyik potenciometerhez
int potpin2 = 5;  // analog lab csatlakozik a masik potenciometerhez

int val1;    // valtozo, amely olvassa az egyik analog lab erteket
int val2;    // valtozo, amely olvassa a masik analog lab erteket

void setup()
{
 Serial.begin(115200);
 szervo1.attach(9);  // az egyik szervot csatolja a 9-es labon a szervo1 objektumhoz
 szervo2.attach(11);  // az egyik szervot csatolja a 3-as labon a szervo2 objektumhoz
}

void loop()
{
 val1 = analogRead(potpin1);            
 val1 = map(val1, 0, 1023, 0, 179);    
 szervo1.write(val1);        
 Serial.print("Val1 = ");
 Serial.println(val1);
                               
 
 val2 = analogRead(potpin2);            
 val2 = map(val2, 0, 1023, 0, 179);    
 szervo2.write(val2);  
 Serial.print("Val2 = ");
 Serial.println(val2);              
 delay(200);                          
}

Indeed, the 'delay(200)' did it to works, although with slow motion.

So I have now a "robot arm" with two servos that I can control with two potentiometers.

Before I uploaded this code abowe, I tried advices and yes, if I unhooked one servo the other started working.

The problem is solved (thank you very much!!), however, how can I read the added debug statements what values are read is?

Regards, from Pál