Posts | Comments

Planet Arduino

Archive for the ‘Piezo’ Category

Feb
05

Space invaders played on a 16×2 character display

arduino hacks, character lcd, Piezo, space invaders, video game, wii nunchuk Comments Off on Space invaders played on a 16×2 character display 

character-lcd-space-invaders

This Space Invaders game does more with less. [Rjk79] managed to make a video game using a two-line character display. The game consists of a wave of invaders on the top line, with the defender cannon on the bottom. The invader isn’t just stationary, but randomly moves to the left and the right. The image above captured a little bit of motion blur from the defender moving into position before firing on the enemy.

An Arduino board controls the 16×2 HD44780 character display. The game also includes sounds generated by the piezo buzzer seen on the breadboard. All the way to the right you can see the Wii Nunchuk breakout board which provides directional control and the firing trigger. If you want to recreate this one for yourself [Rjk79] is sharing the source code on Pastebin. There’s also a demo video found after the jump.

If you don’t have a character LCD on hand you might try this other Space Invaders clone that uses an 8×8 led matrix.

Space invaders on 16x2 Character LCD


Filed under: arduino hacks
Feb
02

Music challenge has you flapping your wrist to make sounds

Accelerometer, arduino hacks, music, musical hacks, Piezo, simon says Comments Off on Music challenge has you flapping your wrist to make sounds 

glove-based-music-challenge

This glove controller let you play a musical game. The challenge is to perform the correct wrist motions at the right tempo to play the intro to the song Where is my Mind by the Pixies. This is demonstrated in the video clip after the break.

We often see flex sensors used on the fingers of glove projects, but this one does it all with an accelerometer. That module, along with the Piezo buzzer used for playback are affixed to the small breadboard on the back side of his hand. Rubber bands connect the Arduino to his third and forth fingers. The tempo and rhythm are pre-programmed but the tone generated is based on the gravity reading at the start of each note. If you don’t have your hand positioned correctly the wrong tone will be played.

The code was published in link at the top. It would be fun to see this altered as a hacked Simon Says game.


Filed under: arduino hacks, musical hacks
Dec
21

Wooden box repeats rhythm used when knocking on the lid

arduino hacks, knock, knock block, Piezo, solenoid Comments Off on Wooden box repeats rhythm used when knocking on the lid 

knock-box-build

[Paul Mandel] just finished building this knock box project. It’s a familiar concept that uses a solenoid to tap on the side of the box. The Arduino driven setup monitors vibrations on the lid. When you knock on the box, it records the pattern and plays it back using the solenoid.

He was inspired by a knock-detecting door lock. Using that code as the starting point he implemented a system that takes input from a simple push button and echos back the rhythm using the Pin 13 LED on the Arduino board. This is a great way to start as it removes the complexity of driving a solenoid and monitoring a piezo element. After a bit of success he implemented each of those hardware modules one at a time. You can get a look at the final product in the clip after the break.

One of our favorite version of this project is still the knock block from several years back.


Filed under: arduino hacks
Nov
02

Build a Basic Infrared Motion Alarm with Weekend Projects

alarm, arduino, GreatCreate, MAKE Projects, Piezo, PIR, pir sensor, RadioShack, Sensor, Weekend Projects Comments Off on Build a Basic Infrared Motion Alarm with Weekend Projects 

rs16_blog_featurecBuild a motion-sensing alarm by combining a few common components: an Arduino, a PIR sensor, a piezo buzzer, and a breadboard. All you need is some jumper wire to connect them all, and the software to run it.

Read the full article on MAKE

Side view

Side view

Contest Entry by Steve Hoefer

How many times have you seen a secret hideout with a secret knock?  It’s a staple of cheesy dramas, Saturday afternoon movies, and tree houses throughout the world.

While working on another project I ran across the Arduino knock sensor tutorial.  Sensing a single knock is a great little project for learning about microcontrollers, but what about sensing specific knocks?  Seeeeecret knocks?  And if we could detect a secret knock, shouldn’t it unlock a door?   If you can’t tell by looking this was cobbled together from spare stuff around the lab, it’s not much more than a piezo speaker, a tiny gear reduction motor, and an Arduino. And PVC pipe.

**Disclaimer: This was built with stuff I had lying around the lab.  How about a video to explain:

A microphone (okay, really a speaker) presses against the door and listens for knocks.  If it hears the right number of knocks in the right cadence it triggers the motor to turn the deadbolt and unlock the door.  If the sequence isn’t recognized, the system resets and listens for knocks again.

The default code is Shave and a Hair Cut but if that’s too obvious you can enter a new knock sequence by holding down the red button and knocking your new secret knock (up to 20 knocks).  The rhythm of your favorite song, Morse code, whatever!  The widget will play back your knock (by blinking the lights) so you can be sure it heard everything correctly.

The whole thing is attached to the door with suction cups

The components are simple, most of the work is done in the microcontroller.  The source code for the Arduino is available at the bottom of the page if you’re curious.

How does it work?

First it records the time between knocks.  If there is a long wait for a knock it stops listening and starts analyzing.

Basic circuity

Basic circuity

First it checks the number of knocks.  If that’s right, we go on to more vigorous authentication.   First it converts the absolute timing of the knocks to the rhythm of the knocks.  This lets us knock fast or slow and as long as we get the rhythm right it will unlock.  That way I can still unlock the door if I’m tired or full of caffeine.  After this it compares the timing with the secret key and if any individual knock is off by too much or the whole thing is off by a certain average amount the door stays locked.  If not, we trigger the motor to turn and the lock to unlock.  If the programming button is pressed it saves the rhythm information and then plays it back.

The detection is surprisingly accurate and can even be dialed up so it’s precise enough  to detect an individual person’s variation on a knock, similar to a Morse coder’s ‘fist‘.  (Though when the verifying is this tight it also triggers false negatives which are annoying.)

To keep things simple (and it’s because it’s what I had available) a motor is attached to the deadbolt using two pieces of spring steel bolted across the D shaft of the motor so that the connection will slip when the lock turns as far as it can. A more precise (and probably durable) way to do it would be to use a servo to turn the lock or have a detector sense when the lock had reached its extent.  Or replace the dead bolt with a solenoid.  Or whatever else you can think of.

Circuit fitting

Circuit fitting

The rest of the electronics are nothing special.  Its so simple that just adding feedback LEDs almost doubled the parts count.  The Arduino has a lot of unused potential on this project.

No proper schematic yet, but there’s a layout and parts list at the bottom of the page. Look for a fully documented Instructable soon.

With some extra electronics (an H-bridge) it would be possible to have the door automatically lock as well as unlock. Other improvements or changes that someone could do:

  • Adding a knob to adjust the sensitivity.
  • Building it into an actual door knocker.
  • Using a more economical microcontroller and enabling a sleep mode for better battery life.
  • Making the whole package small enough to fit inside the door.
  • Storing several knocks so several people can have their own private knocks.
  • Adding a real-time clock and using different knocks for different days of the week or times of day.
  • Listening for door bell presses rather than door knocks.
  • Adding a servo or solenoid powered knocker to provide feedback through the door.  It could then offer a challenge-response security where the door starts a knock sequence and the user has to finish it correctly.
  • Rather than listening for knocks, putting a photoresistor in the peep hole and detecting flashes of light from a pocket flashlight or simply by placing your hand over the peephole. Or an infrared receiver and use special key presses on a remote control.
Knock sensor layout (click for larger view)

Knock sensor layout (click for larger view)

Do I have to point out that this is not a great security measure since overhearing a knock sequence is pretty trivial?  No.  But it’s fun to make and play with.

Here’s my code: If you have trouble with cut and paste below you can download the .pde file here.

  1. /* Detects patterns of knocks and triggers a motor to unlock
  2. it if the pattern is correct.
  3.  
  4. By Steve Hoefer http://grathio.com
  5. Version 0.1.09.10.24
  6. Licensed under Creative Commons Attribution-Noncommercial-Share Alike 3.0
  7.  
  8. Analog Pin 0: Piezo speaker (connected to ground with 1M pulldown resistor)
  9. Digital Pin 2: Switch to enter a new code.  Short this to enter programming mode.
  10. Digital Pin 3: DC gear reduction motor attached to the lock. (Or a motor controller or
  11. a solenoid or other unlocking mechanisim.)
  12. Digital Pin 4: Green LED.
  13. Digital Pin 5: Red LED.
  14. */
  15.  
  16. // Pin definitions
  17. const int knockSensor = 0;
  18. // Piezo sensor on pin 0.
  19. const int programSwitch = 2;
  20. // If this is high we program a new code.
  21. const int lockMotor = 3;
  22. // Gear motor used to turn the lock.
  23. const int redLED = 4;
  24. // Status LED
  25. const int greenLED = 5;
  26. // Status LED
  27.  
  28. // Tuning constants.
  29. // Could be made vars and hooked to potentiometers for soft configuration, etc.
  30. const int threshold = 4;
  31. // Minimum signal from the piezo to register as a knock
  32. const int rejectValue = 25;
  33. // If an individual knock is off by this percentage of a knock we don’t unlock..
  34. const int averageRejectValue = 15;
  35. // If the average timing of the knocks is off by this percent we don’t unlock.
  36. const int knockFadeTime = 150;
  37. // milliseconds we allow a knock to fade before we listen for another one. (Debounce timer.)
  38. const int lockTurnTime = 450;
  39. // milliseconds that we run the motor to get it to go a half turn.
  40.  
  41. const int maximumKnocks = 20;
  42. // Maximum number of knocks to listen for.
  43. const int knockComplete = 1200;
  44. // Longest time to wait for a knock before we assume that it’s finished.
  45.  
  46. // Variables.
  47. int secretCode[maximumKnocks] = {50, 25, 25, 50, 100, 50, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  48. // Initial setup: "Shave and a Hair Cut, two bits."
  49. int knockReadings[maximumKnocks];
  50. // When someone knocks this array fills with delays between knocks.
  51. int knockSensorValue = 0; // Last reading of the knock sensor.
  52.  
  53. void setup() {
  54. pinMode(knockSensor, OUTPUT);
  55. pinMode(lockMotor, OUTPUT);
  56. pinMode(redLED, OUTPUT);
  57. pinMode(greenLED, OUTPUT);
  58. pinMode(programSwitch, INPUT);
  59.  
  60. //Serial.begin(19200);
  61. // Uncomment the Serial.bla lines for debugging.
  62. //Serial.println("Program start.");  // This line too.
  63.  
  64. digitalWrite(greenLED, HIGH);
  65. // Green LED on, everything is go.
  66. }
  67.  
  68. void loop() {
  69. // Listen for any knock at all.
  70. knockSensorValue = analogRead(knockSensor);
  71. if (knockSensorValue >=threshold){
  72. listenToSecretKnock();
  73.   }
  74. }
  75.  
  76. // Records the timing of knocks.
  77. void listenToSecretKnock(){
  78. //Serial.println("knock starting");    // debug.
  79. int i = 0;
  80. // First lets reset the listening array.
  81. for (i=0;i=threshold){   //got another knock…
  82. //record the delay time.
  83. now=millis();
  84. knockReadings[currentKnockNumber] = now-startTime;
  85. currentKnockNumber ++;   //increment the counter
  86. startTime=now;
  87. // and reset our timer for the next knock
  88. digitalWrite(greenLED, LOW);
  89. delay(knockFadeTime);
  90. // again, a little delay to let the knock decay.
  91. digitalWrite(greenLED, HIGH);
  92. }
  93.  
  94. now=millis();
  95.  
  96. //did we timeout or run out of knocks?
  97. } while ((now-startTime < knockComplete) &amp;&amp; (currentKnockNumber < maximumKnocks));
  98.  
  99. //we’ve got our knock recorded, lets see if it’s valid
  100.  
  101. if (validateKnock() == true){
  102. triggerDoorUnlock();
  103. } else {
  104. //Serial.println("Secret knock failed.");
  105. digitalWrite(greenLED, LOW);
  106. // We didn’t unlock, so blink the red LED as visual feedback.
  107.     for (i=0;i<4;i++){
  108.       digitalWrite(redLED, HIGH);
  109.       delay(100);
  110.       digitalWrite(redLED, LOW);
  111.       delay(100);
  112.     }
  113.     digitalWrite(greenLED, HIGH);
  114.   }
  115. }
  116.  
  117. // Runs the motor (or whatever) to unlock the door.
  118. void triggerDoorUnlock(){
  119. //Serial.println("Door unlocked!");
  120. int i=0;
  121.  
  122. // turn the motor on for a bit.
  123. digitalWrite(lockMotor, HIGH);
  124. digitalWrite(greenLED, HIGH);
  125. // And the green LED too.
  126.  
  127. delay (lockTurnTime);   // Wait a bit.
  128.  
  129. digitalWrite(lockMotor, LOW);  // Turn the motor off.
  130.  
  131. // Blink the green LED a few times for more visual feedback.
  132. for (i=0; i < 5; i++){
  133. digitalWrite(greenLED, LOW);
  134. delay(100);
  135. digitalWrite(greenLED, HIGH);
  136. delay(100);
  137.   }
  138.  
  139. }
  140.  
  141. // Sees if our knock matches the secret.
  142. // returns true if it’s a good knock, false if it’s not.
  143. // todo: break it into smaller functions for readability.
  144. boolean validateKnock(){
  145. int i=0;
  146.  
  147. // simplest check first: Did we get the right number of knocks?
  148. int currentKnockCount = 0;
  149. int secretKnockCount = 0;
  150. int maxKnockInterval = 0;
  151. // We use this later to normalize the times.
  152.  
  153. for (i=0;i 0){
  154. currentKnockCount++;
  155.     }
  156. if (secretCode[i] > 0){  //todo: precalculate this.
  157. secretKnockCount++;
  158.     }
  159.  
  160. if (knockReadings[i] > maxKnockInterval){
  161. // collect normalization data while we’re looping.
  162. maxKnockInterval = knockReadings[i];
  163.     }
  164.   }
  165.  
  166. // If we’re recording a new knock, save the info and get out of here.
  167. if (digitalRead(programSwitch)==HIGH){
  168. for (i=0;i< maximumKnocks ; i++){
  169. digitalWrite(greenLED, LOW);
  170. digitalWrite(redLED, LOW); // only turn it on if there’s a delay
  171. if (secretCode[i] > 0){
  172. delay( map(secretCode[i],0, 100, 0, maxKnockInterval));
  173. // Expand the time back out to what it was.  Roughly.
  174. digitalWrite(greenLED, HIGH);
  175. digitalWrite(redLED, HIGH);
  176.         }
  177. delay(50);
  178.       }
  179. return false;
  180. // We don’t unlock the door when we are recording a new knock.
  181.   }
  182.  
  183. if (currentKnockCount != secretKnockCount){
  184. return false;
  185.   }
  186.  
  187. /*  Now we compare the relative intervals of our knocks, not the absolute time between them.
  188. (ie: if you do the same pattern slow or fast it should still open the door.)
  189. This makes it less picky, which while making it less secure can also make it
  190. less of a pain to use if you’re tempo is a little slow or fast.
  191. */
  192. int totaltimeDifferences=0;
  193. int timeDiff=0;
  194. for (i=0;i rejectValue){ // Individual value too far out of whack
  195. return false;
  196.     }
  197. totaltimeDifferences += timeDiff;
  198.   }
  199. // It can also fail if the whole thing is too inaccurate.
  200. if (totaltimeDifferences/secretKnockCount>averageRejectValue){
  201. return false;
  202.   }
  203.  
  204. return true;
  205.  
  206. }
Share/Bookmark


  • Newsletter

    Sign up for the PlanetArduino Newsletter, which delivers the most popular articles via e-mail to your inbox every week. Just fill in the information below and submit.

  • Like Us on Facebook