It is hard to end this blog; I keep thinking of new things to do…(maybe that is why I am ‘Sir Blog-a-Lot’!) We may not have time in class for these; but you can do these at home or if you finish early.

Piezoelectric Effect

The piezoelectric effect is found in certain ceramics and crystals. When a mechanical force squeezes the piezoelectric material a voltage is generated (like in the igniter for a gas barbecue). The reverse also works; when a voltage is applied the piezoelectric crystal structure warps. If the electric current is alternating the material vibrates as in a buzzer or speaker application.

Soldering Wires to Piezo Element

Too much heat can damage a piezo element; so follow these instructions carefully. Pre-tin the wires with solder (sacrifice a black and a red wire jumper from your kit; cut off one end and strip off a quarter-inch of insulation). Add 2 drops of wire to the element; one on the rim and the other near by on the white center. Place the tinned wires to the element and reflow quickly.

Piezo Heartbeat Monitor

Wire the circuit below:

Copy and paste the code in your Arduino IDE:

``````
int threshold = 60;
int oldvalue = 0;
int newvalue = 0;
unsigned long oldmillis = 0;
unsigned long newmillis = 0;
int cnt = 0;
int timings[16];

void setup() {
Serial.begin(57600);
}

void loop() {
oldvalue = newvalue;
newvalue = 0;
for(int i=0; i<64; i++){ // Average over 16 measurements
}
newvalue = newvalue/64;
// find triggering edge
if(oldvalue=threshold){
oldmillis = newmillis;
newmillis = millis();
// fill in the current time difference in ringbuffer
timings[cnt%16]= (int)(newmillis-oldmillis);
int totalmillis = 0;
// calculate average of the last 16 time differences
for(int i=0;i<16;i++){
totalmillis += timings[i];
}
// calculate heart rate
int heartrate = 60000/(totalmillis/16);
Serial.println(heartrate,DEC);
cnt++;
}
delay(5);
}
``````

Tape the piezo sensor to your finger tip and run the code. Open the serial monitor (make sure to change the baud rate to 57600). Keep you finger still and try to let the wires relax (i.e. not taunt or they will show every vibration as junk data).

Optical Theremin

Old science fiction movies loved the eerie and ghostly sounds an odd instrument called the Theremin made. The original used the body capacitance of the musician to interact with radio energy between 2 antennas. The version we have below uses light and a CDS cell (light sensor).

Copy and paste the code in your Arduino IDE:

``````
/* Theremin
* --------
*
*
* Created 24 October 2006
* copyleft 2006 Tod E. Kurt <tod@todbot.com
* http://todbot.com/
*/

int potPin = 0;    // select the input pin for the potentiometer
int speakerPin = 7;

int val = 0;

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

void loop() {
digitalWrite(speakerPin, LOW);

val = val*2;                 // process the value a little
//val = val/2;                 // process the value a little

for( int i=0; i<50; i++ ) {  // play it for 50 cycles
digitalWrite(speakerPin, HIGH);
delayMicroseconds(val);
digitalWrite(speakerPin, LOW);
delayMicroseconds(val);
}
}

``````