Dr. Black & Mr. White: A Journey in Art

A friend of mine creates wire sculptures an I thought to myself: ‘Using one of these as a capacitive sensor and hook it up to a solenoid to make it move shouldn’t be hard.’ Boy, have I been wrong. This page details the design of the resulting sculpture and how I got there.

The build started fairly innocent, but keep in mind that my understanding of electronics is fairly basic. I can hook up a shield to an Ardu, and can place a bunch of switches and potentiometers on a PCB but if you ask me to build a basic amplifier, I’m stumped.

Laying out stuff with Fritzing on an old netbook is a bitch

The early stage

The first Iteration was an Ardu, a wire, a 50 MΩ Resistor, a coil with a neodymium magnet and a diode (realizing that I would induce considerable currents I researched flyback diodes), a transitor and an external power supply. The battery on the left is a symbol for it. I then hooked up a multimeter in series with the coil and cranked up the voltage of the power supply until I reached the rated current of the coil wire. Actually I cranked it up to somewhere near twice the rated current, rationalizing with the idea that I intended to drive the coil with a square wave resulting in a 50% load cycle.

Driving the solenoid with PWM predictably resulted in annoying buzzing and I failed to figure out a suitable low pass filter that wasn’t either sluggish or ate most of the control voltage. So I decided to try my hand at a R-2R DAC. I had plenty of I/O pins left on the Ardu and it would look very electronic. While rifling through my parts bin for an opamp that would become the DAC’s buffer stage (I was not ready to sacrifice any control voltage), I stumbled upon some SPI controlled 8 bit DACs that I had bought for an earlier project that never took off. Hooray!

The resulting solenoid driver took the DAC’s output directly to the collector of the large transistor. On which I promtly burned my right index finger because the constant analogue voltage faced a much lower impedance from the coil and things got cozy pretty fast. Also the control voltage response was unsatisfactory, the 8 bit range of the DAC resulted in some three or four discernible voltage levels at the coil. Some learning was in order and luckily the folks at the local hackerspace were there to help. In the end I was using my DAC bufferd by an opamp fed from the external power supply and set up as voltage follower connected to a voltage divider behind the transistor.

With food stains!

The original design document on the back of a Conrad receipt is lost. Instead I present to you the network plan I used to transfer the circuit from breadboard to a proto shield

It worked! Hoorray for opamps! I got usable sensor output from a length of plastic coated iron wire at ranges around 50 to 80 cm which I tracked via the serial output and a python script and began to work on the reaction code. The activation period of the solenoid would increase with perceived activity. The applied voltage would follow the period. This resulted in high frequency/ low amplitude shivering in the resting state that would change to low frequency/ high amplitude shaking when triggered. I also designed four distinct ways to react to being touched, of which one was chosen randomly, when a threshold was tripped.

  1. High frequency/ medium amplitude vibration signalling stress
  2. Kind of random violent shaking, as if the sculpture was trying to get rid of you
  3. Zero movement for playing dead
  4. And pleasant vibration that was modulated, inspired by purring

The sensor input was smoothed by a running average of the last 32 readings:

class Smoothe_32
  long rawData[32];
  long previous;
  byte index, counter;
  const byte mask = B00011111;

    previous = 0;
    index = 0;
  void append(long value){
    index = counter & mask;
    rawData[index] = value;

  long fetch(){
    long to_return = 0;
    for(byte i = 0; i < 32; i++){
      to_return += rawData[i];
    to_return = to_return >> 5; //This is dividing by 32
    return to_return;

Which is actually the only piece of code that would survive the following ordeal.

The Thursday before the festival came around and I felt well prepared. My hardware was working and the software was ready to be adapted to the conditions in place. Of course we ran late. This was in part caused by mail ordered parts not arriving and some difficulties in organising such an event that had to be expected. While Melanie was working on the wire, I modified the solenoid to work in a pulling direction instead of the originally planned pusher layout. Also the sculpture now consisted of several lengths of wire from different materials, so I soldered inconspicuous pieces of hook up wire between the individual parts. Around eight in the evening I was ready to take a first look at the sensor readings. Which were consistently showing that the measurements ran into timeouts.


The device after the exhibition. Note that the breadboard does nothing, it held the resistors for capsensing

The first way to address that was to change the resistance between the send and receive pins. This didn’t yield usable results. The next step was to only use parts of the wire, so I unsoldered the connections I had made earlier and tried different parts in combination with varying the resistance. This didn’t work either. Finally I remembered a library that had been featured on Hackaday that uses static electricity and some special properties of the Atmega’s ADC to sense motion with a single wire antenna. After downloading it I ran the test example and found it working. Even better: It kept working after I resoldered the connections between all the wires of the sculpture. At one in the morning I decided to hit the bed and do the rest of the coding the next day.

Friday: The exhibition would open at twelve and we arrived around ten, giving us plenty of time. The touch behavior was dropped from the concept, because the new library wouldn’t detect touch. So it was just a question of mapping the sensor output to suitable ranges of frequency and amplitude. I was reading sensor data and Melanie was providing movement to calibrate everything. At one, just one hour after opening the exhibition, we were happy with the results and went out for lunch, dropping off my laptop and a nap in preparation for the evening.

Much orange

Detail of the solenoid. The thread stops the plunger from slipping out and is held in place by liberal amounts of zip ties and superglue.

When we returned, we found Dr. Black & Mr. White in a state of constant agitation. Fellow artists reported, that he has been doing that for quite some time. So I went back, got my Laptop and started debugging. In the end I came up with two possible explanations: Either the sensors were reacting to the movement of the air that set in after the heating had been turned on or it was stuck in a feedback loop, sensing its own movement. Both problems could be addressed with autocalibration that adjusts the sensitivity to a long time average. I implemented that and cleaned up the code in the process. My self made timers were replaced with the much neater ones from the SimpleTimer library and I even added comments to document which parameter did what. Fine tuning would have to wait till the next day, when there actually would be movement to calibrate against. At eleven I called it a day.

Saturday: We arrived, I uploaded the new firmware and started to adjust the operating parameters. The sensor output looked great and the autocalibration successfully prevented feedback loops. But nothing was moving. I suspected that the long time running on full tilt had fried the electronics. Uploading the test firmware for the DAC showed that everything was fine, just a bit sluggish, indicating mechanical problems. After a short trip to the hardware store, the wax paper bearing in the solenoid was replaced by graphite powder and everything looked good. Except that there still was no movement with the installation firmware running.

At this point I realized that my Laptop wasn’t charging. A quick test with the multimeter revealed that the AC adaptor was fine. So I copied all the required files to the SD card of my camera (the thumb drive in my toolbox had a borked file system that refused to be reformatted) and took the laptop home to check if it had just a damaged connector and would work in its docking station. Since it didn’t I dug out my old 10″ netbook, managed to remember its root password after only a dozen tries and got to download the Arduino IDE (twice, the ancient version that lived in my distro’s repository didn’t come with the SPI library that the DAC requires, so I went for the most recent at arduino.cc), pip and all required python libraries for my debug plotter.

Back at the festival I discovered two things: The absence of movement was an error that I had introduced the day before when restructuring the code. Something that I cut and never pasted, because it had actually been in the right place before. This resulted in the amplitude never being increased above zero. Secondly: Recent versions of the Arduino software include a very usable serial data plotter in the ‘Tools’ menu. I fixed the program, tweaked some parameters and in the afternoon of the festival’s day two Dr. Black & Mr. White finally were ready to interact with curious strangers. It was lovely.