Need Help!

Could you please tell me what this means and how to resolve the problem

at gnu.io.RXTXPort.eventLoop(Native Method)
at gnu.io.RXTXPort$MonitorThread.run(RXTXPort.java:1575)
Error inside Serial.serialEvent()
java.io.IOException: Bad file descriptor in nativeavailable
at gnu.io.RXTXPort.nativeavailable(Native Method)
at gnu.io.RXTXPort$SerialInputStream.available(RXTXPort.java:1532)
at processing.app.Serial.serialEvent(Serial.java:215)
at gnu.io.RXTXPort.sendEvent(RXTXPort.java:732)
at gnu.io.RXTXPort.eventLoop(Native Method)
at gnu.io.RXTXPort$MonitorThread.run(RXTXPort.java:1575)
Error inside Serial.serialEvent()
java.io.IOException: Bad file descriptor in nativeavailable
at gnu.io.RXTXPort.nativeavailable(Native Method)
at gnu.io.RXTXPort$SerialInputStream.available(RXTXPort.java:1532)

Thanks

This means that you really think we are mindreaders...?

Where is the code?
:wink:

Cheers,
Kari

Oops sorry

#include <Servo.h>

int LedPin1 = 12;
int LedPin = 13;
int MotorPin1 = 9;
int MotorPin2 = 10;
int servoPin = 11;

Servo VishalServo;

void setup()
{
digitalWrite(LedPin, HIGH);
Serial.begin(9600);
pinMode(LedPin, OUTPUT);
pinMode(LedPin1, OUTPUT);
pinMode(MotorPin1, OUTPUT);
pinMode(MotorPin2, OUTPUT);
VishalServo.attach(servoPin);
VishalServo.writeMicroseconds(1500);
delay(2000);
}

void loop()
{
while (Serial.available() == 0);
int val = Serial.read() - '0';

int i = VishalServo.read();

if (val == 2)
{
Serial.println("Robot is On");
digitalWrite(MotorPin1, HIGH);
digitalWrite(MotorPin2, HIGH);
delay (1000);
digitalWrite(MotorPin1, LOW);
digitalWrite(MotorPin2, LOW);
}

if (val == 1)
{
Serial.println("Robot is turning left");
digitalWrite(MotorPin2, HIGH);
delay(1000);
digitalWrite(MotorPin2, LOW);
}

if (val == 3)
{
Serial.println("Robot is turning right");
digitalWrite(MotorPin1, HIGH);
delay(1000);
digitalWrite(MotorPin1, LOW);
}

if (val == 7)
{
Serial.println("Turning left");
VishalServo.write(i+30);
}

if (val == 9)
{
Serial.println("Turning right");
VishalServo.write(i-30);
}

if (val == 5)
{
Serial.println("Shoot");
digitalWrite(LedPin1, HIGH);
delay(25);
digitalWrite(LedPin1, LOW);
}

if (val == 8)
{
Serial.println("Centering");
VishalServo.writeMicroseconds(1500);
}

else
{
Serial.println("Invalid!");
}
}

When I open the place where we can communicate with the arduino and type in commands then this error appers and my servo goes all jerky and keeps going left,right rapidly.

vishalapr:
Oops sorry

#include <Servo.h>

int LedPin1 = 12;
int LedPin = 13;
int MotorPin1 = 9;
int MotorPin2 = 10;
int servoPin = 11;

Servo VishalServo;

void setup()
{
digitalWrite(LedPin, HIGH);
Serial.begin(9600);
pinMode(LedPin, OUTPUT);
pinMode(LedPin1, OUTPUT);
pinMode(MotorPin1, OUTPUT);
pinMode(MotorPin2, OUTPUT);
VishalServo.attach(servoPin);
VishalServo.writeMicroseconds(1500);
delay(2000);
}

void loop()
{
while (Serial.available() == 0);
int val = Serial.read() - '0';

int i = VishalServo.read();

if (val == 2)
{
Serial.println("Robot is On");
digitalWrite(MotorPin1, HIGH);
digitalWrite(MotorPin2, HIGH);
delay (1000);
digitalWrite(MotorPin1, LOW);
digitalWrite(MotorPin2, LOW);
}

if (val == 1)
{
Serial.println("Robot is turning left");
digitalWrite(MotorPin2, HIGH);
delay(1000);
digitalWrite(MotorPin2, LOW);
}

if (val == 3)
{
Serial.println("Robot is turning right");
digitalWrite(MotorPin1, HIGH);
delay(1000);
digitalWrite(MotorPin1, LOW);
}

if (val == 7)
{
Serial.println("Turning left");
VishalServo.write(i+30);
}

if (val == 9)
{
Serial.println("Turning right");
VishalServo.write(i-30);
}

if (val == 5)
{
Serial.println("Shoot");
digitalWrite(LedPin1, HIGH);
delay(25);
digitalWrite(LedPin1, LOW);
}

if (val == 8)
{
Serial.println("Centering");
VishalServo.writeMicroseconds(1500);
}

else
{
Serial.println("Invalid!");
}
}

When I open the place where we can communicate with the arduino and type in commands then this error appers and my servo goes all jerky and keeps going left,right rapidly.

I DO NOT KNOW WHY THERE IS A SMILY FACE COMMING IN : if (val = 8)

Maybe if you put your code in a code box using the # icon, you wouldn't get smilies.

Why is a smily face comming when I type 8

Ok but could you please tell me what to do to remove this error

Post your code in a code box, not a quatation.

Why does it always print "Invalid" unless you type "8"?

What do you mean?

I mean that when you type in "5", it prints "Shoot" "Invalid".
Why does it do that?

I dont know could you tell me how to remove it.

Thanks

Read zoomkat's comments about the power supply

You need to power the servo and motor(s) separately.

es I am Im powering the motors via 2 external 9 V batteries(1 battery for 1 motor) and I am powering the servo off the arduino

But it doesn't move with the power supply you've got at the moment, so what's the difference?

Try four AAAs instead.

Ok

and I am powering the servo off the arduino

Will not work

I connected it to 4 external batteries but the servo just doesn't want to work when I connect it to an external power supply.And yes I did connect the arduino ground to the batteries ground.

Please help...

After two pages here, you should show the circuit you are using.

Cheers,
Kari