imagelogin

Author Topic: plz help me in servo problem  (Read 1409 times)

0 Members and 1 Guest are viewing this topic.

amrhamed

plz help me in servo problem
« on: June 10, 2012, 10:10:06 AM »
Hello Wiring i have written this code of controlling 2 servos motor by  2 pots  wirelessly by 2 arduinos & 2 Xbees & 2 Arduino Wireless shield , but the servos making random moves without any control with the pots , so what's the error in these codes :
Code: [Select]
Pots Code @ the First Arduino :

//Define Pins
int potPin = 0;
int potPin2 = 1;

void setup()
{
  //Create Serial Object (9600 Baud)
  Serial.begin(9600);
}

void loop()
{
  int val = map(analogRead(potPin), 0, 1023, 0, 179);
  int val2 = map(analogRead(potPin2), 0, 1023, 0, 179);
  Serial.println(val);
  Serial.println(val2);
  delay(50);
 
}

__________________________________________________________________

Motor Code @ the sec. Arduino :

#include <Servo.h>

//Define Pins
int servoPin = 9;
int servoPin2 = 10;

//Create Servo Object
Servo Servo1;
Servo Servo2;

void setup()
{
 //Start Serial
 Serial.begin(9600);
 
  //Attaches the Servo to our object
  Servo1.attach(servoPin);
  Servo2.attach(servoPin2);
 
  delay(500);
}

void loop()
{

  while( Serial.available() == 0);
  int data = Serial.read() -'0';

  int pos = map(data, 0, 1023, 0, 179);
  int pos2 = map(data, 0, 1023, 0, 179);
  pos = constrain(pos, 0, 179);
  pos2 = constrain(pos, 0, 179);

  //Turn the servo
  Serial.println(pos);
   Serial.println(pos2);
  Servo1.write(pos);
  Servo2.write(pos2);
  Serial.flush();
 
 
}

sincerely - amr
« Last Edit: June 10, 2012, 10:23:00 AM by amrhamed »

barragan

Re: plz help me in servo problem
« Reply #1 on: June 21, 2012, 12:29:56 PM »
Which software are you using to program your arduino boards? Wiring or Arduino?