How to blink LED in Java ?

Hello, I'm a french student who just buy an Arduino 2560 Rev3 MEGA , and I have to make some LED blinking by using a Java Interface.

I saw a lot of topic which described how to use rxtx librarie but I didn't success to turn on a LED .

I try to use myrobotlab, but that's the same.

Someone could help me ? How to configure rxtx ? or to use myrobotlab ?

Thanks !

Look at the Serial examples for how to use the Serial port. You would then just have to write the Java app that would open up a Serial connection to the Arduino and send commands.

Yes I already tried , but the example is for reading data , but I want to send data over the arduino. I don't really understand when I write output.write(...) , what parameter ? what mean "byte" ? and how to SELECT a pin to turn on ?

Yes I already tried , but the example is for reading data ,

What example? What have you tried? Need to show some effort that you've made and we can correct any mistakes or misunderstandings.

One easy way to get going is to install the Bitlash interpreter on the Arduino ( Then you can send commands from your Java program like:


to turn on an LED on pin 4, and


to turn it off.


I tried the example : Arduino Playground - HomePage

But it is to read input.

So I decided to make a loop like in Arduino IDE :

public void loop () throws IOException, InterruptedException{
           byte val =-1;
           Byte b1 = new Byte(val);
            while( true )
        output.write(b1);        // Turn LED on.
        Thread.sleep(1000);              // Wait one second
        output.write(0);        // Turn LED off.
        System.out.println("Passage en boucle");

But when i make myArduino.loop() nothing append.

I dont know how to select a Pin , or how to Turn on that...

Well instead of trying to build everything at once, you should be starting small.

First start by defining your requirements; what commands should be sent to the Arduino? What should the Arduino do with those commands? Next, view some of the examples in the Arduino to see how to receive serial data; there are plenty of them. Get the Arduino part working to the point where you can type in commands to the serial monitor that will cause the Arduino to do what you want. From there, you then design the Java interface to replicate sending those commands.