Sensors: Thunder

Thunder

I was working on a site fairly recently where a nearby building was using an old siren as a warning. The kind that served as warnings for the Blitzkrieg. This got me thinking about warnings, and I ended up wanting to work with that same sound. Thunder is, in concept, a simulator for someone reminiscing about the blitz. It consists of three sensors: one proximity sensor on the headphones, and 2 light sensors on the board. Triggereing all of them will cause a recording of  blitz sirens to play. Removing your hands or taking off the headphones causes the audio to stop.

//video here

In this video, the headphones are unplugged for demonstration reasons. Originally I wanted to have it so that the user’s hands would have to cover their ears, but this led to complications. The act of physically placing your hands in a certain place functions as giving an entry and exit to the space of memory.

IMG_1074

the full rig

IMG_1081

the two green squares are light sensors, and the purple/white cable set leads to  the headphone sensor. the other leads nowhere and does nothing.

IMG_1082

Arduino Code. Modified to return a yes/no response

int sv0 = 0;  // variable to store the value coming from the sensors
int sv1 = 0;
int sv2 = 0; 
int req = 400;
 
void setup() {
  Serial.begin(9600);  // initialize serial communications    
}
 
void loop() {
 
  // Read the value from the sensors:
  sv0 = analogRead (A0); 
  sv1 = analogRead (A1);  
  sv2 = analogRead (A2);  
 
  //Serial.print(sv0);
  //Serial.print(" : ");
  //Serial.print(sv1);
  //Serial.print(" : ");
  //Serial.println(sv2);
  if((sv0 < req) && (sv1 < req) && (sv2 < req)){
    Serial.println ("A");
  } else {
    Serial.println ("B");
  }
  delay (50);   // wait a fraction of a second, to be polite
}

Processing Code

// Processing program to handle audio playing
 
// Import the Serial library and create a Serial port handler
import processing.serial.*;
Serial myPort;   
 
import ddf.minim.*; 
Minim minim;
AudioPlayer player; 
 
int valueA;  // Sensor Value A
int valueB;  // Sensor Value B
Boolean running = false;
 
//------------------------------------
void setup() {
  size(1024, 200);
 
  // List my available serial ports
  int nPorts = Serial.list().length; 
  for (int i=0; i &lt; nPorts; i++) {
    println("Port " + i + ": " + Serial.list()[i]);
  } 
 
  // Choose which serial port to fetch data from. 
  // IMPORTANT: This depends on your computer!!!
  // Read the list of ports printed by the code above,
  // and try choosing the one like /dev/cu.usbmodem1411
  // On my laptop, I'm using port #4, but yours may differ.
  String portName = Serial.list()[5]; 
  myPort = new Serial(this, portName, 9600);
  serialChars = new ArrayList();
  
  minim = new Minim(this);
  player = minim.loadFile("AirRaidSirens1.wav");
  
}
 
//------------------------------------
void draw() {
 
  // Process the serial data. This acquires freshest values. 
  processSerial();
 
  background (150);  
 
}
 
 
//---------------------------------------------------------------
// The processSerial() function acquires serial data byte-by-byte, 
// as it is received, and when it is properly captured, modifies
// the appropriate global variable. 
// You won't have to change anything unless you want to add additional sensors. 

ArrayList serialChars;      // Temporary storage for received serial data
int whichValueToAccum = 0;  // Which piece of data am I currently collecting? 
boolean bJustBuilt = false; // Did I just finish collecting a datum?
 
void processSerial() {
 
  while (myPort.available () &gt; 0) {
    char aChar = (char) myPort.read();
 
    // checks whether all sensors are currently triggered or not.
    if (aChar == 'A' &amp;&amp; running == false) {
      running = true;
      player.play();
      println("playing...");
    } else if (aChar == 'B' &amp;&amp; running == true) {
      running = false;
      println("stopping");
      player.pause();
      player.rewind();
    }
  }
}

 

Comments are closed.