Introduction: Playing the Imperial March From Star Wars on Raspberry Pi With Piezo Buzzer

About: Software engineer and open source enthusiast

Let's make some noise with Raspberry Pi and a piezo buzzer! This tutorial provides step by step instructions how to play the Imperial march, also known as the Dart Vader's theme, from Star Wars on your Raspberry Pi. Of course this version is not as good as the masterpiece of John Williams. The advantage of this version is that it is open source.

If the embedded video does not appear on your mobile device, here is an alternative link. If you like this tutorial, please subscribe to my YouTube channel and have a look at my Instructables and videos.

Step 1: Getting Ready

For this tutorial you need the following hardware components:

  • Raspberry Pi (any model or version)
  • Breadboard
  • Piezo Buzzer
  • Male to female jumper wires (x2)
  • microSD card with Raspian GNU/Linux distribution
  • Power supply

Step 2: Wiring

The wiring is very simple. It takes less than a minute. One of the wires connects pin 11 of Raspberry Pi to the buzzer. The other wire connects the buzzer to ground. Raspberry Pi offers several pins for ground connections. In this case I am using pin 14.

Step 3: Installing WiringPi

WiringPi is a GPIO access library for Raspberry Pi written in the C programming language. Open a terminal on your Raspberry Pi or login via SSH. Execute the following commands to download and install WiringPi:

git clone git://git.drogon.net/wiringPi
cd wiringPi
./build

Step 4: Installing the Examples

Execute the following commands on your Raspberry Pi to download the open source examples and to build them:

git clone https://github.com/leon-anavi/rpi-examples.git
cd rpi-examples
cd buzzer/c/
gcc starwars.c -o starwars -lwiringPi -std=c99

Step 5: Playing the Imperial March

Type in the following command to run the binary which you have built on the previous step:

sudo ./starwars

If everything is OK you will hear the Imperial March (aka Dart Vader's theme) from the piezo buzzer.

Enjoy :)