Patrick Jackson
Published

Internet-enabled Candy Dispenser

Create an automatic candy dispenser using a 3D-printed auger, a servo, some PVC fittings - controlled from a web page over Wi-Fi.

IntermediateFull instructions provided5,907
Internet-enabled Candy Dispenser

Things used in this project

Hardware components

Esquilo Air
Esquilo Air
×1
Continuous rotation servo
×1
Hammond Arduino Enclosure
×1
Clear PVC 1 1/2" Tee Joint
×1
Clear PVC 1 1/2" Pipe
×1

Story

Read more

Code

Candy Dispenser Servo Control Squirrel Code

C/C++
Servo control code to dispense candy. It uses the Esquilo servo library to rotate the auger backward for 400ms and then forward for 900ms every time a dispense is requested. Dispense requests can be made over HTTP or with an attached button.
// Import the Esquilo servo library
dofile("sd:/motors/servo/servo.nut");

// Auger servo is on PWM1 channel 0 (pin 6 on Esquilo)
pwm   <- PWM(1);
servo <- Servo(pwm, 0);

// Turn the auger backward
function turnBackward(milliSeconds) {
    servo.position(90);
    delay(milliSeconds);
    servo.off();
}

// Turn the auger forward
function turnForward(milliSeconds) {
    servo.position(0);
    delay(milliSeconds);
    servo.off();
}

// How long to turn the auger for a dispense
BACKWARD_MS <- 400;
FORWARD_MS  <- 500;

// Dispense
function dispense() {
    turnBackward(BACKWARD_MS);
    turnForward(BACKWARD_MS + FORWARD_MS);
}

// Button to dispense
cableButton <- GPIO(13);
cableButton.input();
cableButton.pullup(true);

while (true) {
    // Dispense if the button is pressed
    if (cableButton.islow())
        dispense();

    delay(200);
}

JavaScript code to trigger a dispense

JavaScript
This code uses Esquilo RPC to request a serving of candy.
erpc('dispense');

Credits

Patrick Jackson

Patrick Jackson

3 projects • 6 followers
Thanks to Aaron Tunell.

Comments