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.

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

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://
cd wiringPi

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
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 :)



  • Indoor Lighting Contest

    Indoor Lighting Contest
  • Make It Fly Challenge

    Make It Fly Challenge
  • Growing Beyond Earth Maker Contest

    Growing Beyond Earth Maker Contest

3 Discussions


1 year ago

.Quick question how would I
be able to stop all audio from playing from the buzzer? I've got the project in
an odd condition when I run the steps you provided it plays fine but even
killing the PID sometimes leaves the buzzer stuck on that last note

1 reply

Reply 1 year ago

Hi, thanks for the feedback. Sorry about the issue that you are experiencing. Probably a fix is needed to set the state of the GPIO to which is connected the buzzer to zero. Best regards, Leon


1 year ago

I did almost the same steps.

sudo apt-get update

sudo apt-get install git

git clone git://

cd wiringPi

sudo apt-get install make

sudo apt-get install gcc

sudo apt-get install libc6-dev


git clone

cd rpi-examples/

cd buzzer/c/

gcc starwars.c -o starwars -lwiringPi -std=c99