Introduction: Donut Security System

As humanity has evolved, so has the fight between good and evil. Evil will always try to take from us what we find most valuable. Good must find increasingly ingenious ways to protect that which is rightfully ours. It is only natural, then, that an advanced donut security system be created to protect our circular and besprinkled treasures.

Within this state-of-the-art security system, pressure sensors detect the weight of a donut on a plate. If the donut is stolen, lights and sounds warn the criminal to STOP. The perpetrator will be so surprised at the swift reaction of the machine, they will be forced to replace the donut and leave.

While originally designed for donuts (the world's premier dessert), the code could easily be calibrated to accommodate a cupcake, slice of pie, etc.

Step 1: Supplies

Hardware - Components & Connectors

  • USB Power Source for Arduino x1
  • Arduino Uno x1
  • Breadboard x1
  • Piezo Element x1
  • Pressure Sensor x1
  • Red 5mm LED x1
  • Green 5mm LED x1
  • Wires x14 (3 - 5 inches each)
    • This includes the wires used to lengthen the pressure sensor and LEDs
  • 560 Ohm Resistor x2 (Green-Blue-Brown)
  • 10 k Ohm Resistor x1 (Brown-Black-Orange)
  • Arduino Power Cord for 9V Battery
  • 9V Battery

Hardware - Tools

  • Soldering Iron or Copper Wire Tape
  • Wire Cutters
  • Scissors or Exacto Knife
  • Computer (to load the code)

Software

  • Arduino IDE

Other Supplies

  • Small Paper Plate x2
  • Glad Tupperware Container and Lid x1 (large enough to hold Arduino and breadboard)
  • Tape (to hold the pieces in place)
  • Donut x1 (or more)
  • Decorations (optional)

Step 2: Construction - Phase One

1. Lengthen the wires on the pressure sensor and two LEDs. To do this, you can use a soldering iron or wire tape. The finished components should be about 8 to 10 inches long.

2. Complete the breadboard/Arduino as shown in the image.

Step 3: The Code

int speakerPin = 9;
int sensePin = A4;
int ledPin1 = 13; //Green LED Pin
int ledPin2 = 12; //Red LED Pin
int length = 15;
char notes[] = "a  aaagg gfeedd";
float beats[] = {1, 1, 1, .5, .5, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, };<br>int tempo = 300;

void playTone(int tone, int duration) {
	for (long i = 0; i < duration *1000L; i += tone * 2){
		digitalWrite(speakerPin, HIGH);
		delayMicroseconds(tone);
		digitalWrite(speakerPin, LOW);
		delayMicroseconds(tone);
	}
}

void playNote(char note, int duration) {
	char names[] = {'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C'};
	float tones[] = {1915, 1700, 1519, 1432, 1275, 1136, 1014, 956};
	
	for (int i = 0; i < 8; i++) {
		if (names[i] == note) {
			playTone(tones[i], duration);
		}
	}
}

void setup() {
	Serial.begin(9600);
	pinMode(speakerPin, OUTPUT);
	pinMode(ledPin1, OUTPUT);
	pinMode(ledPin2, OUTPUT);
}

void playSong() {
	for(int i = 0; i < length; i++) {
		if(notes[i] == ' ') {
			delay(beats[i] * tempo);
		} else {
			playNote(notes[i], beats[i] * tempo);
		}
		delay(tempo / 2);
	}
}

void loop() {
	int value = analogRead(A4);
	Serial.println(value);
	if (value >= 500) { //This threshold can be changed for different weights
		digitalWrite(ledPin1, HIGH);
		digitalWrite(ledPin2, LOW);
	} else {
		digitalWrite(ledPin1, LOW);
		digitalWrite(ledPin2, HIGH);
		playSong();
	}
}

Step 4: Construction - Phase Two

1. Upload the code into your Arduino and test it by squeezing the pressure sensor with your fingers.

2. Cut a hole in one paper plate and slip the pressure sensor through it.

3. With the Arduino still attached to your computer, place the other paper plate on top of the sensor. Put your donut on the plate and check the reading. This reading should be reflected in your code to set the threshold for your sensor. (Hint: If you are having trouble getting any reading from the donut, you have two options. First, buy a bigger donut or second, tape something small on top of the sensor to increase the pressure. I used a bead).

4. Once you have your threshold set, make sure the new code is uploaded and attach the 9V battery.

5. Cut two holes through both plates to thread the LEDs through.

6. Place the entire set-up in the tupperware container.

7. Cut holes in the lid to let the pressure sensor and LEDs through.

8. Place the plates on top of the lid and the donut on top of the plates.

Step 5: Enjoy!