Halloween candy vending machine
Halloween Machine
A Halloween vending machine frightens visitors, but the braver ones receive a chocolate reward.
With a project as complex as a Halloween vending machine, you need to take everything step by step; otherwise, you quickly get confused. To begin, you must clarify what purpose the vending machine serves. The young visitors are supposed to start it themselves; it then performs a scary show and hands out a piece of chocolate. The show includes sound and light effects – which doesn't sound too complicated – at first.
Chassis
A stable wooden beam forms the basis of the machine. All of the components can be attached to it easily. The temptation to use warped beams just because they are available and cost almost nothing will probably cause more trouble than spending money on good material. The specific machine from this example has a height of around 190cm (~6ft) with a footprint of 60x60cm (~2x2ft). However, no precise size and material specifications are made at this point, just a few tips.
Above all, you need to make sure that the body does not easily tilt or tip over. For this purpose, it is useful to add weights to the base (e.g., heavy stones). Wheels to roll the machine are useful, too. If you construct the vending machine in your garage or basement, test beforehand whether it will fit through the doors that deliver it to its final destination. I have had to disassemble and shorten a completely finished construction in the past just to get it outside.
Brain Power
Every machine needs a control system. I have used the PiXtend V2 -S- (Table 1) a few times in Halloween projects, and it has always performed excellently [1]; it has all the I/O interfaces I need and is easy to program. This time I chose to use the Python scripting language because it has useful libraries for all the components I use.
Table 1
PiXtend V2 -S- Specs
Digital Inputs and Outputs |
---|
8 Inputs (3.3/5/12/24V) |
4 Outputs (max. 30V, 0.5A each) |
4 PWM/servo outputs (2x16 bits, 2x8 bits) |
Analog Inputs and Outputs |
2 Voltage inputs (0-5V/0-10V) |
2 Voltage inputs (0-10V) |
Interfaces |
4 GPIOs (5V) |
Serial interface (RS-232) |
4 Relays (max. 230V, 6A) |
Support for up to four DHT11/DHT22/AM2302 sensors (temperature and humidity) |
Slot for 433MHz transmitter (radio socket, not included) |
Onboard Voltage Regulator |
Inputs 12-24V DC (max. 30V) |
Output 5V DC/2.4A (supplies PiXtend V2 -S-, Raspberry Pi, and connected USB devices) |
Miscellaneous |
Real-time clock (battery buffered) |
Retain/persistent memory, 32-byte flash EEPROM |
Designed for Raspberry Pi models B+/2B/3B |
Certifications: CE, RoHS |
Hardware Setup
The construction of the vending machine is divided into two areas: the conveyor belts to output the chocolate and the movement of the eyes and mouth. Figure 1 shows the chocolate store, which consists of two conveyor belts that alternately start up and hand out a piece of chocolate.
The sensors are capacitive proximity switches (see the "Zero-Contact Switch" box) with negative switching logic: As soon as something is in front of the sensor, the PiXtend input signal drops to 0V. If nothing is in front of the sensor, the voltage is 24V.
Zero-Contact Switch
In modern installations, zero-contact switches are increasingly found alongside traditional mechanical switches. The three most common sensors are:
- A reflex light barrier, which is based on the principle of light reflection and comprises an infrared transmitter and an IR receiver. As soon as an object reflects enough light, the photoelectric switch is triggered. The range can be several meters.
- An inductive proximity switch, which creates a magnetic field and triggers as soon as a metallic object interferes with the field. The range is often limited to a few centimeters.
- A capacitive proximity switch, which generates an electric field and is triggered as soon as this field is disturbed. It has a similar range as the inductive sensor; however, the electric field can also be disturbed by non-metallic objects.
The conveyor belt starts as soon as the creepy show starts, so the chocolate is ready in time for the output. When the input to which the initiator is connected experiences a positive edge (transition from 0 to 24V) the conveyor belt stops. The belt motors operate at 12V, which they receive from a separate power supply. To get an idea of how the conveyor belt works, watch the video on YouTube [2].
The eyes and the mouth are made of WS2812 LED panels, which a Raspberry Pi controls. It makes sense to order the panels directly from China [3], because they are quite expensive on Amazon. To work with the panels later, you need additional information about their design. The LEDs, soldered in meanders (loops), cannot be addressed directly by physical position. The program contains a matrix that supports easier access to the individual LEDs.
A quick look at the circuit diagram (Figure 2) shows how the sensors and motors for the conveyor belt and the driver for the LEDs work together. The LEDs require 5V, but the GPIO on the Rasp Pi only supplies 3.3V. You therefore need to add a driver component between the Rasp Pi and the WS2812 to increase the voltage: I used an SN74HCT125 TTL [4] (hereafter 74125). Note that the device needs a power supply, which can be provided by the GPIO on the Rasp Pi.
The WS2812 programmable diodes can handle 16,777,216 different colors. They consist internally of three individual LEDs for red, green, and blue. Each of the three colors can be controlled by 1 byte, so you can mix the three colors as required. The 3 bytes reach the LED from a shift register, and the protocol is very time-critical. A high-level language such as Python is therefore not really suitable in this case, but there is a Python library that uses assembler code to transfer the data.
The use of a shift register makes it possible to control almost any number of these LEDs as a long chain. On the Rasp Pi, you only need one GPIO pin to control each LED, no matter how many LEDs are in the chain; however, not every pin is suitable for this usage, because it needs certain timing characteristics. More detailed information can be found on the homepage of the library project [5].
At maximum brightness, an LED can consume up to 60mA, which you should keep in mind when dimensioning the power supply. If you do not turn the brightness up that high, the 5V output of the PiXtend (100mA) is fine for supplying the devices with power. If this is not enough, you need to connect both 5V outputs in parallel to reach 200mA.
The PiXtend is connected to the LEDs with a special flat ribbon cable (Figure 3), which routes out GPIO header pin 32. If necessary, you can easily make this yourself.
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
Linux Servers Targeted by Akira Ransomware
A group of bad actors who have already extorted $42 million have their sights set on the Linux platform.
-
TUXEDO Computers Unveils Linux Laptop Featuring AMD Ryzen CPU
This latest release is the first laptop to include the new CPU from Ryzen and Linux preinstalled.
-
XZ Gets the All-Clear
The back door xz vulnerability has been officially reverted for Fedora 40 and versions 38 and 39 were never affected.
-
Canonical Collaborates with Qualcomm on New Venture
This new joint effort is geared toward bringing Ubuntu and Ubuntu Core to Qualcomm-powered devices.
-
Kodi 21.0 Open-Source Entertainment Hub Released
After a year of development, the award-winning Kodi cross-platform, media center software is now available with many new additions and improvements.
-
Linux Usage Increases in Two Key Areas
If market share is your thing, you'll be happy to know that Linux is on the rise in two areas that, if they keep climbing, could have serious meaning for Linux's future.
-
Vulnerability Discovered in xz Libraries
An urgent alert for Fedora 40 has been posted and users should pay attention.
-
Canonical Bumps LTS Support to 12 years
If you're worried that your Ubuntu LTS release won't be supported long enough to last, Canonical has a surprise for you in the form of 12 years of security coverage.
-
Fedora 40 Beta Released Soon
With the official release of Fedora 40 coming in April, it's almost time to download the beta and see what's new.
-
New Pentesting Distribution to Compete with Kali Linux
SnoopGod is now available for your testing needs