Who's at the door
Hans and Matilda were fast asleep when they heard a knock at the door. He put on a robe and wandered over to the door. "Who is it", he asked, "The postman" replied the stranger. Hans peered through the spyhole and saw the cap of the postman. Why is the postman visiting in the middle of the night thought Hans? He looked again, below the cap he saw a large pair of eyes, above the cap he saw a large pair of hairy ears and through the darkness he saw a large set of sharp teeth. It was the Wolf!
He checked the door was securely bolted and headed back to bed. Before he'd even made it to the bedroom there was another knock at the door so he headed back. Peering out of the door this time he saw a bowler hat. "Who is it?" he asked. "It's the Doctor" the hat replied. Hans looked through the hole again. Underneath the hat were two large eyes, a large nose and a large set of teeth. Hans backed away from the door, when there was yet another knock. "Who is he asked", "It's the UPS guy with your Element14 delivery", was the reply. Hans was overjoyed and was just about to open the door when he decided to look through the spyhole again. Again a hatted figure stood outside, and again the figure had large fury ears, large eyes and very large and pointy teeth. Hans went back to bed. That night there was a range of visitors to his door claiming to be the milkman, the window cleaner and finally granny. After that Hans stopped answering the knocks at the door and tried to get to sleep.
Knock Knock
In the morning Hans had a couple of thoughts, the first was he wanted to upgrade his security and the other was that it might be quite good for the system to check the weather automatically in response to people knocking on the door.
Hans realised that there was a buzzer in the Arduino kit and looked into taking that apart to use as a sensor. It did not want to open up easily so he invested in some new sensors, some simple piezo transducers.
A bit of googling found a suitable circuit for conditioning the sensor signal. The piezo transducer is effectively a voltage source, when the crystal deforms a small voltage is produced. If we put that into a comparator then we can create a strong 0v - 5v swing to indicate the knock. This should be sufficient to wake the Arduino from sleep. A large resistor allows that voltage to discharge and zener diodes stop the inputs being overloaded.
From Thoughts on interfacing piezo vibration sensor - Do It Easy With ScienceProg
Looking in the spares cupboard there were a bunch of 741 opamps that could be used for the comparator but checking the spec he realised that they were not designed to work from a 5v supply, and there were also comments that the output swing was less than the rails so some LM393 comparators were also ordered.
Excuse me for interrupting
Whilst he was waiting for those he did some tests with the interrupts. Reading the Arduino site he learn that only certain pins could be configured as an external interrupt. Looking at the pin out diagram, all of there are taken by the bridge to the Linino module or the I2C bus.
from http://www.pighixxx.com/test/pinoutspg/boards/
Hans saw a cryptic comment in the Arduino documentation that some of the Atmel chips supported change interrupts on many more pins. But there was no specific reference to the Yún or the ATMega32u4 and no details on how to how to attach the interrupt handler code to the pin. Luckily Matt Walkers article on Pin Change Interupts explained how it all worked and a bit of further digging found Mike Schwager's library that wraps up all the AVR specific commands in a friendly way.
Hans tested this firstly in a simple example.
#include "EnableInterrupt.h" int led = 13; int myint = 11; volatile int state = LOW; void setup() { pinMode(led, OUTPUT); enableInterrupt(myint, blink, CHANGE); } void loop() { digitalWrite(led, state); } void blink() { state = !state; }
Then in a power down scenario.
#include "EnableInterrupt.h" #include "LowPower.h" int led = 13; int myint = 11; volatile int state = LOW; void setup() { pinMode(led, OUTPUT); pinMode(myint, INPUT); enableInterrupt(myint, blink, CHANGE); delay(25000); //Time to reprogramme! } void loop() { digitalWrite(led, state); LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF); } void blink() { state = !state; }
Code at: https://github.com/Workshopshed/EnchantedObjects/tree/master/Code
These tests proved successful so Hans was happy to make up the circuit once the parts arrived.
Next: Enchanted Objects Design Challenge - Knock Knock
Reference
http://www.scienceprog.com/thoughts-on-interfacing-piezo-vibration-sensor/
http://www.ti.com/product/lm393
https://github.com/GreyGnome/EnableInterrupt
Arduino - Interrupts
Gammon Forum : Electronics : Microprocessors : Interrupts
Geert's pages - Pin-change interrupts on Arduino
Top Comments