Go Down

Topic: Whistle and Wag! Fun hack for whistle and find device. (Read 2526 times) previous topic - next topic


Jun 10, 2012, 06:54 pm Last Edit: Jun 10, 2012, 07:24 pm by trendski Reason: 1
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.



Code: [Select]
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

void loop()
int lightLevel = analogRead(lightPin); //Read the
                                       // lightlevel

if (lightLevel > 450)
  wag = 1;

if (wag == 1)

  for (pos = 0; pos < 180 ; pos +=2)


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..

Craig Turner, blog: http://gampageek.blogspot.co.uk/ It helps with my learning if I write things down, esp. for others to follow (constructive comments welcomed to improve)

Go Up