Arduino and Processing

I am trying to connect Arduino with Processing. In principle I want is something simple: send datas with Arduino and read with Processing. These are the programs:

Arduino:

int ldrPin = 3;
int valor = 0;

void setup() {

  Serial.begin(9600);

}

void loop() {

  valor = analogRead(ldrPin);
  Serial.println(valor);  
  delay(75);
}

Processing:

import processing.serial.*;
String portname = "/dev/ttyUSB0";  // Puerto de mi máquina
Serial port;  // Objeto port de la clase Serial
int valorUSB;

void setup() {
  // Abre el puerto al que está Arduino
  port = new Serial(this, portname, 9600);
}
void draw() {
  
  if (port.available() > 0) {  // Si el dato está disponible,
       valorUSB = port.read();      // lee y almacena el valor del puerto
  }
  println(valorUSB);
}

The Arduino program works well, however the Processing continually shows me the value 0. What am I doing wrong?

if (port.available() > 0) {

You need to change the 0 to your COM Port number setup in Arduino, however its a bit confusing. Go to Arduino -> Tools -> Serial Port -> and see which port is clicked off and count what number port it is in the list. For example, my Arduino connects to COM 7 and my port list starts at COM 3 so COM 7 is the 5th (last one) that appears on the list. Subtract 1 from this number since Processing counts 0 as a port and you have your port number, mine is port 4 on processing and the 5th option on Arduino (COM7) so I will enter

if (port.available() > 4) {

I'm going to have to disagree with jayjay. Serial.available() just returns how many bytes are waiting in the serial buffer. Choosing the correct COM port is in the

String portname = "/dev/ttyUSB0";  // Puerto de mi máquina
Serial port;  // Objeto port de la clase Serial

AND

port = new Serial(this, portname, 9600);

sections. Now, I cant tell you which part exactly since I don't use linux, but I can assume that jayjay is correct that you have the wrong port but he is wrong in how he tries to fix it. I don't know if linux supports the Serial.list()[n] command, where n is the COM port, but if it does that is the easiest way to fix incorrect COM port selection. Windows has this in the setup section with only "Serial myPort" declared before that as a global

  String portName = Serial.list()[0];
  myPort = new Serial(this, portName, 9600);