Dawn DuPriest
Published © CC BY-NC-SA

Socially-Distant, Voice-Activated Candy Slide for Halloween

A Google AIY Voice Kit, a motor, and 8 feet of PVC pipe become an automated, socially-distant, COVID-safe Halloween candy dispenser!

IntermediateFull instructions provided8 hours639
Socially-Distant, Voice-Activated Candy Slide for Halloween

Things used in this project

Hardware components

DC Motor, 12 V
DC Motor, 12 V
×1
MINI RELAY SPDT 5 PINS 12VDC 10A 120V CONTACT
TaydaElectronics MINI RELAY SPDT 5 PINS 12VDC 10A 120V CONTACT
×1
General Purpose Transistor NPN
General Purpose Transistor NPN
×1
Breadboard (generic)
Breadboard (generic)
×1
SparkFun Breadboard Power Supply 5V/3.3V
SparkFun Breadboard Power Supply 5V/3.3V
×1
Resistor 330 ohm
Resistor 330 ohm
×1
3.6V 0.5W Zener Diode
3.6V 0.5W Zener Diode
×1
Adafruit Neopixel Dot Strand
×1
SparkFun RedBoard
SparkFun RedBoard
×1
AIY Voice
Google AIY Voice
×1

Software apps and online services

Google Cloud Speech API

Hand tools and fabrication machines

3D Printer (generic)
3D Printer (generic)
Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Custom parts and enclosures

Motor Mount

My DC motor has a cross-shaped mount on the end, and this piece slides onto it. I attached that to a wheel that's meant to mount to Lego parts, which might be useful if you want to use a Lego wheel in your design.

Dispenser Wheel

This dispenser wheel is meant to dispense 2-inch capsules. The end mounts onto a stepper motor, but I found a stepper motor is too flimsy for this purpose. You can hot-glue it or super-glue it to the motor mount of your choice.

Schematics

Schematic

The relay circuit that drives the motor for the candy dispenser. Nothing fancy. I used a 5V power supply but you could use whatever is appropriate for your motor.

Code

Python Code for Raspberry Pi

Python
This is the code for the Google AIY Voice Kit that recognizes the phrase "Trick or Treat" or "Tell me a joke" and either dispenses candy or tells you a joke.
Before using this code, you need to get authentication tokens from Google Cloud services, so use the startup guide here https://aiyprojects.withgoogle.com/voice/ to get everything set up.
#!/usr/bin/env python3
# Copyright 2017 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""A demo of the Google CloudSpeech recognizer."""

import aiy.audio
import aiy.cloudspeech
import aiy.voicehat
import aiy.voice.tts
import random
from gpiozero import LED
from time import sleep

in1 = LED(26)
in2 = LED(6)
in3 = LED(13)
in4 = LED(5)


jokelist = ['What does a ghost panda eat?','What kind of music does a mummy like?',
            'What do you get when you cross a vampire and a snowman?', 'What do you call a skeleton when its cleaning up?',
            'What do you call two witches who live together?','How do you fix a cracked pumpkin?','What do birds say on Halloween?']
answerlist = ['Bam Boo','Rap Music','Frost Bite','The Grim Sweeper','Broom Mates','A Pumpkin Patch', 'Trick or Tweet']





def main():

   
    in1.off()
    in2.off()
    in3.off()
    in4.off()
 
    recognizer = aiy.cloudspeech.get_recognizer()
    recognizer.expect_phrase('turn off the light')
    recognizer.expect_phrase('turn on the light')
    recognizer.expect_phrase('blink')
    recognizer.expect_phrase('trick or treat')
    recognizer.expect_phrase('tell me a joke')

    button = aiy.voicehat.get_button()
    led = aiy.voicehat.get_led()
    aiy.audio.get_recorder().start()

    while True:
        #print('Press the button and speak')
        print('speak')
        #button.wait_for_press()
        print('Listening...')
        text = recognizer.recognize()
        turnval = 0
       
   
        if not text:
            print('Sorry, I did not hear you.')
        else:
            print('You said "', text, '"')
            if 'turn on the light' in text:
                led.set_state(aiy.voicehat.LED.ON)
               
               
            elif 'turn off the light' in text:
                led.set_state(aiy.voicehat.LED.OFF)
            elif 'blink' in text:
                led.set_state(aiy.voicehat.LED.BLINK)
            elif 'trick or treat' in text:
               
                in1.on()
             
                sleep(2.3)
                in1.off()
               
                aiy.voice.tts.say("Happy Halloween")
            elif 'tell me a joke' in text:
                j = random.randint(0,len(jokelist)-1)
                aiy.voice.tts.say(jokelist[j])
                sleep(1)
                aiy.voice.tts.say(answerlist[j])
               
            elif 'turn' in text:
                textlist = text.split(' ')
                turnpos = 0
                for st in textlist:
                    if st == 'turn':
                        # the value after "turn" may be number of ms to turn
                        try:
                            turnval = float(textlist[turnpos+1])
                        except:
                            turnval = 0
                            print("Error! no number after turn")
                            next
               
                in1.on()
                sleep(turnval / 1000)
                in1.off()
               
            elif 'goodbye' in text:
                break


if __name__ == '__main__':
    main()

Credits

Dawn DuPriest

Dawn DuPriest

7 projects • 17 followers
I teach math and technology to junior high and high school students at a small project-based school... and I make stuff.

Comments