Description:
I wired up a ceramic bird-shaped soy sauce holder to tweet when his head is opened and to light up the ping pong ball attached to his beak when pushed down. The bird rests on a sponge that is on top of an FSR that is connected to an LED in the ping pong ball; when the bird is pushed down onto the sponge, the ping pong ball lights up. Inside the bird is a photocell, and when the top is removed and the photocell receives light, the piezo buzzer inside the bird repeats a short bird-call-esque melody until the top is replaced.
Components:
LED
FSR
Photocell
Piezo buzzer
Ceramic bird soy sauce container
Ping pong ball
Flower-shaped sponge
Styrofoam tray
Arduino Code:
/*Bird Tweeter
//This program makes an LED light up when an FSR is pressed and
//causes a quick melody to play (imitating birdsong) when a photocell is exposed
//to light.
*/
int photPin = 2; // photocell attached to A2
int photVal = 0; // initial value of photocell output set to zero
int fsrPin = 1; // FSR attached to A1
int fsrVal = 0; //initial value of FSR output set to zero
int speakerPin = 10; // piezo buzzer connected to pin 10
int ledPin = 11; // LED attached to pin 11
void setup() {
pinMode(speakerPin, OUTPUT);
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
fsrVal = analogRead(fsrPin); // read value from FSR, between 0 - 1024
Serial.println (fsrVal);
analogWrite(ledPin, fsrVal/4); //convert from 0-1024 scale to 0-255, write to LED
photVal = analogRead(photPin);
Serial.println (photVal);
if(photVal>30)
{
tone (speakerPin, 2794,25);
delay (25);
tone (speakerPin, 3136, 25);
delay (25);
tone (speakerPin, 4435, 25);
delay (100);
tone (speakerPin, 3322,25);
delay (25);
tone (speakerPin, 3136, 25);
delay (25);
tone (speakerPin, 2637, 25);
delay (100);
tone (speakerPin, 2794,25);
delay (25);
tone (speakerPin, 3136, 25);
delay (25);
tone (speakerPin, 4435, 25);
delay (2000);
}
else
{
noTone(speakerPin);
}
}