Feature

Arduino Nano-Based Meccano

Marble Maze

Johnny “Meccano”

Issue 50, September 2021

Combining Arduino, electronics, and Meccano to make a fun servo-operated marble maze.

Back in Issue 46 (May 2021), we published our Servo-operated Ball Maze project, designed to test your skills, and your sanity. This used two SG90 servos, Arduino Uno, and a joystick module. The adaptable design meant that you could create different maze designs with a 3D printer or foam-cored cardboard.

The project was very popular amongst our readers and loyal followers on our social channels. One such maker is Johnny Meccano. You may remember Johnny’s previous features published in our magazine. Arduino Controlled Meccano Rocket Launcher in Issue 42 and RGB LED Colour mixer from Issue 45.

Johnny has remixed our Marble Mayhem project using Meccano for the structure and maze, and swapping out the Arduino Uno with an Arduino Nano with breakout board.

Johnny was kind enough to provide us details on how he built his project, which can you read here.

I was keen to build the Marble Maze for myself that was published in the DIYODE magazine. The concept was fairly straightforward with an Arduino Uno, breadboard, 2 servos and a joystick. They used lightweight foam-core cardboard. Building it in Meccano proved a challenge.

The first step is to get the servos working on a breadboard. As my other hobby is tinkering with electronics, I soldered up a vero board and got it working but it was unreliable. Too many dodgy connections. It's quite annoying when a jiggle makes things change!

The home made board was relegated to the failed projects tub (which is getting rather full now) and I used an expansion board instead. These have the advantage of providing 3 way header pins for each input and output pin on the Arduino. They are labelled SVG which I assume is Signal, Voltage, Ground so if a servo is connected to digital out 9 then you simple plug the 3 way header socket on the servo into the 3 way header pins labelled 9 on the expansion board.

They can go in the wrong way so make sure you line up Orange with S for Signal. There is a DC socket on the expansion board and you can use a plug pack to supply power from 6V DC to 12V DC.

Connect the joystick to analogue out 1 & 2 and the power G & +ve.

I had it working nicely but when I added a 7 segment display it went up in smoke! I think I just overloaded it. A bit of searching revealed the following YouTube video that explained why it failed: https://youtu.be/4QD80OtV3MI

I had incorrectly assumed that the DC socket on the expansion board was supplying the input voltage directly to the Ground and Voltage pins for the servos. Wrong! The pins are connected to the Nano which has its own onboard voltage regulator and while it can provide enough power for normal servo use as in the DIYODE project, it overloads with the addition of a 7 segment display (that probably didn't have a high enough current limiting resistor).

Coupled with the fact I hadn't adjusted the servo positions, causing them to jam when the Meccano hit the table. Visual inspection of the Nano confirmed the voltage regulator was blistered. I bought a new Nano from Altronics but the J5 86 on the Altronics board didn't mean anything to me. A few Arduino forums said it was an AMS1117 +5V so I've ordered a few in case it happens again. Yep, "It happens".

Bad regulator (left), Good regulator (right).

Under a magnifying glass, I could just make out AMS1117. The new Nano from Altronics is on the right.

The Software

In Arduino land, this is called the sketch. You don't really need to know how to write the code as nearly everything you might want to do has already been done somewhere so it's just a matter of copy/pasting existing code.

The code for this project is available for free download from: http://www.nzmeccano.com/image-159592

Note: Along with other DIYODE articles on coding an Arduino, Paul McWhorter has an excellent series of tutorials on YouTube.

The Build:

To build this project, you really only need to plug the servos and the joystick into the expansion board with the Nano on top.

Parts Required:JaycarAltronicsCore Electronics
1 x Arduino Nano or compatible boardXC4414Z6372ARD-A000005 or ARD-ABX00033
1 x Arduino Nano I/O Shield--DF-DFR0012
1 x 2-axis JoystickXC4422Z6363SS101020028
2 x 180° Mini ServosYM2758Z6392ADA169

Parts Required:

The Frame

The main frame is straightforward. 4 x 12.5" Angle Girders and 4 x Braced Girders. I've used 4 x Angle Brackets, part 12a in each of the bottom corners and 4 x Corner Brackets, part 133a in the top corners to keep it square. The ball return is 2 Rods carefully positioned to catch the ball. The Rods are secured with little plastic thingies, part 59c. The servo is mounted on top of the Angle Girder with a 5 hole Strip and 2 Spacers on each of the 3 Bolts. You may need to shave a bit off the Spacers. You can do this by rubbing on sandpaper until you hear the metal Rod touch.

Before
After
Using Sandpaper

The Ball

Part 168d can be bought easily as it's just a 3/8" steel ball.

TESTING

The original Arduino code from DIYODE to control two servos with a joystick didn't work very well. There were two problems. Firstly the weight of the Meccano meant the inertia was playing havoc with the servos. If you changed direction suddenly there were grinding noises and clicks as the internal plastic servo gears were being destroyed. This was fixed by adding a wait command in the loop to make the movement sluggish. I settled on maxstep=1 and delay=30.

The second problem was every now and again it would lose its place and the tray would forget where centre was and get stuck at 10 degrees when the joystick was in the centre position. Fellow Meccano Club member, Dr Paul Dale, helped me fix this with the constrain command. Now I don't pretend to understand this, but as I've said, you don't really need to. The code has been written for you. You only need to understand how to download the code into your Arduino Nano and once that's done it's easy to plug the servos and joystick into the expansion board.

void loop() { 
  int xnew = map(constrain(analogRead(xpot), 
0, 1023), 0, 1023, 65, 115); 
  int ynew = map(constrain(analogRead(ypot), 
0, 1023), 0, 1023, 115, 65); 
//Controls the servo limits. 
//Reverse to change direction 
  int maxstep = 1; 
    // Change this to change the speed limit 
  xvalue = constrain(xnew, xvalue - 
maxstep, xvalue + maxstep); 
  yvalue = constrain(ynew, yvalue - 
maxstep, yvalue + maxstep); 
  xaxis.write(xvalue); 
  yaxis.write(yvalue); 
  delay(30); 
  //Increase this to make it more sluggish

This is just the loop section of the code. The complete code is downloadable for free from nzmeccano (http://www.nzmeccano.com/image-159592) or at the end of this article.

The servo needs to be mounted on top of the Angle Girder to allow enough room beneath the moving frames for the ball return. These servos never seem to be exactly centred. They have a splined shaft and I've found that if it's leaning to one side, moving the white plastic lever (horn) to the next position results in it leaning too far the other way. Most frustrating! To make this easier I mounted the horn onto a Bush Wheel using 2 Fishplates and used a Crank on the frame. This allows a Rod to be used and makes it easy to adjust the angle by loosening the Grub Screw. You don't have to use a Crank either as they are not all that common. 2 x Bush Wheels will do.

Outer Frame

With the outer frame 12.5", the middle frame needs to be 9.5" to allow for the Bush Wheel and part of the servo body to fit comfortably so use 4 x 19 hole Angle Girders part 8a. Use 4 x Corner Brackets, part 133a to keep it square. It's a good idea to square it up on the corner of the kitchen bench before tightening the Nuts.

Mounting the inner frame is a repeat of mounting the middle frame. Bolt the servos on in the same way using 5 hole Strips and 2 Plastic Spacers on each Bolt. You can see in the photo that I mounted the freewheeling Bush Wheel with the boss on the inside and 2 x Plastic Spacers plus 4 x Washers. This was just to get both Bush Wheels symmetrical. It really doesn't matter much. You could probably get away with just a Pivot Bolt if you were short on parts. The inner frame is 6.5" by 6.5" but as Meccano doesn’t have a 6.5" Angle Girder, I've used 4 x 5.5" Angle Girders, part 9, with 1" Angle Brackets, part 12a, in each corner. A Corner Bracket, part 133a is in the corner where the exit hole is. The base of the maze is 3 x 5.5" x 2.5" Flexible Plates, part 192, and 1 x 5.5" x 1.5" Flexible Plate, part 189. The maze can be fashioned in many ways. I've used various sized Narrow Strips and standard Angle Brackets. You may have to fiddle around with it to prevent the Ball getting stuck but really, it adds to the overall challenge.

The Ball return Rods are on a slight angle to get it lined up under the hole in the base of the maze and also to get both Rods through the triangular hole in the Braced Girder.

WHERE TO FROM HERE?

We hope these build details are enough to get you underway with your own build.

If you don't want to use Arduino, you could use these servo motor controllers. You will lose the ability to make the motion sluggish but it should still work. We sourced ours from eBay for just a few dollars. Note: You will also need 2 knobs (one for each servo) rather than a joystick.

Johnny “Meccano”

Johnny “Meccano”

14 year old student and Meccano builder.