Cheap whistle sensor as an input device

Posted: December 8, 2009 in Uncategorized

Here’s my implementation of a cheap whistle sensor as input device for a microcontroller.

I build it a little time ago, because i have a light-switch in my room and it switches by pulling a cord. For me the whole project was to switch the light when I whistle. The implementation of the whole concept was quite clear, I would use a servo to pull the cord, a microcontroller to drive the servo and a “sensor” to detect the whistle. To make it easy and cheap I find it to complicated to make the microcontroller check the output of a microphone and implement the signal  so i used a really handy and cheap sensor.

The sensor:

The keychain sensor

The sensor is really cheap, like 1,- euro, it’s an so called “keychain finder” that is activated by the user that give’s a whistle. The sensor in it notice the whistle and give’s back a beeping sound and a flashing LED. To detect if the keychain sensor detects something I used the LED that gets a pulse signal from the microcontroller that is inside the keychain sensor. I removed the led and used the + where the LED supposed to be, to use it as an digital input to my microcontroller. For this project I used a AVR ATtiny 2313 to control a servo and read the output of the sensor. I programmed the microcontroller in Bascom AVR, so I could not use a ATtiny 13 because it can not be programmed to drive a servo, otherwise I could have used the Analog input from the microcontroller, and connect a microfone to it, but I used another sensor so I overcome that problem.

When the sensor detects the whistle sound, it generates a pulse signal which get’s to the input of the microcontroller,the pulse takes about a second or 2 which is not usefull, because the microcontoller should wait the whole time and can not detect read the input. Also the keychain sensor makes noise and you don’t want that, at least I don’t. So i used a transitor to control the powerline of the keychain sensor, and power the sensor off if it has given  the microcontroller an signal. About 20ms it put’s  the sensor back on. The keychain sensor is powered by the same battery-pack of the microcontroller, there is a LED between the battery-pack of 5 volts and the sensor (that works on 3 volts) to drop the voltage a bit. Here’s the schematic of the whole design:

The schematic

And here some other pictures and a little video of the working design:

Close-up of the PCB

And the Bascom AVR sourcecode:

$regfile = "Attiny2313.dat"
$crystal = 4000000
$baud = 9600
Config Portb = &B11111011 : Portb = 00000000
Config Portd = &B11000000 : Portb = 00000000
Config Servos = 1 , Servo1 = Portb.0 , Reload = 1
Enable Interrupts
Dim Pinb.2 As Bit


Servo(1) = 36
Waitms 4


‘9 is right
’38-9=29/2 = 14,5 + 9 = 23 or 24
’38 is left


Portb.6 = 1

If Pinb.2 = 1 Then
Portb.6 = 0
Servo(1) = 20
Waitms 20
Portb.6 = 1
End If

Servo(1) = 38



  1. Vadim says:

    That is very nice implementation! You have saved me lots of time and effort, as I’m working on a project requiring a whistle detector circuit. Thanks!🙂

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s