Whistle and Wag! Fun hack for whistle and find device.

These devices have a small led that flashes and a beep when you whistle. I had one left over knocking about the house, so I wanted to find a use for it. They are about 3 x 3 x 1.5 cm and run off a couple of button cells. You don't need to use the plastic whistle to work it, you can use purse your lips and do it yourself - needs to be loud though.

I hooked one up to flash onto an LDR so when you whistle a signal goes via analogue pin to start a servo and wag a piece of wire. Easy way to add an interactive
wagging tail to your robot! The LED is placed right next to the LDR and the whole lot is shaded from ambient light.

Video:

Code:

Servo myservo;
int wag = 0;
int pos;
//PhotoResistor Pin
int lightPin = 0; 

int servopin = 7;   //the pin the servo is connected to
                  
void setup()
{
  pinMode(servopin, OUTPUT); //sets the servo pin to output
  digitalWrite(servopin, LOW);  //servo OFF
  myservo.attach(7);
  myservo.write(90);
  Serial.begin(9600);
}
 
void loop()
{
 int lightLevel = analogRead(lightPin); //Read the
                                        // lightlevel

if (lightLevel > 450)
 {
   wag = 1;
 }
 
 if (wag == 1)
 
 {
   
   for (pos = 0; pos < 180 ; pos +=2)
   {
   
  
   myservo.write(pos);
  
  Serial.println(lightLevel);
   }
   
 }
 
 

}

I put in serial for debugging. You need to play around with what light level you need to trigger the wagging. Also your LDR may vary from mine. See video.

Would welcome some feedback for improvements, additional actions etc..

Cheers