Thursday, December 4, 2014

A huge step today was taken towards completing this project. The circuit was assembled and tested. We faced some difficulty trying to make the speaker work as a piezo sensor. We also noticed that the motor we have is small and that we need a bigger one. The structure is finally assembled and we have the " 5-way pvc " ready to be attached to the circuit once the piezo sensor and motor are connected.


here is the code that we used to test the circuit:


/* Knock Sensor
 * ----------------
 *
 * Program using a Piezo element as if it was a knock sensor.
 *
 * We have to basically listen to an analog pin and detect 
 * if the signal goes over a certain threshold. It writes
 * "knock" to the serial port if the Threshold is crossed,
 * and toggles the LED on pin 13.
 *
 * (cleft) 2005 D. Cuartielles for K3
 * edited by Scott Fitzgerald 14 April 2013
 */

int ledPin = 13;
int knockSensor = 0;               
byte val = 0;
int statePin = LOW;
int THRESHOLD = 100;

void setup() {
 pinMode(ledPin, OUTPUT); 
 Serial.begin(9600);
}

void loop() {
  val = analogRead(knockSensor);     
  if (val >= THRESHOLD) {
    statePin = !statePin;
    digitalWrite(ledPin, statePin);
    Serial.println("Knock!");

  }
  delay(100);  // we have to make a delay to avoid overloading the serial port
}

No comments:

Post a Comment