3 Simple Ways to
Share What You Make

With Instructables you can share what you make with the world — and tap into an ever-growing community of creative experts.

PhotosPhotos

Share one or more photos of a project, recipe, or whatever you've made, quickly and easily.

Step by StepStep-By-Step

Share your step-by-step photos with text instructions of what you made so others can do it too!

VideoVideo

Share your how-to video. You'll need your embed code from a video site such as YouTube.

Play the French Can Can Using an Arduino and Buzzer

Step 5Create Starting Sketch

Create Starting Sketch
To answer the question, "How do I make the buzzer make noise?", I did a Google Search for [CEM-1203 arduino make noise]. Near the top there was a blog link labeled Buzzer Arduino Example Code written by Ron Faludi. Ron shared his code here (Thanks Ron! You're awesome!). 

Copy between the lines:

----------------copy after this line----------------

// Buzzer example function for the CEM-1203 buzzer (Sparkfun's part #COM-07950).
// by Rob Faludi
// http://www.faludi.com

void setup() {
  pinMode(4, OUTPUT); // set a pin for buzzer output
}

void loop() {
  buzz(4, 2500, 500); // buzz the buzzer on pin 4 at 2500Hz for 1000 milliseconds
  delay(1000); // wait a bit between buzzes
}

void buzz(int targetPin, long frequency, long length) {
  long delayValue = 1000000/frequency/2; // calculate the delay value between transitions
  //// 1 second's worth of microseconds, divided by the frequency, then split in half since
  //// there are two phases to each cycle
  long numCycles = frequency * length/ 1000; // calculate the number of cycles for proper timing
  //// multiply frequency, which is really cycles per second, by the number of seconds to
  //// get the total number of cycles to produce
 for (long i=0; i < numCycles; i++){ // for the calculated length of time...
    digitalWrite(targetPin,HIGH); // write the buzzer pin high to push out the diaphram
    delayMicroseconds(delayValue); // wait for the calculated delay value
    digitalWrite(targetPin,LOW); // write the buzzer pin low to pull back the diaphram
    delayMicroseconds(delayValue); // wait againf or the calculated delay value
  }
}

----------------copy before this line----------------

Copy and paste this code into the Arduino IDE, and save the sketch as some descriptive name like 'buzzerExample'. Descriptive names will help in the future once you have many files in one place to sort through.
« Previous StepDownload PDFView All StepsNext Step »
1 comment
Nov 27, 2011. 2:15 AMmichielrutjes says:
The guy's name is "Rob", not "Ron" Faludi ;) Excellent instructable!

Pro

Get More Out of Instructables

Already have an Account?

close

All Steps Viewing
View all steps of an Instructable on the same page when you're a Pro Member.

Upgrade to Pro today!
2
Followers
1
Author:Ultrus(Christopher Stevens)
Web developer and designer who loves renovating and empowering over-sized web projects. Experience in developing and integrating ground breaking creative solutions online. Enjoys solving complex devel...
more »