Friday, July 13, 2012

EL Wire Beat Detector with Processing on an Arduino

So the hardware here is an Arduino Duemilanove with an EL Escudo sequencer and 3 lengths of 3m ELWire. I'm controlling the Arduino with a Processing sketch because I wanted to use the Sonia audio library to process audio input on the laptop and send pinOut commands to the sequencer. I read a little more on that and it looks like the Minim audio library may be a better choice with more options for isolating pitch frequencies I think. You can see it starts responding to MJ's voice and other sounds. Ultimately I plan to have some students work on programming EL Wire sequences for a student dance performance where the EL Wire will be woven into some costumes. I have to figure out if I can integrate an XBee into the works to send the commands to multiple units over wifi so the costumes can be centrally controlled.
Here's the code:

import processing.serial.*;
import cc.arduino.*;
import pitaru.sonia_v2_9.*;
Arduino arduino;
int[] ledPin = {2,3,4}; // EL Escudo pinOuts start at A=2, B=3, etc.
float beat;

void setup() {
  arduino = new Arduino(this, Arduino.list()[1], 57600);
  for(int i = 0;i<3;i++) {
    arduino.pinMode(ledPin[i], Arduino.OUTPUT);
  // change beat value or input volume if beat isn't accurate, or maybe your sample does not have a clear enough beat
  beat = 0.03; 
  // Start listening to the microphone

void draw() {
  float level = LiveInput.getLevel();
  if(level > beat) {

void blink() {
  for(int i = 0;i<ledPin.length;i++) {
    arduino.digitalWrite(ledPin[i], Arduino.HIGH);
  for(int i = 0;i<ledPin.length;i++) {
    arduino.digitalWrite(ledPin[i], Arduino.LOW);

// Close the sound engine
public void stop() {

1 comment :

Erik N. said...

I tried the Minim library which even has a beatDetect class and just couldn't get it to do any better than the Sonia library. Oh well, the main thing I'm looking for is an application that can return a tempo in milliseconds, which the Sonia does pretty well.