Japanese Rock Gardens, more commonly known as Zen Gardens, are a traditional style of rock garden, meant to depict a small landscape surrounded by raked gravel or sand. Many famous older gardens have been maintained for centuries, and are often used as a meditation aid in Kyoto and other Japanese cities.Note: Video shown here is 125x normal speed (1 frame every 5 seconds).
In this project, we’re building a self-contained and fully automatic Zen Garden. We’ve seen a few of these automatic zen gardens over the years, but the most popular is probably the Sisyphus Kinetic Art Table, which is a coffee table with an inbuilt sand bed, covered by a glass top. It contains a small ball bearing that is magnetically drawn through the fine sand, leaving intricate patterns in its wake. After a pattern is drawn, it is erased by drawing over the top of it and a new one begins.
The Sisyphus table is awesome, but it’s huge, heavy and very expensive. We wanted to build a much smaller one suitable as a desk gadget, but does the same job at a fraction of the cost!
How It Works
The core functionality of our Zen Garden is actually very simple! We’re using a simple ball bearing to roll around the base of the garden, which is moved underneath by a small magnet, creating the illusion of a supposedly autonomous ball. This magnet is moved by a set of stepper motors in a pattern, in a very similar fashion to a 3D printer.
In general, the magnet moves very slowly. There isn’t a huge demand for fast and high-performance motor drives, however, we do want to keep the motors quiet and accurate. Otherwise, the whole ‘Zen’ part of the project is drowned out by stepper motors droning and clicking which we don’t really want!
There are two main motor layouts for moving the magnet around our Zen Garden - radial and rectangular. Rectangular is the simplest, and requires one motor for the X axis, and other for the Y-axis - in many cases, the gantry system can be salvaged directly from a 3D printer. Across the grid of the garden, it generates patterns by moving the motors in coordination to create a pattern. It requires a rectangular shaped Zen Garden, although it allows larger patterns to be drawn and simplifies the process of drawing fine patterns - it is a simple Cartesian coordinate system.
A radial or ‘Polar’ layout is a little different, where one motor is used to rotate the entire assembly, and another motor is used to change the radius of the magnet. Why would this method be useful? It simplifies the motor hardware needed, and also allows us to create a purely circular Zen Garden! Additionally, circular shapes become incredibly easy to draw - we can move just one motor. More patterns can be made by simply changing the radius as we rotate our ball around.
However, it does have some caveats too. You’ll notice on our grid diagram, this layout has the most trouble in the direct centre of the plate. If we wanted to draw a straight line through the centre of the garden, we would have to rotate the entire motor assembly once we reached the centre, before changing the radius again. Additionally, since we are rotating the ball constantly, we may end up twisting the power wires running to the electronics for the motor. For this reason, we have to use a slip ring, which we’ll show later.
It’s worth noting that these layouts can be applied to any 2D movement application - if you have a pen plotter robot, these considerations also apply.
How do we create the most interesting patterns in our Zen Garden? This is a slightly more complex question that it may seem, but luckily other similar projects have been created that we can draw inspiration.
There are awesome websites like Sandify.org that can be used to generate pre-made instruction patterns.
After changing some settings on this website, it’s possible to make some incredible patterns with ease. This program exports in various formats, but the format most used is the GCode format. This format simply includes a list of commands with positions.
G1 X244.594 Y344.945
G1 X247.108 Y341.988
G1 X244.613 Y342.602
G1 X242.632 Y334.994
G1 X249.933 Y330.344
G1 X252.845 Y332.542
G1 X253.827 Y328.799
G1 X262.387 Y328.017
G1 X265.179 Y335.083
G1 X262.722 Y335.799
G1 X266.419 Y336.459
G1 X264.862 Y343.361
G1 X257.525 Y342.304
G1 X257.750 Y338.178
G1 X256.023 Y339.886
G1 X249.881 Y334.639
G1 X252.987 Y326.329
G1 X256.571 Y326.138
G1 X255.102 Y322.275
G1 X261.505 Y316.353
G1 X267.857 Y320.171
G1 X266.231 Y321.935
However, we were most interested in creating procedurally-generated patterns.
Not only would we never have to program the Zen Garden for specific patterns, but it would also generate an infinite amount of randomly generated patterns. In a philosophical sense, it would be an interesting thought that every pattern drawn in the garden would have never been seen before, and will never be seen again.
This is where our polar motor layout becomes very handy - we can use the polar coordinate system in mathematics to generate very simple but beautiful patterns very easily! Let’s look at some simple polar equations.
Making a simple circle is as simple as that! If our equation is R = 1, this means that ‘R’, or our radius, is fixed to a value of one. There is only one line on the graph that can meet this criteria, which is a perfect circle.
What about a spiral?
Note: We’re multiplying theta by 0.05 to make the graph fit on our screen.
We’re now basing our equation on another variable theta, which represents the angle of the graph. The angle starts from the right-side line, and rotates anti-clockwise. As the angle increases, so does the radius. And voila, we have a spiral! In a practical sense, all that our zen garden would have to do is rotate the motor assembly constantly, and slowly increase the radius of the marble while it does so.
To create more complex patterns, we use periodic functions like sin, cos and tan like this:
This might look complex, but with a little bit of thinking about how the sine function works, it’s actually very simple. Because the sine function is a periodic function, no matter how big the number we put into it, we will just get a wave that oscillates between -1 and 1 on the output. The bottom line is that as theta (the angle) increases, the radius goes outwards, then inwards, then outwards again and so forth. The ‘a’ variable allows us to adjust the frequency of these oscillations to create all sorts of flower-like shapes.
However, we wanted to find an equation that can generate a virtually unlimited number of shapes and interesting patterns, with minimal effort from us. We ended up adapting an equation we found online (check our resources section for more info), which can generate a variety of awesome patterns just by changing the input parameters:
This is obviously very complex, and we’re not going to go into how the equation works. The main thing to take away from this equation is that every time we generate a new pattern, we randomise the following parameters:
Parameter, Effect on Pattern
- a - How ‘tight’ is the spiral generated by the pattern?
- c - How angular is the pattern? 0 = Perfect Spiral, 1 = Sharp Corners
- o - An offset for each pattern, skewing the output to make new shapes
- n - How many points should the pattern have? For example, n = 4 will generate squares.
We really don’t have to worry about what exactly each parameter does, because every combination of these patterns will make totally different outputs! Every time we need to generate a new pattern, our Arduino just randomises some new parameters and moves the ball back to the centre.
The following are some patterns that can be randomly generated by the equation above:
It’s quite amazing that such chaos and complexity can be generated from a single equation. Some graphs have a clearly repetitive nature to them, while others appear chaotic and dart all around the zen garden. There is no ‘true’ randomness involved with these patterns, but the complexity of the equation makes it appear as such. It’s worth noting that we are constraining the patterns to a maximum distance of 1, to represent the distance of the garden they can travel - we obviously can’t move the ball outside the bounds of the disc!
The maths nerds reading will know there are far more intricate ways of generating patterns, such as using Mandelbrot or Julia set fractals. If you’re interested in doing this, we’ll be setting up our code so you can implement your own equations for the Zen Garden to draw.
There isn’t much the zen garden can’t draw, but its limit will ultimately come down to how precisely we can move the ball bearing.
Driving The Motors
Stepper motors are indispensable for providing exact and repeatable movements, which is why they are virtually ubiquitous in 3D printers and robotics. However, they do require a bit of knowledge to use, otherwise, you may wonder why your projects aren’t moving anywhere! Stepper motors have two sets of coils, one set offset one step from the other. This means that we need to sequentially energise the coils with some sort of driver.
The easiest way to do this is to use a board containing a H-bridge driver like the L298N, which can be seen in this breakout board from Jaycar. Each coil can be energised with a simple digital signal, which means they can be driven from an Arduino.
What’s great about stepper motors is that the voltage supplied to them does not dictate their speed, so long as the motor isn’t skipping steps. However, we do need to be wary of the current needed by these motors. For this reason, if you’re serious about driving these motors the right way, we suggest using one of these A4988 drivers:
These drivers can automatically restrict the current used by the motor, as well as provide microstepping and drive up to 2A per coil (with heatsinking).
Let’s put together our Zen Garden! This is one of our more complicated builds in terms of 3D printing, and you may have to experiment with and adapt some models if the parts you have don’t match what we used.
There are eight 3D printed parts you’ll need to print for the turntable system. Some are deceptively big, so you’ll need quite a large printer to accommodate them. Don’t be afraid to rotate the models diagonally to make them fit, but be sure to be mindful of layer direction otherwise you may have structurally weak components. For example, don’t print the main mount (the large dark blue part) vertically, as it could snap as the stepper motor is moving.
You’ll also need to pick up some metal parts for the rail system. These parts are often found in lower-cost 3D printers, laser cutters and CNC milling machines, so if you have one lying around you’re willing to sacrifice, many of the parts are ready to go.
We’re using three rails in our build - one lead screw to actually move with the stepper motor, and two straight rods to guide it and hold it in place. Each rod has a block at each end to secure the system, which is bolted to the main 3D printed mount.
The main mechanical element of our Zen Garden is the Lazy Susan. Typically used for serving dinners, it turns out they make great general-purpose rotatable bearings for projects. We used a large 300mm bearing from Bunnings Warehouse.
The biggest flaw of these bearings is the ‘play’ they have - i.e. they don’t have a fixed centre, so they can shift left or right by up to 3-4 mm.
To move everything, we’re using two NEMA 17 stepper motors that can be picked up from your local electronics store. NEMA 17’s are easy to get hold of and have plenty of torque for our purposes. As they are a bipolar stepper motor, each coil needs to be driven separately and in a specific sequence to correctly move the rotor.
Let’s get to building! The first we’re doing is assembling the carriage system. This small carriage will have a magnet attached to it, which will sit directly below the sand plate. First up, we need to thread the lead screw through the carriage 3D print. Use some 10mm M3 screws to thread it into the plastic. This must be exactly perpendicular otherwise the travel direction will not be the same across the rods!
We then screwed on the linear bearings, using a few 25mm nuts and bolts. Don’t tighten these down fully until we secure the rest of the rod system.
The rod blocks we’re using are low-cost aluminium units, but are more than adequate for our purposes. After threading the rod into the block, clamp it down tight until the rod can no longer move - this may take more torque than expected!
The bearing block has a rotatable centre with two small grub screws that needs to be secured onto the main lead screw shaft. Do not overtighten these! They will easily strip and make the bearing block useless. We used two and screwed both down to the main 3D printed mount plate.
We can now mount our stepper motor. This stepper motor is for the Radius axis, which moves the magnet towards or away from the centre of the sand plate. We used a few 10mm bolts to secure it to the 3D printed mount. If you ever break the mount, or want to upgrade the motor, a new mount can be printed very easily.
We then attached the flexible coupler to the lead screw and the motor shaft. Note that the diameters are different, so make sure to pick up a coupler that has the correct adapters. Screw the stepper motor down before tightening the grub screws on the coupler.
After screwing down the LM298 drivers into the slots provided, we can attach the coil outputs to the stepper motor. We chopped the wires down to an appropriate size to avoid anything getting caught in the large gear below. We also connected the power wires in parallel between the motor modules, which makes the wiring more compact.
We can now work on the other stepper motor! This stepper motor is responsible for rotating the entire mount system on the Lazy Susan bearing. We 3D printed a 140-tooth inner spur gear and used Gorilla Glue to mount it to the base of the Lazy Susan. It’s extremely important to check that this gear is concentric - that is, the teeth are the same radius the whole way around the bearing. Once it’s in place, use clamps to hold the gear still while it dries overnight. We also included screw holes if you alternatively want to mount it that way.
While we’re waiting for the glue to dry, we attached the stepper motor to the 3D printed mount the same way as the Radius axis. Do not fully tighten these bolts - we have purposely designed short slots to allow the bolts to adjust as necessary.
Next, we can attach the small 10-tooth spur gear to the motor. This means we have a 14x gear reduction from our motor to the main shaft! (140/10 = 14:1) We intentionally printed the spur gear to have a very tight tolerance, so we used some vice clamps to slide the gear over the shaft.
We also realised that the shaft of the motor would foul against the Lazy Susan bearing, so we used some additional nuts we had lying around to raise it above the platform.
We then connected our stepper motor with its coil wires, feeding it through the build to the other side of the mount to the motor drivers. Be sure to keep the wires as taut and short as practically possible to avoid any snags. In other words, a very similar process to the other stepper motor!
In an XY-configuration machine, the wires connecting to anything on the gantry never rotate - they only move in two axes. For our Zen Garden, our polar configuration causes the whole motor system to constantly rotate, which would cause wires to eventually twist up. Not great!
A slip ring operates by dragging copper brushes along a cylinder that allows the wires to stay in contact continuously, no matter how far it has rotated. The slip ring we’re using has six different wires, which we can use for power, data and anything else we need “transferred” into the axis of the machine.
We 3D printed a bracket that holds the slip ring beneath the main mount, out of the way of the linear rail.
We soldered up a small shield to be used with the Arduino Uno, which makes connecting to the pins easier. These 25x30 hole perfboards can be found in most electronics stores and are easy to build your own circuits. Note that we’re not using stripboard here - these are ‘doughnut hole’ boards where each point is isolated until manually bridged with solder. We first soldered on a set of six screw terminals which will be eventually used with our slip ring cables.
We then added some male headers which will be inserted into our Arduino Uno. Unfortunately, the Arduino Uno doesn’t have breadboard-compatible spacing, so we had to give the headers some ‘encouragement’ to make them fit properly. While we were at it, we cut down the board to the Arduino Uno’s size, to avoid it running into the nearby motor carriage.
Next up, we added two brown wires to provide the Arduino with a ground and 5V connection, which will come from the slip ring wires. The small red jumper on the top of the board is for future use with a NeoPixel strip. We also added two sets of four female headers to connect the stepper motors coils to.
Finally, we can slot the shield onto the Arduino Uno and connect the slip ring wires. Note that the wires are quite thin, so be patient with screwing them into the screw terminals.
We can now focus on getting everything wired up. The two stepper motors we’re using are bipolar, which means they have two sets of separate coils. We’re using the simple L298N-based drivers from Jaycar, which are capable of driving a stepper motor each. There isn’t a lot of configuration needed for these - although we do recommend removing the 5V_EN jumper so our Arduino will provide the 5V power instead of the onboard regulator.
Our stepper motors will require current limiting, as their coil voltage is very low and will handle a constant 12V supply. Applying 12V to the coils will quickly cause the motors to overheat, so we need to provide a constant current supply. We used our laboratory power supply for this, limiting the motor coils to around 1.5A. The motors will usually drop to around 4V to accomplish the required current.
The Sand Plate
It was surprisingly tricky to find a suitable plate to put our magnet and sand on for this project. We could have made our own with some woodworking tools, but we wanted something premade that can be slotted into our 3D print. We settled for using a wooden serving tray - it had handles in the side, so we had to cover up these holes to prevent sand from leaking out. Whatever you make or buy, be sure to test that the magnets you’re using can move the ball bearing through the surface of the sand plate.
We also 3D printed some supporting brackets that sit underneath the tray and support the Lazy Susan.
We used double-sided tape to affix the underside of the Lazy Susan to the supports - we don’t want the tray falling down and sand falling everywhere.
Finally, we can pour in some sand and get everything going. Easy, right? As it turns out, there is an absolutely huge variety of sands that can be used for Zen Gardens, and we had to do some experimentation to get everything working.
In general, the sand for this project should have a fine grain, a white or very light colour, and can be shaped very easily. Beach sand is usually too coarse or inconsistent, so we recommend machined sand that can be purchased from sand suppliers. You can source anything from standard fine-grain sand that is used on some tennis courts and small construction projects to extremely fine silica sand.
Commercial Zen Garden tables use fine silica sand, although we weren’t able to source any locally. Bear in mind that this sand can pose a health hazard with its fine particles, so be sure to wear a respirator as you pour it. We did this at the very end, outside the office, because this is a messy process. A workshop full of sand is an extremely frustrating experience, so it was in our best interest to not spill any!
Finally, we can turn on our power supply, drop our ball bearing in and give everything a test run! The first and most obvious issue we had with our build was that the base of the wooden tray wasn’t thin enough to propagate enough magnetic force to the ball.
While it moved well without any sand, the small amount of resistance the grains provided was clearly enough to completely stop the ball from moving. Even after stacking five magnets on top of each other and reducing the thickness of the sand with a credit card, the ball would eventually lose track of the magnet and it would be stranded in the sand. However, before that happens, the ball does make patterns enough to prove our concept is valid!
The other problems we had related to the physical construction of the motor driving. The large spur gear worked incredibly well, however, it was still noisy enough to be distracting. The rail system worked great, but there was enough flex to cause some vibration while the ball was moving.
Finally, the motor drivers we’re using do not support micro-stepping or internal current-limiting - while this isn’t a huge issue, it causes a bit of extra noise that we’d love to address.
NEXT MONTH: Part 2
We wanted to wrap up this project into one part, but unfortunately, the ship of engineering doesn’t always sail on smooth seas. While we had software ready to show off for this part, we needed to rework some parts of how the drive mechanism works. Much of the project can be carried forwards into Part 2, so we can’t wait to show what we’ll end up with!