Halloween candy vending machine
Halloween Machine

© Lead Image © Inok, Fotolia.com
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
Direct Download
Read full article as PDF:
Price $2.95
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Find SysAdmin Jobs
News
-
OpenMandriva Lx 23.03 Rolling Release is Now Available
OpenMandriva "ROME" is the latest point update for the rolling release Linux distribution and offers the latest updates for a number of important applications and tools.
-
CarbonOS: A New Linux Distro with a Focus on User Experience
CarbonOS is a brand new, built-from-scratch Linux distribution that uses the Gnome desktop and has a special feature that makes it appealing to all types of users.
-
Kubuntu Focus Announces XE Gen 2 Linux Laptop
Another Kubuntu-based laptop has arrived to be your next ultra-portable powerhouse with a Linux heart.
-
MNT Seeks Financial Backing for New Seven-Inch Linux Laptop
MNT Pocket Reform is a tiny laptop that is modular, upgradable, recyclable, reusable, and ships with Debian Linux.
-
Ubuntu Flatpak Remix Adds Flatpak Support Preinstalled
If you're looking for a version of Ubuntu that includes Flatpak support out of the box, there's one clear option.
-
Gnome 44 Release Candidate Now Available
The Gnome 44 release candidate has officially arrived and adds a few changes into the mix.
-
Flathub Vying to Become the Standard Linux App Store
If the Flathub team has any say in the matter, their product will become the default tool for installing Linux apps in 2023.
-
Debian 12 to Ship with KDE Plasma 5.27
The Debian development team has shifted to the latest version of KDE for their testing branch.
-
Planet Computers Launches ARM-based Linux Desktop PCs
The firm that originally released a line of mobile keyboards has taken a different direction and has developed a new line of out-of-the-box mini Linux desktop computers.
-
Ubuntu No Longer Shipping with Flatpak
In a move that probably won’t come as a shock to many, Ubuntu and all of its official spins will no longer ship with Flatpak installed.