Projects

DIY Claw Machine

Using an upcycled 3D Printer!

Liam Davies

Issue 73, August 2023

This article includes additional downloadable resources.
Please log in to access.

Log in

Build your own Claw Machine from an old 3D Printer! Our awesome arcade machine comes complete with a joystick, smooth stepper motors, and even a clever claw system!

We’ve built a lot of weird and wonderful candy-related machines over the years, and that trend isn’t going to stop any time soon. This month, we’re building the arcade classic Claw Machine. The premise is simple - a controllable claw with a time limit, a selection of the user’s most sought-after lollies and/or chocolates, and some buttons and joysticks.

We’re designing this project to be as adaptable as possible. Whether you want to make a desk-size micro machine, or a 1:1 arcade beast, the basic layout of the electronics and underlying software will be mostly very similar.

How It Works

Everyone loves to spend time in arcades inspecting the mechanics and electronics of arcade machines. Or is that just us? Anyway, claw machines may be more complex than you realise. There are a massive variety of them, with everything from your typical chocolate claw machines (often found in RSLs and bowling clubs in Australia) to massive commercial arcade machines that can pick up high-value prizes like gaming consoles or tablets.

Image Credit: Highland Park Tavern

They have a simple overhead X-Y gantry, which is usually fairly precise and can be moved freely with a two-axis joystick. The joysticks aren't high-tech - they have simple ON-OFF switches, so skilled players can't exactly position the head by just moving it slowly like an analogue game controller.

A time limit is usually imposed to provide a sense of urgency, and there are a few extra features some machines have too. Some machines with smaller prizes have a "pusher" which can provide a much bigger amount of prizes won with good timing and prize selection.

To prevent cheating, most machines disable prize payouts whenever an external force or shaking is detected. We won't be adding a prize pusher or shake detection to keep things simple. Hopefully, the potential players in your home/office are honest!

Image Credit: Arcade Express

Anti-Slam devices have been around for decades, and many are as simple as the one above, with a weight at the end of a flexible aluminium bar. They're typically designed to fully reset the machine whenever tilting OR shaking is detected, causing the full loss of all credits.

Most arcade claw machines also allow the owner to configure various parameters to make the game easier or harder. Claw strength, joystick behaviour, time limit and cost per play are all configurable to provide any degree of difficulty (or at least, perceived difficulty) desired. We'll provide some of these parameters too - don't get too evil with it!

Image Credit: Plush Bus Arcade Machine Service Manual

3D Printer

You don't have to use a 3D printer for this project, however, our custom 3D models will be designed for the Flashforge Finder in mind. We chose this printer for a few reasons.

The first reason is it was collecting dust, as many of the newer printers we've acquired over the years far outperform and out-spec the humble Finder. The second reason is that Jaycar has since discontinued the Finder and the Finder Lite, so we're expecting that many makers will have upgraded, and are looking for upcycle opportunities for their Finders.

And, most importantly, it has a gantry system that is consistent with how most expect a Claw Machine to work. Some other printers we considered for this project have configurations that are unintuitive for a claw machine. For example, the CR-10 we considered has an extruder that moves in an intuitive way on the X and Y axis, but not on the Z axis - the bed itself moves back and forth, instead of the extruder.

The CR-10 is a large printer, but the layout could make it confusing for beginners. Image credit: 3D META.

This could lead to confusion for the user, as well as making it difficult to enclose the entire system with screens. While we didn't end up using screens on our project due to a lack of time, it should be easy to add - we'll talk more about that later.v

If you don't want to use a 3D printer at all, you'll need to design your own frame and movement hardware. We've done this in past projects such as the Zen Garden from Issue 67. However, be aware that it takes a lot of time to design, build and test the system - it's a fun process, but for this Claw Machine project, we wanted to keep everything simple and easy to follow. It is also probably cheaper grabbing a second-hand 3D printer than building everything from scratch.

Buttons

For our joystick, we’re using Jaycar’s popular SM1052 8-way joystick. It’s affordable, decent feeling and easy to hook into our circuits.

Many arcade systems have buttons built into the Joysticks, however, we don’t have the space to insert one into ours, so we’re using a dedicated button mounted onto the front panel.

At this point in most projects, we normally do a Fundamental Build to make sure everything is in working condition before we commit to a final build. However, because our project revolves around a 3D printer, we can't really test build things without actually committing to it. So, let's dig into the Main Build and iron out any problems as we go!

The Main Build

Parts Required:JaycarAltronics
1x Flashforge Finder 3D Printer ^TL4220-
1x Arduino Nano (or compatible)XC4414Z6372
1x Arduino Nano CNC Shield--
1x Arcade Joystick with MicroswitchesSM1052S1147
1x Illuminated Arcade ButtonSP0666S0912
3x A4988-compatible stepper driversTL4300-
1x 6-core Slip RingPakronics: ADA736-
1x MG996R (or compatible) ServoYM2765Z6393 %
1x 5A Step-Down DC-DC Converter #XC4514Z6334
5x 6mm M3 Screws*HP0400H3110A
2x 20mm M3 Screws*HP0410H3150A
4x 10mm M3 Screws*HP0403H3120A
3x 12mm M5 Screws*Bunnings: 2310746-
8x M3 Nuts*HP0425H3175
3x M5 Nuts*Bunnings: 2310746-
Ribbon Header Wire-W2524

Parts Required:

^ Note that this item has been discontinued by many suppliers in Australia. You may need to source this second-hand. * Quantity required, may only be sold in packs. # Check how much current your motors require, and chose a buck converter appropriately. % This motor is a continous 360 degree version - you will have to modify the code.

Disassembly

We'll first need to pull apart our Flashforge Finder. While we won't intentionally destroy electronic components during the disassembly process, we're also not planning on ever reassembling this printer. For that reason, we'll be cutting quite a few wires as we go. Be sure to disconnect the power as we don't want to short out our power supply during disassembly.

The first thing we'll need to do is remove the panels from the printer, which, on our Finder, is a very easy process.
Just grab a Phillips-head screwdriver and remove the top, side and rear panels. The screws are tapped, not threaded, so you may need to apply a bit of torque to get them to budge.

We're completely removing the Z-axis and the attached print bed, as we won't need it for our project. This can take an hour or two, so be patient.

We first unscrewed the print bed using the levelling adjustment screws. You should be left with the black frame as shown above. We then need to remove the entire underside of the printer to access the stepper motor and bearing rods. There are 10-15 screws to get everything undone, so make sure you unscrew them all and don't force anything!

After that, we can remove the rod holders and unscrew the stepper motor mounts. Use a 2.5mm Allen key and Philips head to remove the bolts.

The Z-axis should now budge and move around. If you put in some elbow grease, you may be able to pull the rods out of their slots, but we weren't able to do this. We instead had to remove the top gantry assembly of the printer and use a pin puncher and mallet to tap them out!

We can now completely remove the bed assembly from the printer! We should be left with a satisfyingly empty printer enclosure, ready for our lollies.

We then worked on removing the head of the gantry, where the extruder is mounted. It won't be mounted for long, though! Grab the Allen Key wrench and remove the top cap of the extruder, disconnecting pretty much every wire you see.

There is a small breakout board that connects the ribbon cable to all components used. On the Flashforge Finder, there are a few components that are connected to this board, including the extruder stepper, two small LEDs, the extruder heater, and an auto-levelling servo motor.

We also needed to remove the bottom tray screw mounts with a step drill, or if you have one available, a Dremel would work okay too.

After we're done removing everything - including the hot end and thermocouple - we should be now left with an empty carriage. We'll be 3D printing some parts to mount onto this carriage in the Main Build!

Main Board

We looked into using the existing mainboard of the Flashforge Finder for use with our Claw Machine, however, it's not really hackable without some serious reverse engineering. The whole board is one PCB, which includes the central microprocessor, the stepper drivers, power electronics and hundreds of resistors. Nothing is removable besides the external components with connectors attached, so we're opting to tear this board out and use our own electronics to drive everything and move it around.

Luckily, all connectors are nicely labelled so it'll be very easy tapping into the existing wires for controlling the stepper motors and limit switches. We removed all cables, including the stepper connectors, limit switches and the two ribbon cables.

The main board can then be unscrewed, and we should have a nice large area to install our electronics into. Note that we won't be using all of the connectors - the USB host and device connectors probably won't be used here, for example.

Spool System

We've spent a bit of time working on a spool system that won't tangle up or break. Because we're using exclusively wires to support the claw system, we need to have some way of winding and unwinding the wires while still keeping them connected.

We devised a clever system using the existing extruder stepper motor, a slip ring and some 3D printed parts.

There are a few parts you'll need to print to get the spool system working. Since it mounts directly onto the Flashforge Finder's extruder carriage, all you'll need is some screws to secure it.

Since we're using the NEMA17 motor included with the printer's extruder to control the spool, we have to move it upwards and backwards to make room for everything. We designed a mount that holds the motor securely with 4x 16mm M3 bolts.

The spool itself has a small spiral insert that holds a small length of wire in place to prevent it from spinning. The wire itself is standard jumper cable, with three wires to power the claw system's stepper motor.

To insert the wire, grab a pair of fine needle nose pliers and slowly push it into the slit. With some patience, you should be able to grab it on the other side and thread it around the spiral. With the wire now on the spool, we pushed it onto the stepper motor's shaft - it should be a snug fit.

At this point, we can thread the wire through the cone-shaped 3D printed component - this will act as a container for our unused wire, making sure it doesn't get tangled anywhere else. We can then solder these output wires onto any three wires of the slip ring, ensuring that we terminate and insulate the unused wires.

The slip ring also has a special 3D printed mount that holds it both onto the stepper and on the Flashforge Finder's carriage. This method of mounting is very similar to our Zen Garden from Issue 67 and 68.

Done! We're pretty proud of this little unit. We used a multimeter to verify we didn't incorrectly solder anything and that all wires had contact. Since we're only using 3 of the 6 wires of the slip ring, we later tucked the others away with zip ties.

Gantry Wires

The original printer comes with a rather wide ribbon cable that connects the extruder to the body of the printer, providing power and data to the components on board. We could use this ribbon cable, however, it has very fine connectors on either end, not suitable for wiring on a standard-size breadboard or perfboard.

We instead opted to add our own ribbon cable, using
unsplit header cables. These are very common cables and very cheap. We used a seven-wide header cable strip, and used double-sided tape to secure it to the side of the claw gantry.

So we have a flexibility with wiring, we opted to solder up a small perfboard breakout. All seven wires were connected in order here, taking care to connect each with the same angle to avoid cable stress problems.

We can then add a four-long male header to the board for the stepper motor wires, and directly solder the slip ring's wires onto the board. The stepper motor has a connector that is compatible with 2.54" spacing, so it's dead simple to drop it into the board.

We can then feed our wire around to the back of the machine. Like the original wire, it's important that we provide enough slack to allow the gantry to move anywhere in the XY plane. We recommend moving the gantry to the front left corner and running wire based on that distance.

Finally, fold the wire at a 90 degree angle and fold it through the original wire slit to the back of the machine. We also replaced the original wire cover.

The Claw

Let's assemble our claw system! We've adapted an existing claw system by Thingiverse user papabravo, and added our own changes to make it better compatible with our project.

The claw we're using is a little different than is used in typical arcade machines - this one uses a clever rack-and-pinion based system that moves linearly. It's not as traditional, but definitely looks awesome and works really well.

To start, screw the small pinion gear onto the servo motor with a M3 screw. It should fit very tightly and not budge at all once tightened.

After slotting it into the enclosure, we'll need to add our rack gears. Note that you'll need to pay attention to the orientation and position of the rack and pinion gears - when the motor moves, it should be able to move the jaws from fully open to fully closed with half of a gear turn.

We can then use a few M3 screws and nuts to secure the claws themselves in place. Feel free to modify these to make a different shape - we left ours as default. Tighten the screws just enough to hold the claw in place - too tight, and the motor won't have enough torque to move them.

Our claw system is now functionally complete. We now just need to hook it up to the rest of the machine. We've included five rectangular slots for threading the spool wire through - choose a slot that best matches the centre of gravity of your claw. This should ensure that the claw hangs as level as possible.

We don't like irreversibly modifying components, so we soldered up a small header row to plug in the servo's header wires and plugged it in. To take up the slack, coil it up inside the claw holder and cable-tie it down if necessary.

At this point, try winding the spool manually (with the stepper motor completely unplugged) and test if the claw mechanism hangs level. If not, adjust the weight balance.

Joystick

Assembling our Joystick mount is fairly simple. We had to print our model a few times to get the dimensions right, while still keeping everything compact. We printed ours in Grey PLA.

The illuminated pushbutton was screwed into the front panel too, ensuring that the locking nut is tight so there isn't any noticeable rotation. There is an LED inbuilt, which can run on 12V. We're running it on 5V directly from the Arduino, which only uses a few milliamps to run at a reasonable brightness.

We then screwed in one of Jaycar's popular SM1052 joysticks, which we removed the top aluminium plate from. You may need to use larger self-tapping screws to secure it in place.

The black cover plate and threaded knob can then be added onto the joystick handle, completing the look of the controller unit.

Let's work on the wiring! Our joystick wiring is fairly simple - all wires connect back to ground. There are seven wires in total - four for the joystick directions, one for the button signal, and one for the illuminated LED on the pushbutton.

We used a small roll of jumper wire with grouped wires, soldered to each connection with heatshrink. Make sure there is at least 50cm - we'll need this to run it back to the main controller board. We daisy chained a single ground wire between each component, ensuring that there is no chance for short-circuits - this could lead to some very hard to diagnose problems.

After we tidied up the wires and did some quick continuity tests to ensure everything is working, we then attached it to the printer case.

The wires can be ran around the perimeter of the printer, keeping it out of the way of the lolly tray area. We then soldered female headers onto the head, grouping the four joystick directions with their own header group. We prefer these breakable headers for projects where we may wish to reconfigure the pin layout as we continue to develop it.

LCD Screen

We chose a 20x4 character LCD to be mounted to the front of our Claw Machine where the old TFT touchscreen was located. While we could have hacked the TFT LCD touchscreen, it would have not have been an easy task. The stock screen is hooked directly into a microprocessor, which means we'd have to do a lot of reverse engineering to make it cooperate.

Instead, we removed the screen, slapped a few layers of double-sided tape onto our 20x4 character LCD, and mounted it onto the outside of the old TFT screen location.

It's not the prettiest mounting solution in the world, but it saves us from pulling out the Dremel and cutting wheels to hack away parts of the stock plastic.

By the way, you may have spotted a little black board hanging off the underside of the 20x4 LCD. This is an I2C breakout board, which can be used to transform what would otherwise be 5-8 data pins into a simple two-wire protocol. Since we're already quite tight on our Arduino's data pins, this saves us the hassle of hooking a bunch up. We can simply connect SDA and SCL to the A4 and A5 pins, and interface with our LCD that way. Easy! Before securing everything down, ensure that you've applied power to the LCD and set the contrast with the potentiometer such that characters are visible.

The wires themselves are just extended jumper wires that are routed around the top of the printer towards the back control board. Speaking of which, let's get that hooked up.

Control Board

Note: Some previous photos in this project may show parts of this control board already connected. We chose to explain this as its own section to simplify wiring.

We're using a CNC shield for the Arduino Nano to act as our control board. We've used other boards in the past such as a similar shield for the Arduino Uno. In any case, if it's marketed as a 'CNC' shield, there is a good chance that it's GBRL compatible and our code will work with no extra configuration!

First, let's slot everything in. Make ABSOLUTELY sure that the stepper drivers are inserted in the correct direction - you definitely do not want to mess the orientation up.

We can then start to connect the other components we've added to the claw machine. Currently, our board will just be hanging out the back of the 3D printer. We started by connecting the three stepper motor cables, for the X (left and right horizontal movement), Y (forward and back) and Z (up and down spool winding) axes. The orientation doesn't matter, however, you may need to invert the direction travelled in code.

We can then plug in the servo motor for the claw, which is connected to D12 and 5V/Ground for power. There are quite a few header locations for 5V and Ground on the CNC shield, so don't worry about running out.

We can now connect our limit switches. We won't be cutting the original limit switch wires, just popping some male jumper wires into them. Grab a multimeter and use the continuity mode to ensure that, when the switch is pressed, it closes the circuit.

After connecting the four joystick wires and the 5V/Ground power for them, we've finished connecting all components to the main control board!

Finally, we need to provide our Arduino with power. There are a few different ways of doing this, but, however you do it, ensure that you have a stable power supply capable of delivering at least a few amps.

We've chosen to use the existing power jack to simplify wiring and allow the use of the existing switch and power jack. The existing power supply uses 24V, which is far too high for both the Arduino and the attached stepper motors to use. We're using a small 5A buck converter to reduce this down to 10V, although, you'll need to check the stepper motors in your printer to ensure you aren't providing too much current - we'll talk more about our experiences with this in our testing section.

At this point, we can start reassembling the Claw Machine, following the reverse of the disassembly instructions. We'd suggest leaving the back panel off so we can program the Arduino Nano.

Motor Control

We have three sets of stepper motors to handle, and a servo motor. It may seem like a complex setup, and, in a situation where fine-grained control is essential, it would be.

However, our project is dealing with fairly predictable inputs and accuracy is not essential, so it's not difficult to write some code to get it all working.

The X and Y motors control the horizontal position of the claw machine gantry. These motors will be exclusively controlled by the joystick, in each of the four directions.

The Z motor controls the spool system. We're using a set routine to handle the spool motor, pulsing it a set number of times and then returning to its original position.

#define X_STEP 5
#define X_DIR 2
#define Y_STEP 6
#define Y_DIR 3
#define Z_STEP 7
#define Z_DIR 4

Since we're using the Arduino Nano CNC shield, we can easily look up the pinout for the board, and assign everything appropriately in code. Speaking of which, let's get to writing the core logic!

Code

We've written fully configurable software for this project, so you won't have to know a line of code to make everything work! If you're not interested in tinkering, just open the code file in the Arduino IDE, and press Upload. If you do want to configure aspects of our project, you'll be able to change the parameters at the top of the code file.

#define CLAW_TIME_MS 15000

The CLAW_TIMER variable changes how long in milliseconds before the claw descends, regardless of where it is. This prevents players from spending as long as they want exactly positioning the claw.

#define MAX_CLAW_HEIGHT 500

Depending on how many lollies you have in the machine, you may need to configure the claw height. This is how many steps the claw will descend before stopping and attempting to grab a prize. You should experiment with this value a bit, as it'll depend on where the claw starts from. Too low and the claw won't reach the lollies at all, and too high and the claw will fall down sideways before grabbing a prize.

#define CLAW_SPEED_DELAY 2000

This parameter describes how fast the claw should descend and ascend when the button is pressed - lower values correspond to faster travel.

The claw can be interfaced by simply using the Servo library, and writing an angle to it between 0 and 180 degrees. We had to do some experimenting to ensure that these angles were reasonable and didn't collide with any claw mechanism parts.

The outer claw position refers to where the claw sits when idle - it isn't important for game difficulty. However, the inner claw position refers to the target position when it's gripping onto a prize. The closer this is to fully closed, the stronger the force will be. Beware, in our experimentation, the servo motor has enough force to crush some lollies!

We'd suggest setting the value to just enough to hold onto a lolly, while making it challenging for players. Players should have to consider what part of the lolly to grab in order to pick it up properly.

#define OPEN_CLAW_POSITION 20
#define CLOSED_CLAW_POSITION 150

Custom Progress Bar

We were inspired by skywodd's Custom Progress Bar in order to show how much time we have left to pick up the lollies. You can check out his full article in the Project Resources (it is written in French). It uses a clever outline and custom character system to display up to 38 segments across the 20-character wide screen.

Each custom character appears like this in code:

byte START_DIV_0_OF_1[8] = {
  B01111, 
  B11000,
  B10000,
  B10000,
  B10000,
  B10000,
  B11000,
  B01111
}; 

We can then initialise it in the setup function like this:

lcd.createChar(0, START_DIV_0_OF_1);

There are seven characters used to make the progress bar work. Skywodd has their own code to handle the progress bar logic, but we wrote our own. You can check out the full code in the project resources if you're interested in seeing how it works.

Testing

After plugging everything in and turning on the rear switch, we poured some lollies and chocolates into the bed of the printer. We also added our 3D printed chute onto the side of the printer, which drops any won lollies outside the printer, ready to collect.

The Joystick is very responsive, and it's easy to move the claw wherever desired above a lolly. It definitely has that 'clunky' feel that old arcade machines have, which is a nice touch. After pressing the button, the spool descends to its required level, and the claw closes on whatever you may have collected. It ascends again and the user must direct the claw to the exit chute - we currently haven't implemented the code for the claw to find its way to the chute. We'll talk more about why shortly.

The LCD works excellently. It's directly in front of the user's vision, which makes the timer all the more apparent when hunting for a lolly. The 20x4 LCD was a good choice, and is very visible.

One of the issues we still have to fix with this project is the loudness of the motors. We did spend a bit of time tuning them, such as enabling microstepping and reducing current, however, they still emit quite a strong humming noise. Part of the reason is that we're overvolting these motors, due to the minimum voltage of the buck converter. This causes the motors to get hotter quicker and generate more noise, albeit with much more torque.

This is why, in our code, we turn off the motors when we're not moving the gantry system - we'd rather them not overheat! If you're building this project, we suggest sourcing a buck converter that can provide much less voltage to prevent this issue from occurring.

One of the limitations of our code currently is that it does not have absolute position control. Ideally, when the machine is turned on, it will move the gantry to the limit switches so it knows where the claw is, and how far it can move in every direction before fouling with the chassis.

We simply ran out of time to implement this, but fortunately, the functionality is not greatly affected. The main downside is that the claw must be moved by the player to the exit chute. In any case, we've provided the code for those who are interested to review and improve it. Overall, though, the claw machine is a successful project that had staff around the DIYODE engaged for hours!

Where to from here?

There are a few things we haven't included in this build for the sake of simplicity. You may wish to add any of these features for further development!

The first thing we'd suggest adding is side panels. We currently have left the lollies out in the open, which leaves the machine open to lolly stealing! Besides the fact that we ran out of time to add side panels, we didn't prioritise this as it also allows DIYODE staff around the office to quickly grab a treat. We think of it as a stylish treat reservoir with a minigame built-in.

Image Credit: The Men's Cave

If you're understandably adding side panels to keep sweet tooths out around the home or office, though, we suggest starting with some Perspex or acrylic and going from there. You may be able to secure some panels to the inside with some double-sided tape, or use a Dremel to add holding slots.

We also haven't added a coin slot for payment. If you're a local business owner or know someone who is, this could be an awesome way to make some quick cash! There are many coin slots available from electronics suppliers which can be set up to provide an electronic pulse when a certain type or quantity of coins are inserted.

Image Credit: Sparkfun COM-11636

When we started this project, we also were planning on adding some additional lighting and gadgets to the lolly compartment, however, we ran out of GPIO pins to implement this. If you're interested in adding a bit of additional aesthetic appeal to your project, we suggest grabbing an Arduino Mega with a CNC shield.

Finally, we'd also suggest adding a coin pusher and/or shake detection. This would add another level of skill and integrity to the game. A ramp could be added that closes the prize chute if the machine has recently been moved or jolted.

Let us know what you come up with at @diyodemag!

Reading & Resources: