// Importar a biblioteca do Arduino -  jssc.jar (dentro da instalação do arduino)
package arduino;

import jssc.SerialPort;
import jssc.SerialPortException;

public class Arduino {

    public static void main(String[] args) throws SerialPortException, InterruptedException {

        String str;

        SerialPort serialPort = new SerialPort("COM4");

        serialPort.openPort();

        serialPort.setParams(SerialPort.BAUDRATE_9600,
                SerialPort.DATABITS_8,
                SerialPort.STOPBITS_1,
                SerialPort.PARITY_NONE);

        Thread.sleep(1000);

        while (true) {

            str = serialPort.readString();

            if (str != null) {

                System.out.println(str);

            }

            Thread.sleep(1000);

        }

    }

}
