Problem Arduino and Processing

I have the arduino and ultrasonic HC-SR04. I want to help please us. The arduino want to measure the distance and what gives the serial. Communicates with the processing and when the distance is greater than 150cm displays an image, if less playing video. My problem is that I run the processing but the video plays either away or close. Please help me. I beginner!!

Arduino is from a library NewPing

    // ---------------------------------------------------------------------------
    // Example NewPing library sketch that does a ping about 20 times per second.
    // ---------------------------------------------------------------------------
    #include <NewPing.h>
    #define TRIGGER_PIN  12  // Arduino pin tied to trigger pin on the ultrasonic sensor.
    #define ECHO_PIN     11  // Arduino pin tied to echo pin on the ultrasonic sensor.
    #define MAX_DISTANCE 400 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.
    NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
    void setup() {
      Serial.begin(115200); // Open serial monitor at 115200 baud to see ping results.
    void loop() {
      delay(50);                      // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings.
      unsigned int uS =; // Send ping, get ping time in microseconds (uS).
      Serial.print("Ping: ");
      Serial.print(uS / US_ROUNDTRIP_CM); // Convert ping time to distance and print result (0 = outside set distance range, no ping echo)


    // Video
    Movie movie;
    // Image
    PImage img;  // Declare variable "a" of type PImage
    // Serial
    import processing.serial.*;
    Serial myPort;  // Create object from Serial class
    int val;      // Data received from the serial port
    void setup() {
      size(640, 360);
      String portName = Serial.list()[1];
      myPort = new Serial(this, portName, 115200);
      // Load and play the video in a loop
      movie = new Movie(this, "");
      img = loadImage("moonwalk.jpg");  // Load the image into the program
    void movieEvent(Movie m) {;
    void draw() {
      if (movie.available() == true) {; 
      image(movie, 0, 0, width, height);
      if ( myPort.available() > 0) {  // If data is available,
        val =;         // read it and store it in val
      if (val>130) {
        image(img, 0, 0);
      } else {
        image(movie, 0, 0, width, height);

Put a print in the Processing sketch right after the serial read to see what is incoming. You are reading one byte. You are sending “Ping: xxx cm” where xxx is the range.