loading
Eat too many cookies? These are some guidelines for how you can add a few security features to an ordinary box of cookies - or at least have a fun toy.

The runaway cookie box will roll away when objects approach it and sound an alarm when it is picked up.

What you need for the craft side of things:
-empty cookie box
-wheels (4)
-Legos (axles, gears, basic)
-hot glue
-electrical tape
-popsicle sticks, colorful straws, googly eyes, or whatever you want to give your box some character

What you need for the computing side of things:
-Arduino
-hacked servo
-tilt sensor
-distance sensor
-speaker
-resistors (2x100K&, 1x100&) 
-breadboard
-wire
-wire strippers
-soldering iron
-solder

[This project was done for Olin College's Computing & Craft class, taught by Dr. Amon Millner.]

Step 1: The Circuitry

During this step, you'll set up all the circuitry required for the project.

First, connect the Arduino's 5V power and ground pins to the bus strips of the breadboard.

Second, connect the tilt sensor to the breadboard. Connect the wires on one side to the power strip and the wires on the other side to a 100K& resistor going to ground as well as to digital ins on the Arduino (in this case I used 3 and 4).

Third, connect the three distance sensor wires: red to power, black to ground, and yellow to an analog in on the Arduino (in this case, I used A0).

Fourth, connect one of the speaker's wires to ground and the other to a 100& resistor connected to a PWM digital in on the Arduino (in this case, I used 5).

Last, connect one of the hacked servo's wires to ground and the other to another digital in (in this case I used 9).

Step 2: The Box

During this step, you'll construct your moving cookie box monster that will hold all the circuitry from the last step.

For ease in assembling the project, you can cut a rectangular hole on the bottom of each side.

Hot glue the sides of the breadboard to the space just above this hole.

Hot glue the head of your hacked servo directly to a Lego wheel.

Now construct a Lego chassis for the box with a regular front axle and only one wheel connected in the back. One of the rear wheels is, as you may have noticed, currently attached to your servo. Tape down your Arduino and your servo so that the fourth wheel is oriented in the right direction.

Now you can hot glue your distance sensor to the top back of the box so that your box will spy its enemies coming from behind. You can let the speaker simply rest on top of the breadboard.

Last, attach whatever crafty materials you want! As you can see with my project, I gave it popsicle antenna eyes with a colorful straw mohawk.

Step 3: The Code

The last piece of your project is programming the Arduino so that your cookie box behaves the way you want it to.

First, initialize and define all your variables. Here's the code I used:

const int tiltPin1 = 3;
const int tiltPin2 = 4;
const int speakerPin = 5;
const int distancePin = A0;
const int motorPin = 9;

int tiltState1 = 0;
int tiltState2 = 0;

void setup() {
pinMode(speakerPin, OUTPUT);
pinMode(motorPin, OUTPUT);
pinMode(tiltPin1, INPUT);
pinMode(tiltPin2, INPUT);
pinMode(distancePin, INPUT);


Next, define the conditions and all behaviors. Here's how I did it:

void loop(){
  tiltState1 = digitalRead(tiltPin1);
  tiltState2 = digitalRead(tiltPin2);
  int val = analogRead(distancePin);
  if (val > 450) { // if an object is "close"
    digitalWrite(motorPin, HIGH); // turn motor on
  }
  else {
    digitalWrite(motorPin, LOW);}
  if (tiltState1 == HIGH) { // if tilted (case 1)
    tone(speakerPin, 131, 125); // sound alarm
    delay(125);
    noTone(speakerPin);
    delay(125); } 
  else {
    noTone(speakerPin); }
  if (tiltState2 == HIGH) { // if tilted (case 2)
tone(speakerPin, 131, 125); // sound alarm
delay(125);
noTone(speakerPin);
delay(125); }
else {
noTone(speakerPin); }
}     


Step 4: Enjoy!

Once you've plugged your Arduino in and uploaded the code, your cookie box should be good to go!

Some possible directions you may want to take this project in:

-Amplify the signal to the servo in the circuit and use a gear system to move the box faster
-Add a second servo and implement the ability to change direction of the box
-Modify the behavior of the box so that it could be a friendly cookie pet. When it sees an object in the distance, it approaches it - and plays nice music when its owner is kind enough to pick it up!

Here's a video of my cookie box in action!
(http://www.youtube.com/watch?v=BT6FXfrFG1U)

 
Nice work Schmegano! I was wondering where my girl scout cookies went.<br><br>I like how you've introduced one way to make this project and offered suggestions for possible directions others might take. I'd like to offer another possible direction - make your own tilt sensor.<br><br>You crafted your tilt sensor using the colorful straws, a balled up piece of foil, and paper clips (poking two paperclips through each end of the straw so that when the straw is tilted, the foil ball inside lands between the paperclips and completes the switch). Others could try different ways of making a tilt sensor - such as hanging a magnet near a reed switch and making the string swing the magnet away from the switch when tilted.<br><br><br>
Great project, and a nice writeup, too!<br><br>In the last step, you can make the YouTube URL an active hyperlink by using the &quot;Link&quot; icon in the editor (it's the globe with a little chain).<br><br>Also, you should be able to embed the video directly in the step, provided you click the little &quot;Use old embed codes&quot; box and <i>don't</i> check the &quot;enhanced security&quot; box on the YouTube page.
Thanks! I wasn't using the old embed code - but it looks like it's working now!

About This Instructable

1,218views

2favorites

License:

More by schmegano:How to make a runaway cookie box 
Add instructable to: