Controlling Arduino with Processing GUI

Hi, I am working on a project for school that involves making a spring powered launcher that has to fire a projectile a set distance by adjusting the angle and amount of tension in the spring. I would like to make it so that I can enter a distance into a processing program on the computer, and have it automatically calculate the required angle and tension for the spring (using a pre-made equation). I would like it to then send this data to the Arduino via USB and have it move the motors to the correct location. Finally, I would like to have a button (either real or virtual) that will fire the projectile by activating a solenoid. I already know how to interface stepper motors and solenoids to the Arduino, but I need some help with how to approach the computer side of the project.

Any help would be greatly appreciated.


Interesting project. Every office should have one.

The way I would approach this problem is to get the Arduino side working and debugged before you start on the GUI.

You're going to be using the usb serial port to control it from Processing, so why not design the data transfer format to be human-readable commands so you can control it from the Serial Monitor… then when it's working, processing can send those same commands from the GUI to the Arduino.

There are simpler approaches, but suppose you could send these commands to the Arduino via the Serial Monitor or a Processing program:


There is plenty of information here on the forum how to parse serial input and call your C code to work the motor and solenoid.

Good luck with your project,


Edit: grammatical correction.

Thanks for the help, I understand what you are suggesting, and I think it will work quite well, but I am having trouble figuring out how to get the Arduino to read the commands from the serial port in the format that you suggested.

I know that I will have to read the data into some kind of variable, then determine what the data is and what needs to be done, but I am not sure what code to use to do this. In the past, I have done very basic serial control where I used code like this:

void loop() {

// see if there's incoming serial data: if (Serial.available() > 0) {

incomingByte =; // read the oldest byte in the serial buffer

//Preform the code to activate the stepper motor and the LEDs

if (incomingByte == '0') {

myStepper.step(14); // moves the stepper 14 steps forward

delay(50); // wait 50ms

myStepper.step(-14); // moves the stepper 14 steps backward

Also, what would be a simple way to convert an angle into a set number of steps?

Thanks again for all of the help.

I know that I will have to read the data into some kind of variable

Actually, an array. You'll need an index variable, too. Don't forget the NULL terminator.

strtok(), atoi(), and/or atof() would bear looking at, once you have a NULL terminated array of chars.

Also, what would be a simple way to convert an angle into a set number of steps?

There isn't. What does an angle of 47 degrees mean, in terms of steps, anyway? If you want the stepper to rotate 47 degrees, that's one thing. How to do that depends on the number of steps per rotation of your stepper, which is not defined in your snippet.