The Maven Box: an Arduino Controller for Software Developers




Introduction: The Maven Box: an Arduino Controller for Software Developers

Every job has it's routine. I am a software developer who works with a Git/Maven based workspace everyday. So when I start working, my daily routine is to update and build my local workspace, pulling changes from GitHub, execute a maven build and execute the updated software. Usually I get my first coffee after that, but because I love coffee so much I thought there must be a faster way to get my system updated and running.

That's why I build the "Maven Box". It basically...

  • selects a branch from several GitHub projects
  • stashes changes before pulling
  • pulls the changes
  • triggers a maven build
  • shows the status of 6x test systems
  • has 3x customizeable function keys

What skills do you need? For whom was this instructable written?

For the Arduino stuff, only basic skills are required, especially if you only want to use buttons, switch buttons and LEDs. Components like the 74HC595 shift registers are a bit more complex, but with the help of the related documentation easy to handle. This instructable aims for Java developers who would like gain some experience with the Arduino. It does not explain in detail how to build this exact controller box but should give tips how to handle the major obstacles and where to find additional help.


I want to thank user travershenry who presented an awesome Arduino based game controller here at ( It gave me a great inspiration when I build my controller and when writing this instructable.

Step 1: Gather Components

For the controller box you can use any switch, push button or LED available. I've build my box with the following components:

  • 1x Arduino Uno R3
  • USB Type B cable
  • 220 Ohm resistors
  • 10k Ohm resistors
  • some wires
  • 10x LED (3mm)
  • 4x push buttons
  • 3x switches
  • 1x rotary encoder
  • 1x 74HC595 (8 bit shift register)

The second list may differ depending on the components you want to use. I'm gonna show you within the next steps how to wire each component and how to write the corresponding code for it (or where to find it).

Step 2: Layout and Build Your Controller Case

Putting LEDs, switches and buttons into a box is not a big issue. Of course you want the box to look fancy. So I simply designed the background of the panel via Photoshop. I glued the paper on the top using regular paper glue and sealed it using "paper foil(?)" (a transparent gluey film you can use to wrap up book covers).

I drilled the holes for the buttons afterwards. Unfortunately I don't have a real workbench so not every hole was drilled precisely :-(

Finally, I copied the idea from user "travershenry" using carbon-fibre type decal for all sides (see link on top of this instructable).

Step 3: Wire Components

There are already enough tutorials out there for wiring LEDs, buttons and switches with an Arduino. So I skip the basic details here and provide links with the tutorials I've used instead:

Wiring LEDs

Arduino tutorial:

Wiring Switches

Arduino tutorial:

Button Debouncing

Arduino tutorial:

Rotary Encoders

I've used the following encoder for my box:

I've used pin 2 and 3 for the encoder pins to use Arduino interrupts to read the single. The code for this is shown in the next step.

74HC595 8-bit Shift Register

Running out of digital pins? These shift registers allows you to control a big amount of LEDs with only 3 digital pins.

You can find a detailed tutorial about this component, including source code and wiring schemes here:

Step 4: Implement the Arduino Sketch

With the help of the tutorials mentioned in the previous step, you should be able to write most of the Arduino sketch. I have attached here my full sketch that can be used as blueprint.

For the rotary encoder implementation, you will find different examples how to listen on the encoder changes.

I'm using the given implementation that works for the rotary encoder mentioned in the previous step:

//do not change these pins!
const int encoderPin1 = 3;
const int encoderPin2 = 2;
volatile int lastEncoded = 0;
int encoderValue = 0;

void setup(){
  digitalWrite(encoderPin1, HIGH); //turn pullup resistor on
  digitalWrite(encoderPin2, HIGH); //turn pullup resistor on
  //call updateEncoder() when any high/low changed seen
  attachInterrupt(digitalPinToInterrupt(encoderPin1), updateEncoder, CHANGE); 
  attachInterrupt(digitalPinToInterrupt(encoderPin2), updateEncoder, CHANGE);

 * The rotary encoder implementation
void updateEncoder() {
  int MSB = digitalRead(encoderPin1); //MSB = most significant bit
  int LSB = digitalRead(encoderPin2); //LSB = least significant bit
  int encoded = (MSB << 1) |LSB; //converting the 2 pin value to single number
  int sum  = (lastEncoded << 2) | encoded; 

  if(sum == 2) {
    encoderValue --;
    String value = String(encoderValue);
    String cmd = "{source:'ROTARY_ENCODER', event:'ROTATE_LEFT'}";

  if(sum == 1) {
    encoderValue ++;
    String value = String(encoderValue);
    String cmd = "{source:'ROTARY_ENCODER', event:'ROTATE_RIGHT'}";
  lastEncoded = encoded; //store this value for next time  

The next section explains how the bi-directional communication is established with a Java program running on the computer the Arduino is connected with.

Step 5: Bi-Directional Communication Between Arduino and Java

The basic idea of the whole project was to have a Java daemon running on my windows machine that will

  • receive messages from the Arduino
  • display these messages via pop-up windows
  • send information to the Arduino with monitoring information
  • update the status of some LEDs to visualize this information

Let's have a look on the communication directions and how they can be implemented:

Sending messages from the Arduino to Java

As you've seen in the previous step the Arduino sends strings in JSON format to the serial port:

String cmd = "{source:'ROTARY_ENCODER', event:'ROTATE_RIGHT'}";

The serial communication of the Arduino is setup in the init method of the sketch. You can use any machine readable format you prefer. I've used JSON since the conversion to a Pojo is pretty easy using GSON.

Receive messages from the Arduino

I've started the project using the rxtx library for Java ( I was able to send and receive messages from/to the Arduino, but I wasn't able to listen on messages from the Arduino in a non-blocking way. As a result my program was running with bigger CPU usage than necessary, so I switched to jSerialComm ( - a platform-independent serial port access for Java which supports event-based reading and writing via callbacks.

Establishing the connection with jSerialComm:

SerialPort serialPort = SerialPort.getCommPort(port);

The port is the COM port the Arduino is connected on. If you don't know which port it is, open the windows device manager - it will show you what port is used (see screenshot).

Listen on messages from the Arduino:

serialPort.addDataListener(new SerialPortDataListener() {

  public int getListeningEvents() {

  public void serialEvent(SerialPortEvent event) {
    if(event.getEventType() != SerialPort.LISTENING_EVENT_DATA_AVAILABLE) {
    byte[] newData = new byte[serialPort.bytesAvailable()];
    serialPort.readBytes(newData, newData.length);

    String arduinoMessage = new String(newData);


Parsing the JSON message from the serial events is actually a little bit more difficult. Have a look at the sources at GitHub ( The class implements the communication with the Arduino and the JSON parsing and object creation via GSON.

Sending messages from Java to the Arduino

My control panel has 6x LEDs which are indicating the availability of test-systems. The Java program checks the availability via HTTP requests and updates the status of the LEDs depending on the return code of the HTTP request.

The status string with this monitoring information is written to the serial output stream of the Arduino connection:

if(serialPort.isOpen()) {
  output = new BufferedOutputStream(serialPort.getOutputStream());
  String monitoringResult = "monitoring:0:true|";

In this example the monitoringResult string "monitoring:0:true|" indicates that the first pipeline that is monitored is available. The suffix "|" indicates the end of the command that is written to the Arduino. Now the Arduino has to parse this string:

Receiving messages from Java

The following method is called inside the loop method of the Arduino sketch:

void listenForUpdates() {
  String command = "";
  if(Serial.available() > 0) {
    command = Serial.readStringUntil('|');    
  if(command.length() > 0) {
    String commandToken = tokenize(command, ':', 0);
    if(commandToken == CMD_MONITORING) {
      int index = tokenize(command, ':', 1).toInt();
      String statusToken = tokenize(command, ':', 2);
      boolean enabled = statusToken == "true";

      registerState[index-1] = enabled;
      Serial.println("{'message':'" + command + "'}");

The reading of the serial messages is based on the method Serial.readStringUntil('|'). The pipe symbol indicates the end of a command so that the command itself can be analyzed and evaluated. In this example the parsing of the monitoring command is shown that will update the array registerState with the current status of the pipline at the position index.

Step 6: Designing the User Interface

Once the communication between the Arduino and the Java program is established successfully, you may want to use the buttons on your control panel to visualize information on the computer's screen. For my control panel, I have three different situations where I want to show a notification or control UI:

  • Show the status of all test pipelines when the "pipeline" button is pressed.
  • Show a notification for n seconds when one of the switch button was switched.
  • Show a project control slider when the rotary encoder of the push button is pressed.

I've attached some screenshots with comments that visualize how the UI is working. I've implemented the UI with JavaFX, feel free to use Swing, AWT or SWT instead (if you even need a UI).

The sources are hosted at GitHub:

Step 7: Autostart the Java Program in the Background

There are a lot of different solutions out there to run a Java program as a windows service. I've googled some, tried some, failed and finally used winrun4j ( The setup was done in a few minutes and I was totally satisfied with putting a windows link into the autostart folder instead of configuring a real service.

According to the Apache Commons Daemon projects ( seems the way to go, but I wasn't able to properly setup my project for this.

Step 8: Conclusion

What I loved about the project was the variety of work: to design and photoshop the controller layout, drill and tape the case, think about the required buttons and switches and to program the Arduino and Java frontend + backend.

And of course, here is the list of issues I would do different the next time:

  • Take more care about the size of the case: I had to re-solder most of the wires since I wasn't able to put the wired plate back into the case. The jumper wires I've put into the Arduino were simply too high.
  • Drilling holes: I already mentioned that I could have drilled the holes more precisely - my number one pain point.
  • The lamination problem: Maybe I should have drilled the holes after I've glued the controller background and before I've laminated it. This would have avoided the nasty laminate rips.

I hope you enjoyed reading this instructable and found some inspirations for you next Arduino project.

Be the First to Share


    • For the Home Contest

      For the Home Contest
    • Big and Small Contest

      Big and Small Contest
    • Make It Bridge

      Make It Bridge



    6 years ago

    The code looks like it'll only count a transition from 00 states to 01 or 10 states. Other transitions will be ignored. Effectively it'll only count 1/4 of the transitions. Is this the intent?


    Reply 6 years ago

    I didn't look deeper into it - actually I don't know how rotary encoders are working :-|. I just copied the code somewhere and was happy that it works with the given rotary encoder in a way that one rotation "click" matches on increase/decrease of the given counter.


    6 years ago

    I don't really understand all of the dev lingo stuff (I'll get there one
    day), but I do appreciate the color scheme of this thing. Do you own
    any orange amps? It looks a lot like my Tiny Terror!


    Reply 6 years ago

    The orange is complete random, but yes, the layout is inspired by an Orange guitar amp.


    6 years ago

    Cool box! Looks like an Orange Guitar amp


    Reply 6 years ago

    Yes! It's inspired by an Orange Guitar amp. The color combination is my favorite.


    6 years ago

    Where do I get that knob?!??!


    6 years ago

    Awesome! Great work!


    Reply 6 years ago



    6 years ago

    You missed the "turn on the coffee machine" button :)

    Great work


    Reply 6 years ago

    Haha, even more important: the coffee machine status LED!