about
This webpage shows you two different setups to use a micro controller, like Arduino or Teensy, to analyse sound and use this as an impulse for audio reactive motor control.
Music and sound inspire many people, including me and my creative work. For one of my artistic works I wanted to extend the experience of a piano concert by moving objects in the concert hall reactively to the music being played. I wanted to read the music depending on the volume level and frequency and send it via a microcontroller to a motor controller. Since I couldn’t find a tutorial that fits my needs, I designed my own setup, which I would like to share with you on this website.
This page shows you two different setups to read out sound and how to send this information as impulses to motors, such as steppers or servos. The basic idea of each setup looks like the schematic you see here.
The aim of this page is that everyone who is interested can implement such a project without much previous knowledge needed. For this I simply use common open source coding software and components from the DIY community, such as Arduino and Teensy.
It would be great to see these basic setups being used to create further artistic projects as teaching objects in museums, exhibits in artistic spaces or inspiring kinetic objects at parties or concerts. Feel free to send me a link to your audio reactive projects via e-mail.
tutorials
Two different tutorials are explained below. The first tutorial describes the structure of Setup A, which is inexpensive and easy to implement. In the second tutorial Setup B is explained in detail, which is more complex in structure, but ultra quiet and very powerful.
setup A
- 7 predefined frequency bands
- up to 16 servos can be moved
- ~100 € for the basic components
setup B
- up to 512 freely adjustable frequency bands
- 10+ stepper motors can be moved
- ~250 € for the basic components
setup A > components > schematic > code
SETUP A uses an arduino and a sparkfun spectrum shield to split the audio into seven frequency bands and move seven seperate mini servos. As an alternative indication of the audio analysis seven LEDs are used. The components for this setup will cost you ~100 € and is simply built.
setup A > components > schematic > code
So lets start with the simple SETUP A,
At first let us have a look on the components you will need.
Arduino Uno Rev 3
This component is the heart of the setup. It will read out the information from the Spectrum Shield and send it to the Servo Shield. A smaller Arduino could do the work as well.
costs ~20€
Sparkfun Spectrum Shield DEV-13116
The Spektrum Shield will analyze the sound and prepare these signals for further processing by the Arduino Uno.
costs: ~35€
Stackable Header Kit
These headers will connect the Arduino to the Spectrum Shield.
costs: ~3€
Adafruit PCA9685 16-Channel Servo Driver
With the driver, up to 16 servos can be controlled simultaneously by the Arduino. Up to 62 boards can be connected in a row, so that finally up to 992 servos can be controlled. For SETUP A we need only one driver board and 7 servo motors.
costs: ~10€
Breadboard for Arduino
The breadboard has a uniform grid on which the components and power supply are connected with wires.
costs: ~3€
7x LEDs
LEDs are wired to the Arduino for easy optical control during correct analysis of audio frequency bands.
costs: ~1€
7x 220 Ohm Resistor
The resistors make sure that the LEDs get just enough electrical current that they glow and don’t break.
costs: ~0,25€
Dupont Jumper Cable
There are different versions of these cables, which differ in their ends. There are male-male, female-female or male-female ends. It is best to have enough of all variants in stock. Furthermore it is advisable to leave the colour of the cable the same for each signal.
costs: ~3€
7x FS90R 360° Continuous Rotation Micro RC Servo
This servo can rotate several times on its own axis.
7x SG90 180° Rotation Micro RC Servo
This servo type can rotate 90° in both directions. This gives it a rotation angle of approximately 180°.
Both servo types are useful for different applications. The question is always, what exactly do I want to drive or move? If the exact idea is not yet clear, it makes sense to have both types for experimentation.
costs per pack: ~ 20€
Power Supply 6V
The servos run on as low as 5V, but better use 6V to make them rotate faster. The Ampere doesn’t really matter, as long as it’s higher than 500mA.
costs: ~8€
DC Power Adapter
Our system needs power supply.
costs: ~3€
USB Cable type B
To connect your computer to the Arduino.
costs: ~5€
setup A > components > schematic > code
And now let us have a look at the schematic setup, to set up an audio reactive motor control.
At first place the spectrum shield on the arduino by using the stackable header kit.
The audio signal must be pluged into the Audio in with a small audio-jack. If you want to listen to the audio, you can plug some earphones or another audio cable into the Audio out port.
For the LED’s i used the pins 3,6,7,9,10,11,12 on the Arduino/Spectrum combination. You can change these pin decleration in the code.
setup A > components > schematic > code
Here is the code for Setup A.
Copy all code of the three tabs (decleraton, void setup, void loop) into your arduino software.
Depending on the servos you use, copy the right code for continous rotation servos or 180° servos.
/******************************************************************************
Sketch by Alex Rex
based on:
SparkFun Spectrum Shield PWM Demo
Toni Klopfenstein @ SparkFun Electronics
February 2015
https://github.com/sparkfun/Spectrum_Shield
*********************************************************************************/
#include
#include
//Declare Spectrum Shield pin connections
/////////////////////////////////////////
#define STROBE 4 // #define constantName value
#define RESET 5 // #define constantName value
#define DC_One A0 // Analog Pin A0 with the name DC_one
#define DC_Two A1 // Analog Pin A1 with the name DC_Two
//Define spectrum variables
int freq_amp; // variable for the 7 Frequency-Bands of the MSGEQ7
int Frequencies_One[7]; // one channel of the stereo input
int Frequencies_Two[7]; // the other channel of the stereo input
int i;
//Define LED connections on the shield
//////////////////////////////////////
int LED[] = {3, 6, 7, 9, 10, 11, 12}; // pins on Arduino/Spectrum Shield for the seven LED's
int pulse1 = 340; // counterclockwise
int pulse2 = 0; // 290 = clockwise
int level = 210; // minimum level of sound to trigger LED or STEPPER
// ~110 for soft piano songs, 175 - 340 for pop-songs or songs with a beat
int levelbass = 170; // I gave the bass a different level to trigger its servo
int band_1 = 0; // 7 frequency bands, choose: 0,1,2,3,4,5,6
//0 = ~63Hz , 1 = ~160Hz , 2 = ~400Hz , 3 = ~1000Hz , 4 = ~2500Hz , 5 = 6250Hz , 6 = 16000Hz
int band_2 = 1;
int band_3 = 2;
int band_4 = 3;
int band_5 = 4;
int band_6 = 5;
int band_7 = 6;
int band_8 = 7;
//SERVO Motor Shield pin connections
////////////////////////////////////
// called this way, it uses the default address 0x40
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
// Depending on your servo make, the pulse width min and max may vary, you
// want these to be as small/large as possible without hitting the hard stop
// for max range. You'll have to tweak them as necessary to match the servos you
// have!
#define SERVOMIN 150 // this is the 'minimum' pulse length count (out of 4096) [150 is fine]
#define SERVOMAX 350 // this is the 'maximum' pulse length count (out of 4096) [290 is perfect]
// our servo # counter
uint8_t servo_1 = 12; // servo_1 is connected to port 12 of the PCA9685 servo board and so on for the other ports
uint8_t servo_2 = 10;
uint8_t servo_3 = 8;
uint8_t servo_4 = 6;
uint8_t servo_5 = 4;
uint8_t servo_6 = 2;
uint8_t servo_7 = 0;
uint8_t servo_8 = 14;
setup B > components > schematic > code
SETUP B uses a teensy and an audio board to read frequencies out of the audio input and send impulses to stepper drivers to controll powerfull stepper motors. For these components you will pay ~250 € and it will take you some more time to wire all together. This will provide you with a solid audio reactive motor control system, that can handle art exhibitions or little installations on festivals or concerts.
setup B > components > schematic > code
The servos from setup A are nice, but they don't have much power and are loud and not really precise. Thats why i decided to create a setup, that will use stronger stepper motors.
Instead of an Arduino Uno and a Spectrum Shield I used a single Teensy 3.5. With this setup I can easily define my own frequency bands and don't have to use the predefined frequency bands from the Spectrum Shield.
Let us have a look at the components needed, to set up a advanced audio reactive motor control:
Audio Adaptor Board for Teensy 3.0 - 3.6
This adaptor will provide the Teensy 3.5 with stereo line-level input.
costs ~15€
2x Breadboard for Arduino
The breadboard has a uniform grid on which the components and power supply are connected with wires. We need two of these small boards to allow the teensy audio board combination setup to be placed.
costs: ~6€
Dupont Jumper Cable
There are different versions of these cables, which differ in their ends. There are male-male, female-female or male-female ends. It is best to have enough of all variants in stock. Furthermore it is advisable to leave the colour of the cable the same for each signal.
costs: ~3€
Stackable Header Kit for Teensy
To connect the Audio Board to the Teensy.
costs ~4€
External Stepper Motor Driver for A4988/DRV8825/TMC2100
For every stepper motor we will need one of these boards. But before we can use this board, we have to remove one resistor and add a new 4.6 kOhms resistor on the flipside. You will find a detailed tutorial for this rebuild down in the schematic.
costs ~5€/piece
4.6 kOhm Resistor
For rebuilding the Stepper Driver Board.
costs ~0.05€/piece
Stepper Driver TMC2208
This driver controls the motor and makes its rotation ultra quiet, which is pretty useful for sound installations. For each stepper motor in the final setup we will need one of these drivers.
costs ~6€/piece
Stepper Motor Nema 17
There are different types of Nema 17 Motors available. All of them are strong and precise.
costs ~10€/piece
Micro USB-B Cable
Connecting computer and teensy.
costs ~5€/piece
setup B > components > schematic > code
Before we can start to wire everything up, we have to rebuild the stepper driver board, so it will work togehter with the ultra quiet TMC2208 driver. At first remove the R1 resistor on the front while using needle-nosed pliers or hit it hard but carefully with a small screw driver.
After this solder a ~4.6 Ohm resistor on the back, connecting GND (ground) and EN (enable).
After you finished this rebuild, connect your 12-24V power supply to the setup. Please pay special attention to directions of the currents! Otherwise you will burn your TMC2208 very fast. Finaly you have to set the right current setting on your TMC2208 driver while turning the potentiometer and measuring the voltage simultaneously. Please find detailed information how to this in this little guide or in this youtube-tutorial.
And now let us have a look at the schema of the setup.
setup B > components > schematic > code
Here you can find the code for Setup B.
Copy all code of the tabs (decleraton, void setup, void loop) into your arduino software or download (soon) the *.ino file.
//AURA SETUP B v1.0
//12. February 2020
//written by ALEX REX
//alexrex.de/audioreactive/
//This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.
#include
#include
#include
#include
#include
#include
// AUDIO BOARD DECLERATION///////////////////////////////////
// GUItool: begin automatically generated code
AudioInputI2S i2s1; //xy=253,139
AudioAnalyzeFFT1024 fft1024_1; //xy=388,279
AudioAnalyzePeak peak1; //xy=398,232
AudioOutputI2S i2s2; //xy=476,149
AudioConnection patchCord1(i2s1, 0, i2s2, 0);
AudioConnection patchCord2(i2s1, 0, i2s2, 1);
AudioConnection patchCord3(i2s1, 0, peak1, 0);
AudioConnection patchCord4(i2s1, 0, fft1024_1, 0);
AudioControlSGTL5000 sgtl5000_1; //xy=335,333
// GUItool: end automatically generated code
#define DEBUG 1 //debug anzeige (Serial.print(...);) aktivieren/deaktivieren
//PINS FÜR POTIS ZUM EINSTELLEN DES GEWÜNSCHEN FREQUENZBANDES:
#define PEAK_LEVEL_PIN A2
#define BASS_FREQ_PIN A6
#define BASS_SPREAD_PIN A3
int knob_peak = 0;
int knob_bass_freq = 0;
int knob_bass_spread = 0;
float fft_boi = 0; //boi = "bin of interest"
float fft_threshold = 0.050; // 0.090
float peak = 0;
int lastFilterValue = 0; //variable for storing filter values
int lastFilterPeak = 0; //variable for storing filter values
float weight = 0.5; //this value adjusts how much a new value affects the filtered result:
elapsedMillis msecs; //sometimes simpler than using metro() or ... chrono()
// STEPPER DECLERATION///////////////////////////////////
Stepper motor1(31, 32); // STEP green jumper cable, DIR yellow jumper cable
Stepper motor2(29, 30); // STEP, DIR
Stepper motor3(27, 28); // STEP, DIR
Stepper motor4(25, 26); // STEP, DIR
Stepper motor5(34, 33); // STEP green jumper cable, DIR yellow jumper cable
Stepper motor6(36, 35); // STEP, DIR
Stepper motor7(38, 37); // STEP, DIR
Stepper motor8(24, 39); // STEP, DIR
StepControl controller1; // Use default settings
const int microsteppings = 16;
long umdrehung = 100 * microsteppings; // 200*microsteppings
// AUDIO REACTIVE DECLERATION///////////////////////////////////
examples
The natural scientist and artist Hans Jenny points out that the effect of sound on space is characterized by the following signatures: shaped structures and dynamic movements, which both merge into a unity through a periodic play of forces. These signatures will shape your audio reactive motor controlled project.
Have fun experimenting creatively with the parameters of the setups:
Mechanics:
- Forms of movement such as: Rotation, longitudinal movement
- Various adapters for the motors
- Forwarding of movement to objects etc.
Software:
- Motor control: speed, acceleration, delay
- Sound analysis: volume level, frequency selection
- Add more sensors for a rich interactive installation
example 1
simple rotation
This is the first very simple configuration in which I assigned a motor to each frequency band, which rotates whenever the corresponding frequency reaches a certain level in the song. I used setup A and 360° rotation servos for this.
In addition to the seven motors that move coupled to the analysis of the seven predefined frequency bands of the Spectrum Shield, I have connected an eighth motor whose rotation is transformed into a longitudinal motion. This eighth motor also moves to a certain defined frequency band, which I assigned to it.
example 2
linear movement
This is the second configuration. For this I used setup A and 180° rotation servos, which move linear actuators forward or backward. These seven motors and components are arranged in a hexagon and have a seventh motor in the center. On the end of the 3D printed mechanical actuators I fixed surfaces. These lift or lower thin rods which are guided through a grid of a black panel. Thus sound can be represented visually in a defined moving matter.
The 3D printed parts are created by potentprintables and are available at thingieverse.
example 3
In The Woods
For this setup I use a Teensy 3.5, which analyses the sound and uses this information to drive control commands to stepper motors. The motors rotate when a defined frequency exceeds a certain level. The rotation of the motor is converted into an oscillating movement of a rod via an eccentric. The wooden stick is set in motion by the music of a piano. In the final implementation, a piano concerto is thus extended immersively. In the final realization, a piano concerto is thus sensually expanded.
Please check again in february to see the photos of the final installation.
contact
Please contact me via e-mail:
mail[at]alexrex.de
You will find my other project in my portfolio:
www.alexrex.de
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.