We received our cut parts yesterday. There was some sort of malfunction with the laser cutter and the 1/4" acrylic wasn't cut all the way through. Since the material is so brittle it was to difficult to get the parts out of the cuts. While trying to get the parts separated three of the four were broken beyond repair. The parts were super glued back together but they are not going to be strong enough to be used in the actual prototype.
Friday, December 12, 2014
Thursday, December 11, 2014
We took another large step in completing the project. Our group was having trouble creating more complex knocks. We manipulated the code multiple times, but no matter what we did we could not create complex knocks. After trouble shooting for multiple hours we decided that we needed to get a new sensor, so Adam went to radio shack and picked up a Piezo Transistor. When installed the next day, it solved all of our problems. This video shows the more complex knock that we created.
This is our part that is being fabricated, which was created using Solidworks. This part will be created using a laser cutter with 1/4 inch acrylic. We will need six of these to create the mechanism that will turn the lock on the door. We will connect those six pieces by bolts, and then connect them to the motor.
Tuesday, December 9, 2014
Here is a video showing how the knock detected will unlock the door.
https://www.youtube.com/watch?v=_UEoKcbbSzQ
https://www.youtube.com/watch?v=_UEoKcbbSzQ
Today our team got the motor that is capable of turning the knob on the structure. We then connected the motor to the circuit we had ready. The only issue we ran into is that we don't have the right piezo sensor. We ran some tests to get the motor working. Here is the code we used:
Analog Pin 0: Piezo speaker (connected to ground with 1M pulldown resistor)
Digital Pin 2: Switch to enter a new code. Short this to enter programming mode.
Digital Pin 3: DC gear reduction motor attached to the lock. (Or a motor controller or a solenoid or other unlocking mechanisim.)
Digital Pin 4: Red LED.
Digital Pin 5: Green LED.
Update: Nov 09 09: Fixed red/green LED error in the comments. Code is unchanged.
Update: Nov 20 09: Updated handling of programming button to make it more intuitive, give better feedback.
Update: Jan 20 10: Removed the "pinMode(knockSensor, OUTPUT);" line since it makes no sense and doesn't do anything.
*/
// Pin definitions
const int knockSensor = 0; // Piezo sensor on pin 0.
const int programSwitch = 2; // If this is high we program a new code.
const int lockMotor = 9; // Gear motor used to turn the lock.
const int redLED = 4; // Status LED
const int greenLED = 5; // Status LED
// Tuning constants. Could be made vars and hoooked to potentiometers for soft configuration, etc.
const int threshold = 15; // Minimum signal from the piezo to register as a knock
const int rejectValue = 25; // If an individual knock is off by this percentage of a knock we don't unlock..
const int averageRejectValue = 15; // If the average timing of the knocks is off by this percent we don't unlock.
const int knockFadeTime = 150; // milliseconds we allow a knock to fade before we listen for another one. (Debounce timer.)
const int lockTurnTime = 650; // milliseconds that we run the motor to get it to go a half turn.
const int maximumKnocks = 20; // Maximum number of knocks to listen for.
const int knockComplete = 1200; // Longest time to wait for a knock before we assume that it's finished.
#include <Servo.h>
Servo myservo;
// Variables.
int secretCode[maximumKnocks] = {50, 25, 25, 50, 100, 50, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; // Initial setup: "Shave and a Hair Cut, two bits."
int knockReadings[maximumKnocks]; // When someone knocks this array fills with delays between knocks.
int knockSensorValue = 0; // Last reading of the knock sensor.
int programButtonPressed = false; // Flag so we remember the programming button setting at the end of the cycle.
void setup() {
pinMode(lockMotor, OUTPUT);
pinMode(redLED, OUTPUT);
pinMode(greenLED, OUTPUT);
pinMode(programSwitch, INPUT);
myservo.attach(9); // attaches the servo on pin 9 to the servo object
Serial.begin(9600); // Uncomment the Serial.bla lines for debugging.
Serial.println("Program start."); // but feel free to comment them out after it's working right.
digitalWrite(greenLED, HIGH); // Green LED on, everything is go.
}
void loop() {
// Listen for any knock at all.
knockSensorValue = analogRead(knockSensor);
if (digitalRead(programSwitch)==HIGH){ // is the program button pressed?
programButtonPressed = true; // Yes, so lets save that state
digitalWrite(redLED, HIGH); // and turn on the red light too so we know we're programming.
} else {
programButtonPressed = false;
digitalWrite(redLED, LOW);
}
if (knockSensorValue >=threshold){
Serial.println(knockSensorValue);
listenToSecretKnock();
}
}
// Records the timing of knocks.
void listenToSecretKnock(){
Serial.println("knock starting");
int i = 0;
// First lets reset the listening array.
for (i=0;i<maximumKnocks;i++){
knockReadings[i]=0;
}
int currentKnockNumber=0; // Incrementer for the array.
int startTime=millis(); // Reference for when this knock started.
int now=millis();
digitalWrite(greenLED, LOW); // we blink the LED for a bit as a visual indicator of the knock.
if (programButtonPressed==true){
digitalWrite(redLED, LOW); // and the red one too if we're programming a new knock.
}
delay(knockFadeTime); // wait for this peak to fade before we listen to the next one.
digitalWrite(greenLED, HIGH);
if (programButtonPressed==true){
digitalWrite(redLED, HIGH);
}
do {
//listen for the next knock or wait for it to timeout.
knockSensorValue = analogRead(knockSensor);
if (knockSensorValue >=threshold){ //got another knock...
//record the delay time.
Serial.println("knock.");
now=millis();
knockReadings[currentKnockNumber] = now-startTime;
currentKnockNumber ++; //increment the counter
startTime=now;
// and reset our timer for the next knock
digitalWrite(greenLED, LOW);
if (programButtonPressed==true){
digitalWrite(redLED, LOW); // and the red one too if we're programming a new knock.
}
delay(knockFadeTime); // again, a little delay to let the knock decay.
digitalWrite(greenLED, HIGH);
if (programButtonPressed==true){
digitalWrite(redLED, HIGH);
}
}
now=millis();
//did we timeout or run out of knocks?
} while ((now-startTime < knockComplete) && (currentKnockNumber < maximumKnocks));
//we've got our knock recorded, lets see if it's valid
if (programButtonPressed==false){ // only if we're not in progrmaing mode.
if (validateKnock() == true){
triggerDoorUnlock();
} else {
Serial.println("Secret knock failed.");
digitalWrite(greenLED, LOW); // We didn't unlock, so blink the red LED as visual feedback.
for (i=0;i<4;i++){
digitalWrite(redLED, HIGH);
delay(100);
digitalWrite(redLED, LOW);
delay(100);
}
digitalWrite(greenLED, HIGH);
}
} else { // if we're in programming mode we still validate the lock, we just don't do anything with the lock
validateKnock();
// and we blink the green and red alternately to show that program is complete.
Serial.println("New lock stored.");
digitalWrite(redLED, LOW);
digitalWrite(greenLED, HIGH);
for (i=0;i<3;i++){
delay(100);
digitalWrite(redLED, HIGH);
digitalWrite(greenLED, LOW);
delay(100);
digitalWrite(redLED, LOW);
digitalWrite(greenLED, HIGH);
}
}
}
// Runs the motor (or whatever) to unlock the door.
void triggerDoorUnlock(){
Serial.println("Door unlocked!");
int pos=0;
int i=0;
for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
//for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
//{
// myservo.write(pos); // tell servo to go to position in variable 'pos'
// delay(15); // waits 15ms for the servo to reach the position
//}
// turn the motor on for a bit.
//digitalWrite(lockMotor, HIGH);
//digitalWrite(greenLED, HIGH); // And the green LED too.
//delay (lockTurnTime); // Wait a bit.
//digitalWrite(lockMotor, LOW); // Turn the motor off.
// Blink the green LED a few times for more visual feedback.
for (i=0; i < 5; i++){
digitalWrite(greenLED, LOW);
delay(100);
digitalWrite(greenLED, HIGH);
delay(100);
}
}
// Sees if our knock matches the secret.
// returns true if it's a good knock, false if it's not.
// todo: break it into smaller functions for readability.
boolean validateKnock(){
int i=0;
// simplest check first: Did we get the right number of knocks?
int currentKnockCount = 0;
int secretKnockCount = 0;
int maxKnockInterval = 0; // We use this later to normalize the times.
for (i=0;i<maximumKnocks;i++){
if (knockReadings[i] > 0){
currentKnockCount++;
}
if (secretCode[i] > 0){ //todo: precalculate this.
secretKnockCount++;
}
if (knockReadings[i] > maxKnockInterval){ // collect normalization data while we're looping.
maxKnockInterval = knockReadings[i];
}
}
// If we're recording a new knock, save the info and get out of here.
if (programButtonPressed==true){
for (i=0;i<maximumKnocks;i++){ // normalize the times
secretCode[i]= map(knockReadings[i],0, maxKnockInterval, 0, 100);
}
// And flash the lights in the recorded pattern to let us know it's been programmed.
digitalWrite(greenLED, LOW);
digitalWrite(redLED, LOW);
delay(1000);
digitalWrite(greenLED, HIGH);
digitalWrite(redLED, HIGH);
delay(50);
for (i = 0; i < maximumKnocks ; i++){
digitalWrite(greenLED, LOW);
digitalWrite(redLED, LOW);
// only turn it on if there's a delay
if (secretCode[i] > 0){
delay( map(secretCode[i],0, 100, 0, maxKnockInterval)); // Expand the time back out to what it was. Roughly.
digitalWrite(greenLED, HIGH);
digitalWrite(redLED, HIGH);
}
delay(50);
}
return false; // We don't unlock the door when we are recording a new knock.
}
if (currentKnockCount != secretKnockCount){
return false;
}
/* Now we compare the relative intervals of our knocks, not the absolute time between them.
(ie: if you do the same pattern slow or fast it should still open the door.)
This makes it less picky, which while making it less secure can also make it
less of a pain to use if you're tempo is a little slow or fast.
*/
int totaltimeDifferences=0;
int timeDiff=0;
for (i=0;i<maximumKnocks;i++){ // Normalize the times
knockReadings[i]= map(knockReadings[i],0, maxKnockInterval, 0, 100);
timeDiff = abs(knockReadings[i]-secretCode[i]);
if (timeDiff > rejectValue){ // Individual value too far out of whack
return false;
}
totaltimeDifferences += timeDiff;
}
// It can also fail if the whole thing is too inaccurate.
if (totaltimeDifferences/secretKnockCount>averageRejectValue){
return false;
}
return true;
}
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:
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 }
https://www.youtube.com/watch?v=lA9g-3e6hVM
This is a video showing how the lock assembly works for our project.
This is a video showing how the lock assembly works for our project.
Wednesday, December 3, 2014
We were finally able to acquire all of the materials needed for the structure which include a 24" long piece of 1" pvc, two 1" 90 degree pvc connectors, two 1" pvc end caps, a 5-way 1" pvc fitting, suction cups, and a door knob, What set the group back a little is trying to find a 5-way pvc fitting, which eventually had to be ordered online, other than that the parts were found at Rob's house, and the local hardware store.
Subscribe to:
Posts (Atom)