Introduction: Candy Counting Robot Costume With the Raspberry Pi

In this project, we took the tried-and-true robot costume and gave it some life with the Raspberry Pi, GrovePi, and a handful of Grove sensors. The costume is a standard robot costume, but with a candy-counting machine attached that talks!

When a piece of candy is placed in the robot, it flashes its LEDs, thanks the candy donor for the piece of candy, and announces the candy count. We use the Raspberry Pi for brains, the GrovePi and assorted sensors to detect candy, and a battery powered speaker to do the talking. The whole project takes about 2 hours to build.

Components

We’ll need a few electronic and non-electronic components for the project:

You should be able to use cardboard boxes from around the home. The size of these are going to vary depending on your child’s size, and your expected candy haul.

Step 1: The Build

We started by wrapping the small box and the large box with the silver duct tape. Originally we were planning on using silver spray paint, but decided that the fumes might be bad for our 2-year old. The tape worked well and gave it a bit of a rough look.

Next in the small box, we cut a small flap in the top, about 4″ x 4″ for the candy chute. We bent this into the box, and taped it to the bottom of the box at an angle. This provides a protective area to keep the candy from dropping in on the electronics.

Make some holes.

Next, we made some holes. First, we poked 4 small holes along the bottom for the chainable LEDs. We secured them to the box with some thin wire we had laying around.

We made another hole, big enough for the RGB LED screen to fit through. We secured the RGB LED screen with some clear packing tape on the back of the display, holding it in place. We made a similar hole for the bar-graph LED display, below it.

Finally, we added the Ultrasonic Sensor. This will be our candy detection sensor: as a hand with candy in it goes towards the candy chute, it triggers the Ultrasonic sensor. We mounted this at a slight 45 degree angle and wrapped it in silver duct tape to make sure it didn’t move around and trigger false alarms. We will mount the Pi and GrovePi in the small box with more clear packing tape. We built a small cradle for the bundle on the side, below the candy chute.

We also made a slot for the USB Battery charger at the bottom. This needs to be securely held in place: it’s the heaviest item and if it breaks loose, combined with the kinetic energy of your 2 year old, it will do some damage.

Step 2: Set Up the Sensors and the Raspberry Pi

With all the sensors mounted to the small box, we can begin set up the Pi. You’ll need to place the SD Card in the Raspberry Pi, attach the GrovePi and place both in the GrovePi Case. We have instructions on this here!

Connecting the sensors:

  • The LED Bar Graph connects to Port D5
  • The Ultrasonic Ranger Sensor connects to Port D4
  • The Chainable LEDs connect to D7
  • The RGB LCD Display connects to any of the I2C Sensor Ports.
  • Connect the Raspberry Pi Speaker to the Raspberry Pi Aux Jack.

Initially, we’ll set up the Pi with Ethernet so we can do some set up, but we’ll eventually use the Dexter Industries Wifi Dongle to make the costume a wifi access point. For now, connect both the ethernet cable and the WiFi dongle to the Pi.

With the sensors in place, we can now strap the Pi into the box and tape her in there!

Step 3: Set Up the Code

Next, we’ll login to the Pi and do some set up. The code is up on Github and available here. You’ll want to update Raspbian for Robots. You can find a video on how to do this here. This will guarantee you have the python code in the GrovePi Github repository for this project.

First, let’s make sure the volume is up and running on the Raspberry Pi. In the command line run:

aplay /usr/share/sounds/alsa/* 

If you are able to hear the sounds, move to the next step! If not, this tutorial may help you set up the audio: Increase the volume to 100%.

Next, install espeak. Run the following in terminal:

sudo apt-get install espeak -y

After it is successfully installed, run the following command. (disregard error messages on the terminal if you can hear sound):

espeak “hello”

If you are able to hear “hello” from the headphones or the speakers then move to the next step!

Our final step is to set up the python program to auto-run at boot. We’ll be using rc.local, and there is some background on this here. In the command line, open up the file rc.local:

sudo nano /etc/rc.local

In the file, add in the line:

python /home/pi/Desktop/GrovePi/Projects/Candy-Counting-Robot-Costume/robot.py &

This should go into the file ABOVE the final exit command, and below any other commands.

Optional: Customize the Wifi Access Point.

As we mentioned above, the robot costume is going to have its own wifi access point. We do this through Cinch, a version of Raspbian For Robots, which automatically opens up a WiFi access point. This can be handy for debugging or restarting the costume on the fly with a phone or laptop (not that you want to haul one around while trick-or-treating, but hey . . . maybe you’re that person!). It can also be a cute party trick: “She’s also a wifi access point!”

You can customize the pages served up by the Raspberry Pi access point by rewriting the HTML files in the directory

/var/www/html 

And add in any extra pictures or code you want to run. When someone logs into the wifi access point “dex” they’ll see this web page at the address “10.10.10.10”

Step 4: The Robot in Action

With the rc.local file modified, the robot should boot right up. Be sure to give it a few test runs. The code is super-stable (I ran it for a day or so in my office to test before releasing it in the real world!).

Remove the ethernet cable and the Raspberry Pi Power supply, and plug this baby into your USB Power Battery and go get some candy! Close up the small box, and mount it to the big box, slap it on your child and go!

Step 5: Further Improvements

As with any project, you always think of improvements on the backside.

I really wanted to add the Grove IR sensor and a remote control, so I can have the robot say messages out loud to either my kid or the the candy donor. I was also hoping to add a “reboot” button this way so I could remotely reboot the Pi if anything got stuck (it didn’t, but that’s easier than taking the costume apart to reset the Pi. I also thought about adding a temperature sensor to the inside of the costume. We live in Dubai and it gets hot; it would be fun to maybe blast out the temperature once in a while.

More Questions?

Learn more about our projects here

Questions? Refer to our tutorial here

Comments

About This Instructable

382views

4favorites

License:

More by dexter_industries:BrickPi3 BalanceBot – A Segway With the Raspberry PiDo You Want to Build a Snowman?Raspberry Pi Servo Flag Waver
Add instructable to: