Arduino rc robot freezes when unplugged from pc

Hi!
I am building a radio controlled digger. Everything works just fine, but only when plugged to PC. Code works like this

Read recieved message from transmitter
Check the third letter
Is third letter an 'F'?

YES
Run motors
NO
Turn motors off

Well, everything is okay, until we unplug the Arduino. In this case it works like this

Start
Wait for the message
Message is 'F', run the motors
Run the motors
Run the motors
Run the motors
And it's stuck, won't read any other messages I am sending

I am using Arduino Uno with Motor Shield (Shield powered with 4xAA batteries and Arduino with 9V battery via barrel connector) and 433 MHz XY-MK reciever

This is my code:

#include <VirtualWire.h>
#include <AFMotor.h>
AF_DCMotor motor1(3);
AF_DCMotor motor2(4);
char c;
void setup()
{
     motor1.setSpeed(140);
     motor1.run(RELEASE);
     motor2.setSpeed(140);
     motor2.run(RELEASE);
     vw_set_rx_pin(2);
     vw_set_ptt_inverted(true);
     vw_setup(2000);
     vw_rx_start();
}

void loop()
{
    uint8_t buf[VW_MAX_MESSAGE_LEN];
    uint8_t buflen = VW_MAX_MESSAGE_LEN;
    if (vw_get_message(buf, &buflen))
    {
      int i;
      String data;
    for (i = 0; i < buflen; i++)
    {
         data +=char(buf[i]);
    }
   c = data[2];
   switch(c){
   case 'F':motor1.run(FORWARD);
            motor2.run(FORWARD);
            break;
   case 'L':motor1.run(FORWARD);
            motor2.run(BACKWARD);
            break;
   case 'R':motor1.run(BACKWARD);
            motor2.run(FORWARD);
            break;
   case 'B':motor1.run(BACKWARD);
            motor2.run(BACKWARD);
            break;
   default: motor1.run(RELEASE);
            motor2.run(RELEASE);
            break;
   }
}             
}

Someone knows what is the problem? It's slowly driving me mad

Up!
I really need to know what the answer is, please, give me some suggestions and help

EDIT: The same error occurs when the only power I use comes from USB cable

For informed help, please read the "How to use this forum" post and follow the directions.

Appropriate forum section - checked
Correct language - checked (i'm not speaking fluent english yet but I am trying to write everything correctly)
Do some research before posting - I've spended 2 days for research before writing this post, checked
Make a meaningful subject line - checked
Code tags - checked
Post in proper sentences - checked
Detailed description - checked
Expectations and reality - checked
Bumps - well, that's my fault but normally people here are getting answers in half an hour, not 3 days

jremington, I am trying to, but I really can't see your point. Can you tell me what do you think is wrong with my post?

You forgot to post a wiring diagram and links to or detailed specifications of the motors and motor shield -- the most likely source of the problem.

Now I see it, my bad!

Shield: adafruit l293d motor shield: Overview | Adafruit Motor Shield | Adafruit Learning System
Motors: I couldn't find the exact specification of motors used, but they are taken from this chassis 2WD Smart Robot Car Chassis Kits Arduino 2 motor 1:48 Speed encoder Battery Box | eBay

I will post the wiring diagram later in this post

Problem is now solved. All I had to do was replace 4xAA batteries with another 9V battery. The problem was lack of power for the motors

Thank you all for help

Problem is now solved. All I had to do was replace 4xAA batteries with another 9V battery.

You'd have done better to replace the 4xAA with 6xAA, if by "9V battery" you mean a PP3 smoke alarm battery.

Yes, I am using PP3 batteries. I know that their lifespan is equal to the lifespan of a fly, but I have no room (or battery basket) for 6 AA batteries in my project. I think good solution would be nimh or another rechargeable accumulators but this would provide further research and some money investment, so, maybe later but for now I will stick with casual PP3s

Try six AAAs

The battery life comes from (in part) the available amperage in those batteries, @AWOL is very very right when he says that AAAs would be better. Also the motors in other situations may stall out easier by pulling too much current as they get near stalling AKA browning it out atleast in part. A final note is that it'll help your "project piggy bank" if you switch them due to a longer battery life, and AAAs are much cheaper and in ready supply in comparison to those clunky PP3s