Change the Pitch

by littleBits

Published on May 15, 2014

Use an analog input to generate a pitch on your speaker. This will produce an effect similar to that of an oscillator.

*To complete this exercise, you will need to download the Arduino software.

In this sketch, the Arduino "reads" the voltage of the analog input (between 0v and 5v), and then assigns a corresponding value from 0 - 1023, where 0v has a value of 0 and 5v has a value of 1023. The pitch of the speaker output will change between depending on the input value. You can experiment by changing the range of the pitch (Hz).

For more “getting started” sketches, click here.

For support check out the littleBits and Arduino forums.

To learn more about coding, find examples on Arduino’s website.

How To Make It


Download the Arduino software to your computer (it's free!) and open the "Change The Pitch" sketch. The "Change The Pitch" sketch can be found on this page in the "other files" section.


Build your circuit (see the photo gallery for an image of the setup). Make sure the dimmer is connected to the A1 input pin and the button is connected to the D9 output pin.


Plug the micro USB cable into both the Arduino module and a USB port on your computer.


Turn your power module on. You should see a red light illuminate on the power module and a yellow light flash on your Arduino module.


In the Arduino program, select your board. Go to Tools>Board>Arduino Leonardo. This littleBits Arduino module is modeled after the Arduino Leonardo and is therefore compatible.


Next select the serial port that the Arduino will communicate over by going back to "Tools" and selecting the correct port in the "Port" section. The name of the port will depend if you are on a Mac or Windows computer. On a Mac, it will start with /dev/tty.usbmodem... and a PC will start with COMM… In Windows, you can look for the USB serial device in the ports section of the Windows Device Manager. If you are on a Linux machine, the port will look like /dev/ttyUSB…


To upload the Arduino sketch to your Arduino module, press the arrow button in the top left corner of the screen. You will see a blue bar at the bottom of the window that says "compiling sketch", and you should see two yellow lights flash on your Arduino module when this happens. The upload is complete when you see "done uploading" at the bottom of your sketch window.


Once the program is uploaded, press the button. You will hear a tone coming from the speaker. Then, adjust the dimmer to change the pitch.


Try changing the output range (Hz) in the code and see what happens.

Related Projects

Play your theme song music whenever you walk into the room

This is a motion triggered MP3 player that will play music when you walk into the room. I loaded the scene transition mu...

Improved Doorbell (1.0)

Improved Doorbell by smallBits Short Description: This is the improved edition of the oringinal doorbell. It is also working with ...

Holiday Doorbell

My 8 year old daughter and I used the littleBits basic kit and created a cute holiday doorbell. We picked up a money holder box at...