Xbee Servo control

I’m using this code for servo end of connection and all it does is draws minimal current and the servo gets HOT.

The transmit code is working just fine through the serial port. The xbees are working to I have tested many of times.

Only after uploading this code into the Arduino Uno it make Servo get hot and does not respond to xbree communications. What can I do to correct this?

Code:
#include <Servo.h>

Servo myservo; // Create servo object to control a servo

char readstr[4]; // Character Array to store the serial input
int cstrpos = 0; // Variable to store the current input array position
long val = 0; // variable to store the value from the input

int maxValue = 175;

void setup()
{
Serial.begin(9600); // Startup the Serial Interface
myservo.attach(9); // Attaches the servo on pin 9 to the servo object
}

void loop()
{
char ch; //A Place to Store the character we just read

if (Serial.available()) // is there anything to be read from serial port?
{
ch = Serial.read(); // read a single character

// print out to serial port the character we received (similar to an echo)
Serial.print(ch);

if (ch >= ‘0’ && ch <= ‘9’) // Number so store it in the input array
{
readstr[cstrpos] = ch; // Add the read character to the array of read numbers
++cstrpos; // Increase the position in the array
}
else // not a number so lets set the position of the servo
{
readstr[cstrpos] = ‘\0’; // Add a null to the end of the string array to terminate the string
val = atol(readstr); // Convert the string to a long int

if (val > maxValue) {
val = 175;
}

cstrpos = 0; // Reset the array position back to the beginning so the next input starts a new input

//Print to the serial port what we are going to do
Serial.print(“Servo set to: “);
Serial.println(val);
Serial.println(””);
}
}

// The servo needs constant feed of values so we constantly output the PWM value
myservo.write(val); // Set the PWM value to send to the servo
delay(15); // Just a little delay

} [/color]

Your use of code tags didnt seem to work.

Use the button with <> on it

#include <Servo.h>
 
Servo myservo;          // Create servo object to control a servo
 
char readstr[4];        // Character Array to store the serial input
int cstrpos = 0;        // Variable to store the current input array position
long val = 0;           // variable to store the value from the input
 
int maxValue = 175;
 
void setup()
{
  Serial.begin(9600);   // Startup the Serial Interface
  myservo.attach(9);    // Attaches the servo on pin 9 to the servo object
}
 
void loop()
{
  char ch;              //A Place to Store the character we just read
 
  if (Serial.available())      // is there anything to be read from serial port?
  {
    ch = Serial.read();        // read a single character
   
    // print out to serial port the character we received (similar to an echo)
    Serial.print(ch);
   
    if (ch >= '0' && ch <= '9')    // Number so store it in the input array
    {
      readstr[cstrpos] = ch;      // Add the read character to the array of read numbers
      ++cstrpos;                  // Increase the position in the array
    }
    else                          // not a number so lets set the position of the servo
    {
     readstr[cstrpos] = '\0';     // Add a null to the end of the string array to terminate the string
     val = atol(readstr);         // Convert the string to a long int
 
     if (val > maxValue) {
       val = 175;
     }
     
     cstrpos = 0;                 // Reset the array position back to the beginning so the next input starts a new input
     
     //Print to the serial port what we are going to do
     Serial.print("Servo set to: ");
     Serial.println(val);
     Serial.println("");
    }
  }
 
  // The servo needs constant feed of values so we constantly output the PWM value
  myservo.write(val);            // Set the PWM value to send to the servo
  delay(15);                     // Just a little delay
   
}

PS. As the Servo is getting hot, I suspect you have not wired it up correctly or its not compatible with the Servo library

Use a much simpler sketch to test the movement of the servo from end to end, then once that is working, go back to your Xbee code

Servos get hot when using an external power supply and the external power supply and arduino grounds are not connected together.