The “Don’t bug me” bug, on mbed

Towards the end of school holidays is always a frustrating time for parents. You back at home from the annual trip away and your kids are bored or at least tell you they are bored constantly every hour on the hour. This would be good if you yourself weren’t actually back to work. With my son and daughter constantly in and out of my office my memory recalled a device that create a Youth Repellent Sound.

Upon further study adults have difficulty hearing above the 16 khz range. and for a frequency of 16khz we need a wavelength of 1/16000 = 6.25 10 to the minus 5. Pulse Width Modulation is basically a square wave so we can us it to generate sound.

To fit in with PWM we need to interpret a period to mark the wave high and the duty cycle to 0.5 to get a symmetrical square wave.

#include “mbed.h”

PwmOut speaker(p21);

int main() {
speaker.period_us(62.5);
speaker = 0.5;
}

Schematic
wpid-youthrepellent_schem-2011-09-11-15-56.png

Breadboard
wpid-youtrepellentbb-2011-09-11-15-56.png

PCB

wpid-youthrepellent_pcb-2011-09-11-15-56.png

Code

This displays an LED on the mbed to confirm that the script is running

#include “mbed.h”

PwmOut speaker(p21);
DigitalOut myled(LED1);

int main() {
speaker.period_us(62.5);
speaker = 0.5;
myled = 0;
while (1) {
myled = !myled;
wait(1);
}
}

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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