I am new to arduino and I want to interface it using java . I want to know is there a way to change the variable or set the variable using the input from java :D Thanks For reading Hope you can answer my question .. Sorry for my english not my first language :D

  • 2
    Devise and implement your own custom protocol through the (USB-tunneled) serial connection: the Java side would tell the Arduino “set this variable to this value” and the Arduino would do it. – Edgar Bonet Oct 27 '16 at 13:54

Although you can't straight-up change variables on the Arduino, you can create your own protocol over a serial connection using processing (https://processing.org) on your computer, and a sketch on Arduino.

Use the function


on the arduino to initialise a serial connection to your computer, and then in processing use the lines:

Serial myPort;    // Initialise a serial object (do this at the start of the program)

// Inside the setup() function:
String portName = Serial.list()[0];    // Get the first portname on the list (this may need to be changed to get the right one)
myPort = new Serial(this, portName, 9600);

to connect from the computer.

Once you have done this, you can use the functions


in processing, and

val = Serial.read();

To recieve data on the arduino.

Source (see here for more info): https://learn.sparkfun.com/tutorials/connecting-arduino-to-processing/all

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.