A virtual puppet project.

Making 3D models can be a fun way to learn computer programming and can even form a basis for creating simple animations. Here we use an Arduino and the Processing language to make a very simple 3D virtual puppet to demonstrate just how simple it can be. We will use Processing to create and manipulate the puppet. We will then use the Arduino as a means of interfacing some sensors to control our puppet, including a switch, some variable resistors, and a small solar panel (for example salvaged from an old calculator or other solared powered gadget that's surplus to your needs).

The program looks like Figure 1 when it starts, with a simple 3D humanoid figure forming our puppet. With the Arduino attached we can then manipulate the puppet as shown in Figure 2, such as by changing its position and speed of rotation using the variable resistors. One of those variable resistors we can also use to make the figure explode or implode, and we can use the switch to make the puppet jump into the air. The solar panel we can use to change the light brightness shining onto our puppet, but if you don't have one you could use a variable resistor instead just as easily.

The virtual puppet as seen when the processing program is run.

Figure 1. The puppet initial screen.

The processing program screen while under control by the Arduino.

Figure 2. The puppet under Arduino control.

The first thing that's needed is to have the Arduino and Processing environments installed, using the links above. All of the instructions on how to use those software products are available at the links, and hopefully shouldn't be too difficult to follow. Then, the code we'll be using can be downloaded using the following links:

Click here to download the Arduino code.

Click here to download the Processing code.

The Arduino code can just be uploaded to the microcontroller board using the Arduino programming environment. It just reads the voltage level on each of the first eight analog input pins, and continually writes those values out through its USB port, for Processing to interpret. To control the puppet you'll need to install some sensors on your Arduino, either using the connectors on a normal Arduino board, or using a breadboard, as illustrated in Figure 3 which uses an Arduino Nano.

The sensors and Arduino installed on a solderless breadboard.

Figure 3. The Arduino breadboard project with sensors attached.

Whichever board, or method, you choose, the sensors are all easily interfaced to the Arduino, as shown in Figure 4. The LED is used by the Arduino to flash a signal every time it writes out its sensor values, but if you don't want one you can just leave it out of your circuit without causing any problems. The processing code uses the voltage levels it reads on its analog pins to decide what changes you want to make to the puppet, so if you have other favourite analog sensors (such as a hunidity sensor, or even a digital thermometer chip) you can easily use those too. You may notice that we're connecting a switch to an analog input here, when a digital input would normally be used, but that's just to make life simpler. In this project we're just using the analog inputs.

Attaching sensors to the arduino analog input pins.

Figure 4. Connecting sensors to the Arduino analog input pins.

With the Arduino connected to a USB port on your computer you can now run the Processing program. However, unless you're very lucky your sensors won't yet work because you need to change the code to use the virtual serial port you are using. To do that, take a look at the output pane at the bottom of your Processing code window, and find the port number in the list printed there (you may need to scroll up to find it). Then, change the the following line in the setup function to the correct port number:

myPort=new Serial(this, Serial.list()[set_port_number_here], 115200);

Having done that you should now be able to control the puppet. The Processing code is currently set to map analog inputs to the following puppet variables, but you can change these to your hearts content to add new effects and behaviour.

Arduino analog pin:

Processing variable:

A0

Left to right puppet position (x-axis).

A1

Forward to backward puppet position (y-axis).

A2

Rotation speed and direction.

A3

Explode and implode magnitude.

A4

Switch to make puppet jump.

A5

Solar panel to control lighting level.