MakerFaire MakerBar Arduino Candy Box
Last (last-last) minute build for the MakerBar booth at NYC MakerFaire. Swipe for candy, the closer your hand, the angrier the box becomes (vibration) then proceeds to open, revealing an unexpected robot arm (false-bottom) that presents you a with piece of candy. All materials were constructed from MDF by way of CNC.



Notations
1. Limited time did not permit me to complete the build. A reloading system was to be applied to the under side; it was alternatively reloaded by hand as the effect was slow regardless.



Arduino Gibberish
// False Bottom Arduino Candy Box
// Vije Miller

#include "Stepper.h"

// Stepper
const int stepsPerRevolution = 200;
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);

// Stepper Limits
const int topstop = 6;
int topstate = 0;
const int botstop = 5;
int botstate = 0;

// Stepper State
int posstate = 0;

// Sensor Pins
const int trigPin = 4;
const int echoPin = 3;

// Vibration
int motorPin = 12;
int vibration = 0;

void setup() {
// Stepper Speed - Ugh
myStepper.setSpeed(210);

// Stepper Limiters
pinMode(topstop, INPUT);
pinMode(botstop, INPUT);

// Vibration Motor
pinMode(motorPin, OUTPUT);

Serial.begin(9600);
}

void loop() {
// Sensor Polling
long duration;
pinMode(trigPin, OUTPUT);
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
pinMode(echoPin, INPUT);
duration = pulseIn(echoPin, HIGH);
Serial.println(duration);

// Vibration Motor Map
vibration = map(duration, 300, 800, 255, 0);
analogWrite(motorPin, vibration);

// Trigger Candy
if (duration < 300) {
if (posstate == 1) {
up();
}
}
delay(100);
}

// Stepper To Limit
// IF button is LOW then run
// IF button is HIGH then stop
void up() {
while (botstate == LOW) {
botstate = digitalRead(botstop);
myStepper.step(-1);
posstate = 0;
}
// Delay then Return
delay(2000);
down();
}

void down() {
while (topstate == LOW) {
topstate = digitalRead(topstop);
myStepper.step(1);
posstate = 1;
}
}

Archive
https://hackaday.io/project/14983-makerfaire-makerbar-arduino-candy-box

10:54:29 197-016