Five piezos are used to trigger a thunder sound in Pure Data in an attempt to control both panning and volume at once. This could be potentially useful when live control of a thunderstorm with lightning strikes at various distances and sizes, it could also be used in a war scene with many explosions of varying intensity.
There seems to be no real advantage of using this setup over a traditional set of drum pads/ triggers but it's helped me get to grips with some basic Arduino concepts. It may be worth experimenting with arranging the piezos differently before moving on to more complex sensors.
The piezos were connected to analog inputs 0-4, a 1M Ohm resistor was wired in parallel with the piezos to function as a pull down resistor.
Below is the Arduino code, it makes use of the Arduino MIDI library. It's modified from the example "knock" sketch that comes with the Arduino IDE so there may be a few needless vestiges of that in there.
#include <MIDI.h>
const int ledPin = 13; // led connected to digital pin 13
const int piezo1 = A0; // the piezo is connected to analog pin 0
const int piezo2 = A1;
const int piezo3 = A2;
const int piezo4 = A3;
const int piezo5 = A4;
const int threshold = 100; // threshold value
int sensorReading1 = 0; // variable to store the value read from the sensor pin A0
int sensorReading2 = 0;
int sensorReading3 = 0;
int sensorReading4 = 0;
int sensorReading5 = 0; // variable to store the value read from sensor pin A1
int ledState = LOW; // variable used to store the last LED status, to toggle the light
void setup() {
pinMode(ledPin, OUTPUT); // declare the ledPin as as OUTPUT
MIDI.begin(); // Launch MIDI with default options
}
void loop() {
// read the sensors and store it in the variable sensorReadingx:
sensorReading1 = analogRead(piezo1);
sensorReading2 = analogRead(piezo2);
sensorReading3 = analogRead(piezo3);
sensorReading4 = analogRead(piezo4);
sensorReading5 = analogRead(piezo5);
// if the sensor 1 reading is greater than the threshold:
if (sensorReading1 >= threshold) {
// send noteon
MIDI.sendNoteOn(100, analogRead(piezo1) / 8, 1);
delay(100);
MIDI.sendNoteOff(100, analogRead(piezo1) / 8, 1);
delay(5);
}
// if the seonsor 2 reading is greater than the threshold:
if (sensorReading2 >= threshold) {
// send noteon
MIDI.sendNoteOn(75, analogRead(piezo2) / 8, 1);
delay(100);
MIDI.sendNoteOff(75, analogRead(piezo1) / 8, 1);
delay(5);
}
// if the seonsor 3 reading is greater than the threshold:
if (sensorReading3 >= threshold) {
// send noteon
MIDI.sendNoteOn(50, analogRead(piezo3) / 8, 1);
delay(100);
MIDI.sendNoteOff(50, analogRead(piezo1) / 8, 1);
delay(5);
}
// if the seonsor 4 reading is greater than the threshold:
if (sensorReading4 >= threshold) {
// send noteon
MIDI.sendNoteOn(25, analogRead(piezo4) / 8, 1);
delay(100);
MIDI.sendNoteOff(25, analogRead(piezo1) / 8, 1);
delay(5);
}
// if the seonsor 5 reading is greater than the threshold:
if (sensorReading5 >= threshold) {
// send noteon
MIDI.sendNoteOn(1, analogRead(piezo4) / 8, 1);
delay(100);
MIDI.sendNoteOff(1, analogRead(piezo1) / 8, 1);
delay(5);
}
}
The piezos were attached to a hardback notebook with electrical tape as shown in the image below.
The piezos control a modified version of an example patch from Andy Farnell's Designing Sound as shown below. Pan and gain controls were added (highlighted in blue). The left outlet of the notein object triggers the "go" object and plays the thunder sound when any value is received.
The middle outlet of the notein object is the velocity value which controls the output volume, a spigot object is used to store the velocity value for longer than the duration of contact with the piezo, maintaining a consistent volume for each hit.
As the midi notes used are 1 for the leftmost piezo, 25, 50, 75 for the middle piezos and 100 for the rightmost these values are divided by 100 in order to control the pan_position fader.
Triggering a different instance of the original patch for each piezo would probably be more useful as the current setup doesn't sound great when the lightning/ thunder strikes overlap.