Introduction: Computer Controlled Arduino

About: I just love making stuff...and working out!

Have you ever wanted to control the Arduino with a program on your computer that can handle a full GUI? I'm sure most will say yes, but a full GUI takes hard work. You need to know the basics of it all before you can do the whole thing. A really good program that you can make a GUI with is Processing. You can get this at

https://processing.org

The Arduino IDE is based off of the one from Processing. On the site you can look at the reference guide and tutorials to help you get used to processing if you need it. Processing allows us to make programs on the computer that can get input from the mouse and keyboard and through a serial port give that information to the Arduino. Let's

get started!

(I've entered this in the Coded Creations contest so please vote for me)

Step 1: Stuff Required

Required:

1. Arduino Uno (I used a Rev3)

2. Breadboard

3. 2 LEDs of two different colors

4. Jumper wires

5. 2 220Ohm Resistors

6.USB programming cable for Arduino Uno

7. Processing

8. Arduino IDE

9. A brain

Optional:

1. Time

2. Blood, Sweat, and Orange Juice

Step 2: Make the Circuit

The circuit in the image is the circuit you will need.

It is a fairly simple circuit and it won't take too long to make it.

You just need to hook up the 2 LEDs to the Arduino through Digital I/O pins with 220Ohm resistors to ground.

Hook the ground from the Arduino to the ground line on your breadboard and you've finished the circuit.

Step 3: Make the Processing Program

First, you start with the Processing program. It is a basic program that takes input from the computer and gives you visual feedback along with writing to a serial port.

The program I wrote was...

/**
Arduino LED Control By: RobotsWillRule 5/2/2015

Based off of representative colors for the LEDs. Processing control by keyboard. AS for LEDs. R for reset. **/

import processing.serial.*;

Serial port;

void setup(){

//Sets the size

size(300, 300);

//Sets the neutral background color

background(0);

frameRate(10);

port = new Serial(this, 9600); }

void draw(){

//This reads to see if a key is pressed

if(keyPressed){

//These If Statements check to see if a certain key is pressed

if(key == 'a' || key == 'A'){

//These backgrounds are the representative colors of the LEDs

background(50, 20, 200);

port.write('B'); // This writes to the serial port for the Arduino

}

if(key == 's' || key == 'S'){

background(0, 100, 0);

port.write('G'); }

//This is for the reset of the screen and LEDs on Arduino

if(key == 'r' || key == 'R'){

background(0,0,0);

port.write('w'); } } }

All this program does is take input of A, S, or R on the computer then gives visual feedback on the computer in the form of background colors. After that it writes to a serial port through the Serial library so the Arduino can read it. A list of open COM ports are printed in the black box at the bottom of the IDE

Step 4: Make the Arduino Code

The code for the Arduino is for the LEDs and reading the serial port for commands. When it gets a command it lights up the correspondent LED. The following code is what I used, but I'm sure you and everyone else here can modify it in all sorts of ways. In fact I hope that everyone who reads this tries to modify every aspect of it. That is how you're supposed to learn right?

char ledRef;
int bLed = 11;

int gLed = 9;

void setup() {

pinMode(bLed, OUTPUT);

pinMode(gLed, OUTPUT);

Serial.begin(9600); }

void loop() {

if(Serial.available()) {

ledRef = Serial.read();}

if(ledRef == 'B'){

digitalWrite(bLed, HIGH);}

if(ledRef == 'G'){

digitalWrite(gLed, HIGH);}

else{

digitalWrite(bLed, LOW);

digitalWrite(gLed, LOW); }}

This Arduino code checks for commands over the serial port. If the right command is given for a certain LED it will light up. The code doesn't do anything special for codes without any meaning.

Step 5: Time for Testing

Now is the time to test if it will actually work together.

First, you need to upload the code to the Arduino.

If you don't do that the code won't upload right because the COM port would be active from the Processing sketch.

Then, you start the Processing application you made.

A small black screen will pop up.

Press the A key and it will turn blue.

If you did everything right the blue LED will light up.

Next, if you press the S key the green LED will light up along with the window turning green.

For both the LEDs to turn back off press the R key.

If all this works you made it right!

Step 6: Troubleshooting

1. Check your circuit. Although its low voltage unplug the Arduino and check to make sure the LEDs are in the right way and if the wires are in right.

2. Check your code. Coding problems are always there in some way or form. It is just the matter of finding them that makes it hard.

3. If you can't find the problem feel free to ask questions. I'm sure there is someone (like me) that won't mind helping.

Step 7: Thank You

This is my first Instructable, but I plan on making many more. Please give suggestions for this and/or other projects.(But please none that will break the bank!)

Coded Creations

Participated in the
Coded Creations