<
>
back to all cubes

Cricket Cube

When shade falls, the crickets in ths cube start singing

The poetic cricket cube sets an example for good minimalism. Though Liron Heffets was not a programmer, he found a way to make those little piezo transducers sound like crickets of different kinds. He also found a super-simple way to combine the sounds of two crickets in a way they sound simultaneous, using "time sharing" in a creative way.

In the cube design we also tried to find the appropriate minimalism, focusing on the way to hold the speakers in place.

Arduino code - download here

/*
  CUBES originally created by the interaction Lab, Holon Institute of Technology for the Design Museum Holon.
  http://interaction.shenkar.ac.il
  This work is licensed under a Creative Commons Attribution 3.0 Unported License

  Crickey Band Cube
   25/10/2011
 
 Written by Liron Heffets
 
 *********  documentation *********  
 this code operates two piezos in a way they sound like crickets band. 
 the number of crickets playing at a time is ruled by an analog input that comes from a light sensor (LDR - light dependent resistor). 
 high light - means no crickets are playing. 
 medium light - means one cricket is playing.
 low light (dark) - meens two crickets are playing together. 
 */

//=============================================

// const
const int firstCricetOutputPin = 2;
const int secondCricetOutputPin = 3;
const int sensorPin = A0;    // pin that the sensor is attached to

// variables:
int sensorValue = 0;         // the sensor value
int sensorMin = 1023;        // minimum sensor value
int sensorMax = 0;           // maximum sensor value
int darkLevel1 = 0;
int darkLevel2 = 0;


//=============================================


void setup()
{
  Serial.begin(115200);

  // calibrate is only meant to be run when setting up the project in a new location (and new lighting).
  // connect the cube to a computer and open serial monitor.
  // 2 seconds after turning the cube on, the Arduino built-in led will light. You then have ~5 seconds
  // to make maximum shade and maximum light, and then see the calibration data. test it and if it works
  // fine - uncomment the lines below and change the numbers accordingly.
  calibration();

  darkLevel1 = 800;
  darkLevel2 = 600; 

}


//=============================================


void loop()
{ 

  // read the sensor:
  sensorValue = analogRead(sensorPin);
  // apply the calibration to the sensor reading
  sensorValue = constrain(sensorValue, sensorMin, sensorMax); 
// play the crickets:
  playCrickets(sensorValue);
}



//=============================================



// operates the crickets band at according to analog input 'sensorValue'
void playCrickets(int sensorValue)
{
  // medume light
  if(sensorValue <= darkLevel1 && sensorValue > darkLevel2)
  {
    playOneCricket(firstCricetOutputPin);
    delay(550);
  }
  // low light
  else if(sensorValue <= darkLevel2)
  {
    int delayFactor = 100;
    int delay1 = 0;
    int delay2 = 0;
    for(int i = 0; i <= 3; i++)
    {
      switch(i)
      {  
      case 0:
        {
          delay2 = 3 * delayFactor;
        }
        break;
      case 1:
      case 3:
        {
          delay1 = delayFactor;
          delay2 = 2 * delayFactor;
        }
        break;
      case 2:
        {
          delay1 = 2 * delayFactor;
          delay2 = delayFactor;
        }
        break;
      }
      playOneCricket(firstCricetOutputPin);
      delay(delay1);
      playOneCricket(secondCricetOutputPin);
      delay(delay2);
    }
  }
}


//=============================================


// operates one cricket at the digital output givven pin. 
void playOneCricket(int outputPin)
{
  int duration  = 35;
  int delayTime = duration + 5;
  int startPitch = 100;
  int pitchBounce = 20;

  int sp = startPitch;  
  for(int i = 0; i < 6; i++)
  {
    tone(outputPin, sp, duration);
    delay(delayTime);  
    sp += pitchBounce;
  }
  noTone(outputPin);
}


void calibration() {

  // give the operator 2 seconds to put the cube on the table
  delay(2000);

  // turn on LED to signal the start of the calibration period:
  pinMode(13, OUTPUT);
  digitalWrite(13, HIGH);

  // calibrate for ~5 seconds
  while (millis() < 7000) 
  {
    sensorValue = analogRead(sensorPin);
    if (sensorValue > sensorMax) 
    {
      sensorMax = sensorValue;
    }
    if (sensorValue < sensorMin) 
    {
      sensorMin = sensorValue;  
    }
  }

  // signal the end of the calibration period
  digitalWrite(13, LOW);

// calcutate the levels of light where the chirping is changed. 
// there are three levels (as documented above.)
  int delta = (sensorMax - sensorMin) / 3;
  darkLevel1 = delta * 2 + sensorMin;
  darkLevel2 = delta + sensorMin; 
  
  Serial.print("sensorMin: ");  
  Serial.println(sensorMin);  
  Serial.print("sensorMax: ");  
  Serial.println(sensorMax);  
  Serial.print("darkLevel1: ");  
  Serial.println(darkLevel1);
  Serial.print("darkLevel2: ");  
  Serial.println(darkLevel2);

}

Parts:

(1x) Arduino Mini Pro 5V

(1x) Small Piezo Transducer

(1x) Large Piezo Transducer

(1x) LDR - Light Dependent Resistor

(1x) 7.2V Li-Po Battery

(1x) 5.5/2.1mm Jack Socket