Kids' Basics: GolfBot

Arduino Uno & Servo powered

Daniel Koch

Issue 51, October 2021

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

Log in

Ultra-miniature golf with an electronic twist.

This small servo project partners with a range of craft options to enable you to build your own remotely operated golf course. It is based on an Arduino Uno and could be adapted to other games, too.

Putt-Putt or mini golf used to be a far more common pass time than it currently is. Partly due to changing social interests, and partly because of the viability of running such businesses today, it is now hard to find a place to play it. However, our version fits on a tabletop, has a minimum of parts, and can be customised as much as you want. The electronics are little more than an Arduino Uno, a servo, and a potentiometer.

The golf course, however, can be made of whatever you want. We made ours from Kinetic Sand, which is a brand name for coloured sand coated with a complex set of chemicals to make it stick to itself. When loose, it flows somewhat like a thick liquid (or a viscous fluid, to use the scientific term). When pressed down, or into a shape, it stays that way.

While there are cheaper generic brands of this sand available now, you could also use modelling dough (the stuff most of us know under the brand name Play Doh), non-drying modelling clay (which most of us know under the brand name Plasticine), or even cardboard or foam-core board.

Make sure you read all the way through the instructions before you build, as sometimes you have to decide things ahead of time. You can skip the ‘How It Works’ section but do read the ‘Where To Next’ before building.

While we do provide schematic (circuit) diagrams, you don’t need to know how to read these to build this project. You can do it from the photos and the Fritzing, the diagram that looks more like a picture of the parts assembled, which is named after the software used to make the drawings.

The only thing you normally need to know for Kids’ Basics is basic component identification skills, like knowing what a resistor is. Even then, you can probably work it out! The only tools you normally need, unless instructed, are basic hand tools like small pliers, flush side cutters, and a pencil.

Before you start this project, it is helpful to upload the code to the Arduino Uno, so that nothing has to be moved or disconnected later.

The Build:

TOOLS & MATERIALS (See Text for details):
Bamboo Skewers
Modelling Dough
Kinetic or Magic Sand
Foam-Cored Board
Hot Melt Glue Gun and Glue
Small Pliers
Sharp Knife
Rubber Roller

TOOLS & MATERIALS (See Text for details):

Parts Required:IDJaycarAltronicsPakronics
1 x Solderless Breadboard PB8820P1002DF-FIT0096
9 x Plug-to-plug Jumper Leads # * WC6027P1017SS110990049
3 x Plug-to-socket Jumper Leads * WC6027P1017SS110990045
1 x 10kΩ 16mm Potentiometer, Linear (B) TaperR1RP7510R2243-
1 x Arduino Uno or Compatible Board XC4410Z6280ARD-A000066
1 x SG90 Micro Servo YM2758Z6392DF-SER0043
1 x USB-A to USB-Whatever-you-have Lead @ WC7723P1940BSS321010007
1 x Potentiometer Knob HK7707H6030-
1 x PushbuttonSW1SP0609S1135 ADA1119
1 x 100nf MKT or Ceramic Capacitor *C1RM7125R3013B -
1 x 10kΩ Resistor *R2RR0596R7582 SS110990043
1 x Packet Breadboard Wire Links PB8850P1014A SS110990044

@ Will have the other end cut off so an old phone charging cable is perfect.

# Two of these have their ends cut off and can be plug-to-plug or plug-to-socket.

* Quantity shown is what is used in the build. Product may only be available in packs.

The frame that holds our servo is made from bamboo skewers and glued directly to the servo housing. The ‘Golf Club’ is also glued directly to the servo. For this reason, these steps are included in the build, rather than the craft. Everything in the craft build is optional and can be changed.

Please Note: There is a pushbutton, along with a capacitor for debouncing and a resistor to avoid floating, in the schematic and Fritzing. These are optional for the ‘Where to next’ section, and they do NOT appear in the build. They are there for those who are confident to take this project further. This is why they are shown partly transparent.

Step 1:

Take a spare USB lead and cut off the small end that normally plugs into the device. Leave the end that goes into the computer or power outlet. Strip back some of the outer jacket and bare the inner cores.

Step 2:

Cut one end off each of two plug-to-plug jumper leads, one light and one dark coloured. Twist the dark one to the black wire in the USB lead, and the light one to the red wire. Tape the joins. Some USB leads use other colours. Cut off the other two wires, usually green and white.

Step 3:

Take three plug-to-plug jumper leads, and plug them into the end of the servo cable. Take note of which coloured jumper goes to which coloured servo wire.

Step 4:

Servos like these usually have a red wire in the middle for positive (+) power. Take the jumper lead connected to the red wire and plug it into the red (+) rail of a breadboard.

Step 5:

The negative (-) power wire is one of the outer wires, and is often brown, sometimes black, and occasionally another colour. Take the jumper lead connected to it, and plug the free end into the blue (-) rail of the breadboard.

Step 6:

The last servo wire is the signal wire. It is usually orange or yellow, and is almost always one of the outer wires. Take the jumper lead connected to it, and plug it into a row of the breadboard at a spot close to the power wires.

Step 7:

Take two more plug-to-plug jumper leads, and connect one from the red (+) rail of the breadboard to the Vin terminal on the Arduino Uno. Connect another from the GND terminal to the blue (-) rail on the breadboard.

Step 8:

Connect another plug-to-plug jumper lead from pin 3 of the Uno to the breadboard, into the row where the jumper lead from the servo signal wire is.

Step 9:

One more plug-to-plug jumper lead needs to be connected, this time from terminal A0 on the Uno, to a spot on the breadboard.

Step 10:

Take three plug-to-socket jumper leads this time, and slide the sockets onto the legs of a 10kΩ 16mm potentiometer (a 24mm pot will work but you’ll never get the sockets on). They will be a tight fit and you may need pliers to get this to work. Also, add a knob to the shaft of the potentiometer.

Step 11:

Plug the jumper lead from the middle leg of the potentiometer (the wiper) into the breadboard where the jumper lead from pin A0 is. One of the outer jumper wires into the red (+) rail of the breadboard and the other one into the blue (-) rail.

Step 12:

Plug the pins from the modified USB lead into the breadboard power rails, with the light coloured lead to the red (+) rail and the dark lead to the blue (-) rail. Take the opportunity to double-check all of your connections now.

Step 13:

On a piece of spare cardboard or foam-core, use Blu Tack to stick down the breadboard, Uno, and the potentiometer. You may also like to stick on a USB power bank if you are using a small one to power this project. Plug in the USB lead and look for power lights on the Uno to see if everything is connected. If all is well, turn the shaft of the potentiometer. The servo arm should move at the same time.

Step 14:

Turn the potentiometer so that it is in the middle of its travel, half-way between its left and right endpoints. Mark this on the cardboard. You may also need to remove, rotate, and replace the cap on the knob that has the index mark on it.

Step 15:

Take the two-arm servo horn, and place it so that it is perpendicular (at right angles) to the long axis of the servo body. Because of the teeth of the servo, you may not get it exactly straight, but this won’t matter. After this, you can unplug the USB lead from the power source.

Step 16:

Cut four 12cm lengths of bamboo barbeque skewer, and one piece at 11cm. Mark the half-way point of each, using a ruler and marker rather than guessing. Also, measure the thickness of the servo case and mark the middle of that.

Step 17:

Hot-melt glue the 12cm skewers to the body of the servo so that the halfway mark is exactly in the middle of the servo body. Two go on top of the mounting brackets, and two go at the bottom of the case.

Step 18:

Glue the 10cm skewer onto the servo horn so that the halfway point is exactly over the shaft of the servo.

Step 19:

Cut two rectangular paddles from spare cardboard. The size is up to you. The smaller they are, the harder it will be to hit the ball, but the larger they are, the harder it will be to fit into tight places. Glue them to the 10cm skewer at the ends so they point away from the body of the servo.



The heart of this project is a servo. There are two types in general use: Positional, and Continuous Rotation. Both are controlled with a form of Pulse Width Modulation or PWM. Some readers may already be aware that the Arduino series has some pins which are specifically labelled as being capable of PWM. On the Uno, these are pins 3, 5, 6, 9, 10, and 11. Yet the Uno can control up to twelve servos.

How? The answer is that while PWM can be used at some very high frequencies (the number of full on/off cycles per second), and the dedicated pins are capable of that, other PWM signals operate at a much lower frequency than regular Input/Output (I/O) pins can handle.

Inside a servo are a few gears, which slow the motor’s rotation down to manageable levels, and also convert this speed into ‘torque’, or turning force. This is a whole lesson in its own right, so we’ll gloss over that here. Also inside the case is a small circuit, which receives the incoming train of pulses, as well as the power. The width of the pulse is what makes things work.

All ‘hobby’ servos, which are the sort we are using, work on a standard cycle length of 20 milliseconds, or 50 Hz. What changes is the amount of High (On) and Low (off) time in that cycle. The High time is actually quite short: 1 ms at the shortest, and 2ms at the longest. The remaining 18ms to 19ms are low. If you want to see some diagrams of how this works, check out The Classroom in Issue 49.

For a 180° servo, 1ms is 0°, 1.5ms is 90°, and 2ms is 180°. These are the most common servos. However, there are 270°, 90°, and even 60° servos available. Whichever you have, 1ms pulses will put the servo at its minimum rotation, 1.5ms will put it in the centre, and 2ms will put it at full rotation. Continuous, or 360° servos, behave the same, except that 1ms is full speed backwards, 1.5ms is stationary, and 2ms is full speed forwards.


At first, we tried to condense an explanation of voltage dividers into this space. However, we could explain the concept on its own, but not the backup maths. That’s fine if you already understand ratios and fractions, but many younger readers have either not learned this at school yet, or haven’t developed a solid understanding yet. Because of that, we have broken the whole topic out into a Fundamentals article elsewhere in this issue.

The voltage divider, in this case, is the 10kΩ potentiometer, and its wiper is connected to pin A0. As you turn the knob, the wiper moves across the resistor that is connected between the power rails, and so the relationship between the resistance on one side of the wiper versus the other varies. The voltage at the wiper varies accordingly and is fed to pin A0 as a signal of anywhere between 0V and 5V. This is used by the code, as the input pin has a sampler attached that turns the voltage of 0 to 5V into a number between 0 and 1023.


The code itself is very nearly identical to the examples provided from Arduino’s website, but we have a few minor changes. This is because there is no better way to do things than those examples! We have relied mainly on comments in the code to explain line by line, but a few things merit a deeper explanation.

#include <Servo.h>

This line adds a library to the code. Libraries are prewritten blocks of code that deal with complex or time-consuming tasks without the coder ever having to know what’s going on. They basically contain a subset of instructions that tell the code what to do. When the code is assembled into machine code to write to the microcontroller, all this information is written, but the coder never sees it. You might have to add this from the Libraries Manager within your IDE, or it may already be accessible depending on the IDE version you use.

Integers are a type of variable, and variables are places within the code that information is being stored. In this case, the integers create names for things as well as creating the storage space. So, the first one,

int swingPot = A0;  

just tells the code that we’re using analog input pin A0 and gives it a name, swingPot, because it’s the wiper of the potentiometer used to cause the swing of the servo arm. The second one,

int swingVal;

stores the value of the potentiometer as a number between 0 and 1023.

The other main feature of the code worth discussing is mapping. The ‘map’ command is followed by several parameters.

swingVal = map(swingVal, 0, 1023, 0, 180);

The first, ‘swingVal’ in our case, tells the command which variable it is working with. The next two numbers separated by commas is the range that value should be between. In this case, that’s 0 to 1023, because it’s a 1024 number. Following that, the last two numbers are the range to scale the number between. We have 0 to 180, because we have a 180° servo. If you had a 90° servo, this would read:

swingVal = map(swingVal, 0, 1023, 0, 90);

This command decides the relationship between the first two numbers and the second two. So, it effectively divides 1024 by 180, so that the swingVal number has to increase by 5.68 before the servo moves 1°out of its 0° to 180° scale. It’s not exactly like this, as only whole numbers are used, but that’s the general idea.

The rest of the code is straightforward and explained by the comments.

The Craft:

You can use anything you can think of to build your golf course. We used kinetic sand, foam-core board, and Play-Doh (well, not the brand-name stuff because we needed LOTS) to make three different holes for our course. You can also use other materials to add details and obstacles to your golf course.

Further options we thought of are a sandpit, a garden, or an obstacle course laid out on a normal floor. You can probably come up with other ideas. Be careful not to let sand or dirt get into the servo, and please ask your adults before using a garden bed or setting up obstacles all over the living room - they will probably be the perfect size to tread on or slip over on.

We’re going to present our three builds as continuous steps, but you can choose which method or methods you use, if any. You might just take our process and adapt it to your own materials or location. Whatever you do, some handy tools are bits of scrap cardboard or foam core, spoons, and spatulas.

You will probably think of other things too. A small rubber craft roller would help but we couldn’t find one, and we’re in lockdown while making this, so we chose to use what we had instead of going to the shops that are still open.

Step 1:

‘Fluff up’ the Kinetic Sand by teasing it apart and running it through your fingers so there are no clumps. Spread it out on your play area on the general shape of your golf course hole.

Step 2:

Use a roller or piece of cardboard or foam-core to press down a path of firmer sand. While a real golf course has a ‘fairway’ section which in smoothness is between the ‘rough’ and ‘green’, most putt putt courses are one finish.

Step 3:

Cut a hole with a spoon or similar where you want the target to be, then press down around it with a round, flat object. We used the lid of a jar. The final section has to be very flat, so don’t cut the hole after flattening the sand.

Step 4:

Add obstacles, including barriers made with sand, other objects, and bunkers dug carefully with a spoon. Also make a tiny depression at the start, where the ball will sit to ‘tee off’.

Step 5:

Roll a long cylinder of modelling dough and lay it in a line that you want your course to take. We laid ours on a sheet of cardboard.

Step 6:

Use a rolling pin to flatten the cylinder until it is smooth and level enough to putt the ball along. A few small bumps, dips, and slopes here and there are part of the gameplay, but too big and it will stop the game.

Step 7:

Cut out a hole for the ball to sink in, then press down firmly with the same round object from step 3.

Step 8:

Roll another, much smaller cylinder and use it to make a side wall for the course. Do the same for the other side. Push down gently, and use a fingertip to smooth down any places where the ball could become wedges or trapped.

Step 9:

Use more dough, maybe in other colours, to add obstacles to your course. We used a bread knife to cut shapes out of ours and lay in the other colours for sand and water. This means we can separate them later without ruining the colours.

Step 10:

Sketch with pencil a course on a sheet of foam-core or corrugated (thick) cardboard. Cut out the middle sections. You may need a knife for this rather than scissors, so make sure you find an adult to help you.

Step 11:

Glue this cut-out to a base sheet, either more of the same material, or poster cardboard, which we used. Cut out a hole for the ball to sink in, and check the edges for any raised edges or bumps.

Step 12:

Use scraps of foam-core, cardboard, or anything else to make obstacles for your ball to navigate. As before, be careful of creating spaces too tight to fit the arm of the robot.


To use your Golfbot, place a small ball at the ‘Tee’ position at the start of the course. The ball can be a small marble, ball bearing, plastic ball from a toy or craft box, or anything else like that. It must be heavy enough to roll easily (so not a ball of paper) and smooth too, so if you use a bead, make sure the hole is small.

Plug in the USB lead to a power source, and place your golfbot on its legs so that the face of the ‘club’ sits just behind the ball. Once you have it placed, turn the knob of the potentiometer to draw the ‘club’ backwards. Do it slowly so you don’t get the direction wrong and bump the ball.

Now, turn the knob the other way to hit the ball. The faster you turn the knob, the faster the ‘club’ swings and hits the ball. You can explore a lot with this. Raising the club a long way back allows you to watch its speed coming down again, and adjust the speed you turn the pot at to make it faster or slower. Also, whether the club strikes the ball before it gets to the vertical, at the vertical, or after, changes the ball behaviour. How much so will depend on your surface among other things.

As the ball moves around the course, move your golfbot into a position to hit the ball again. It is designed so you can turn it upside down, and left to right, and the club will still swing the same way when you turn the potentiometer knob.

On the soft courses like sand and dough, you can press the legs into the surface slightly to get the position and level right. This isn’t true of the cardboard, which adds another layer of skill and challenge to the game.

You can play several ways. In regular golf and normal putt putt, you have a ‘par’ score to beat. This number is how many shots a skilled or regular player usually takes to complete that hole. After several games, you’ll have a number to beat. You can compete against friends with as many holes as you build, and see who gets the lowest under par, or the closest to it if over.

Alternatively, you can just count the number of shots, and either try to do it in fewer shots than your friends, or less than you did before. Finally, you can race the clock and see how quickly you can sink a ball into the hole regardless of the number of shots (though there will likely be a strong link!).


Most of the further options have been discussed already. You can make the holes more complex, either by being longer, having more obstacles, or both. You can also make as many as you want, up to the limits of how much material you have, how much space you have, and how much it’s going to get in the way of everyone else where you live. Beyond this, if you’re already great at coding but just starting with electronics, then you might like to try adding a button to the circuit. We added it as an option in the schematics and Fritzing, but didn’t add it in the build: They are the ghosted components.

Using this, you could write code that reads the position of the potentiometer as a speed, then ‘fires’ the club when the button is pressed. You could also write into the code that the club should swing back by a certain amount first, just for fun, but this won’t add anything to the physics of the game. In real life, the swinging back first allows the momentum to build in the club as it is brought forwards again, to strike the ball.

You couldn’t just apply that much force from a still start. That’s for long shots of course. For a real putt, you can happily work from a push start. In the Golfbot, the servo has plenty of power to move the ball, and the extra weight of a bamboo skewer and cardboard paddle will add nothing noticeable to it.

WARNING! If left out too long, or in excessively dry air like in front of an air conditioner, modelling dough like Play Doh and off-brand versions will dry out. The fact that the base is cardboard helps carry moisture away. We may or may not have left ours in front of the air conditioner over the weekend (which was on to keep the 3D printers at the same temperature as they printed).

On the subject of dry golf courses, one of those 'Only in Australia' kind of places is Coober Pedy's golf course. The opal mining town in the South Australian outback has a golf course that is worth looking up online. Ask your adult first though!