matt_terje
Published © GPL3+

Sound Wave Starting Gun

The brief for this project was to enable a professional deaf runner to react to the sound of a starting pistol.

BeginnerShowcase (no instructions)670
Sound Wave Starting Gun

Things used in this project

Hardware components

Shaftless Vibration Motor
×1
SparkFun Sound Detector (with Headers)
SparkFun Sound Detector (with Headers)
×1

Story

Read more

Schematics

Circuit Diagram

Code

Sound Wave Start Gun Code

C#
// First we assign a label each of the key features of the code.

int micPin = A2; // sound detector in analog pin A2.

int vibrationPin = 3; // vibration motor in digital pin 3.

// creating boxes for the values from the sound detector to go into.

int micValue1 = 0;  // The way we know whether or not there is a loud noise occuring is by
                    // collecting two consecutive readings from the sound detector and calculating
int micValue2 = 0;  // the difference between the two. This bit of code essentially creates a box
                    // for these two values to be stored.


// The setup establishes the building blocks of the code.

void setup() 
{ 
  Serial.begin(9600);   // tells the code to expect a reading from the serial monitor.
  pinMode(vibrationPin, OUTPUT); // tells the code that vibrationPin is an output = current out.
  pinMode(micPin, INPUT); // tells the code that the micPin is an input = current in.
}


// The loop is the instruction manual - telling the code what to do whilst looping continuously.

void loop()
{
  micValue1 = analogRead(micPin);   // put a value in the micValue1 box from the micPin.
  Serial.println(micValue1);        // send micValue1 to the serial monitor
  
  delay(1);                         // wait 1 millisecond
  
  micValue2 = analogRead(micPin);   // put a value in the micValue2 box from the micPin
  Serial.println(micValue2);        // send micValue2 to the serial monitor
  
  if (micValue1 - micValue2 > 140 || micValue2 - micValue1 > 140)   // The boolean maths equation which uses the values 
                                                                    // in the boxes to make the calculation and will
  {                                                                 // return a True or False answer. (|| = or)
   digitalWrite(vibrationPin, HIGH);            // if True (the differnece in either equation is > 140) turn on the vibration motor 
   delay(2000);                                 // for 2 seconds
   digitalWrite(vibrationPin, LOW);             // then turn the vibration motor off
      delay(500);                               // for half a second

                                                // the loop is tne repeated
                                                // note that if the equation returns false the loop
                                                // begins again
  }
}

Credits

matt_terje

matt_terje

1 project • 0 followers

Comments