Raspberry Pi plus add ons.

Beep a PC Speaker Add Beeper to Raspberry Pi

by Lewis Loflin

Beeping the speaker on a Linux PC is simple. Open a text editor and copy the following code. Assuming one has sudo permissions with a password and in a recent Debian desktop save the file as beep.sh in /home/whoever/bin.

# beep the speaker
# has to have sudo without password set.
sudo sh -c "echo -e '\a' > /dev/console"

Open terminal in bin set to executable:

sudo chmod + x beep.sh

Type beep.sh and speaker will beep.

5V buzzer.

Raspberry Pi

The Raspberry Pi no buzzer or speaker. I added one as shown above. This involved compiling a small program using WiringPi.

Place compile binary in /home/pi/bin. open terminal:

~ $ sudo chmod +x beep
#include <wiringPi.h>
#include <stdlib.h>
#include <stdio.h>

#define beepPin 18

int main()   {

	if (wiringPiSetup() == -1)
	// Use Broadcom pin numbers
	// 1 is OUTPUT; 0 is INPUT
	pinMode(beepPin, 1); 
	digitalWrite(beepPin, 1); // on
	digitalWrite(beepPin, 0); // off 

return 0;