Arduino Projects: The Rolly Mk. II robot

rolly mk2

Robotics has been, is, and will likely always be one of the most popular uses for an Arduino microcontroller board. Based on web comments alone, the Rolly Robot from last year has been one of the most popular Arduino projects in our Arduino masterclass series, which is amazing given how low-fi it was, but then, maybe that was part of its charm.

It still wanders slowly around my home occasionally, but I have to confess that its days in the sun are numbered – this month, we’re swinging the bottle of champers over the Rolly Mk.II robot.

New chassis

Block diagram of the Rolly Mk. II robot.

The major new feature this time around is the replacement of the food container lid for a proper acrylic chassis. We spotted a relatively cheap robot chassis kit online some time ago, but recently its price dropped down to just $12 on eBay and we couldn’t resist.

And for what you get, it’s excellent value. For the most part, it includes much of the hardware we scrounged last time for the Mk. I, so the Mk. II not only looks better, it’s far more robust and reliable as a result.

The kit includes acrylic chassis, GM3 DC gearbox motors with matching big yellow tyres, front universal castor wheel, all necessary screws and nuts, plus a basic four-AA battery holder. Just search ‘robot car chassis’ on eBay and you’ll find quite a few of them. As for total cost, check out the Parts List and you’ll see that, not including batteries, the new Mk. II robot should cost around $50-55 (given the Aussie exchange rate).

Electronics

Solder 0.1uF ceramic/polypropylene capacitors across the motor terminals to reduce noise.

From an electronics viewpoint, there wasn’t too much wrong with the Mk. I, so we’re using the same design again – an Arduino Uno R3 microcontroller board driving an L293D Motor Drive Shield with a TowerPro SG90 servo motor controlling an HC-SR04 ultrasonic sensor whacked on top.

The use of a standard non-switched battery holder means we need a power switch – the simplest option is a standard SPST (single-pole/single-throw) toggle switch in series with the positive battery lead.

The source code or ‘sketch’ for the Mk. II has also had an overhaul and refit – it gets rid of some ‘dead wood’ code plus a number of bugs.

As a result, we’ve been able to crunch the code down from 8.5KB to 6.5KB (leaving you more Arduino flash storage space to play with yourself.)

So let’s get into it:

STEP 1: Build the chassis

This robot chassis kit is available on eBay for as little as US$12.It’ll probably come as no surprise that there are no instructions with this chassis, so you’ll need to crack open your McGyver skills for a bit of ‘DIY’, but really, it’s not too difficult. There are two versions of the kit on eBay – the simplest way to tell them apart is one uses brass tapped spacers on the castor wheel; the other doesn’t.

What both kits do have in common is some 30mm long M3 machine screws to bolt the steel mounting plate to the GM3 motors. When you mount this, make sure the tiny motor power terminal tabs face the inside – this will help keep your wiring neat.

The only other thing with the motor mount is the two holes in the top should line up with the chassis, allowing you to use two of the smaller M3 machine screws supplied to mount it in place.

You can remove the brown paper from the acrylic chassis, but we kinda like it…

Now is also probably a good time to point out that the acrylic chassis plate has a protective paper covering on both sides that you can remove – or not. The acrylic chassis itself is transparent – we chose to leave the paper on, one, so we can protect it while we muck around with the design, and two, so you can see it more clearly in the pics.

Since you will need to drill at least one hole for the power switch, the paper also helps keep the acrylic from shattering or cracking while you drill.

And here’s another tip – don’t use normal high-speed drill bits when drilling into the acrylic as they can cause cracking. You should be able to find shallow-pitch plastic-cutting drill bits at the local hardware store. Failing that, use a standard drill bit on a slow setting. Acrylic has a habit of melting if you drill too fast and don’t lean too heavily on the drill or the acrylic sheet will crack.

We installed the battery holder at what we’re calling the ‘rear’ of the chassis – alongside the driving wheels. Again, use two of the small M3 machine screws down through the top with nuts underneath. The batteries will still happily sit on top of the screws and make contact.

STEP 2: Adding the Arduino Uno R3

At this point, you can either drill a couple of extra holes to add in mounting screws on the microcontroller as we did, or you can use Scotch double-sided mounting tape. This stuff sticks like the proverbial to a blanket, so you won’t need to worry about it falling off, even if you have a major stack and roll.

Three rows of six header pins soldered into the Motor Drive Shield’s analog terminals will make life easier.

Before adding the Motor Drive Shield, we recommend you solder in some pin headers to the analog input area at the front. Some shields will have these already installed – if not, you can buy them from Jaycar or eBay for a dollar or so. Solder them in carefully and it’ll make any future mods much easier to do. You just need three rows of six pins each.

If you’re dangerous with a soldering iron in hand, practice before doing this or rope in an experienced mate to help.

STEP 3: Wiring up the GM3 motors

The Motor Drive Shield does the hard work, handling the motors and sensors.

This is probably the step that needs the most dexterity. The tiny connection tabs on these motors are a bit fragile, so don’t be rough with them. Also, you’ll need to add in 0.1uF capacitors across these tabs – they help reduce the radio-frequency noise generated by the motor brushes and stop it mucking up the Arduino and shield. Ceramic capacitors are cheap and do the job – polypropylene caps work too, but they’re much more expensive.

Try to keep your wiring reasonably tight and measure the wire length to each side of the motor shield terminals. Another tip, twist the wires together as a pair – this will also help reduce noise up the line.

STEP 4: Setting up the servo motor

We’ve used a DPDT toggle switch but a SPST switch with just the red battery wire will work.

It’s quite common to see one or two HC-SR04 ultrasonic sensors fixed to the front of a rolling robot, but we figure mounting one to the top of a servo motor adds a bit more character and interest.

Back in the Mk. I, we used double-sided tape to hold the sensor to the servo. For Mk. II, we’re recommending cable ties. Use the straight-edge arm from the servo motor accessories bag and align each arm under one of the sensors. Use a cable tie to wrap under the arm either side of the centre mounting point, up around the back of the printed circuit board either side of the four-pin header.

If you place the edge of the arm against the 4MHz crystal (the metal pill-like object at the bottom of the sensor circuit board), you can clamp it so that the ultrasonic sensor is sitting flat and flush against the servo motor arm. Pull the cable ties tight, but not ridiculously so – you want just a little flexing in the servo arm. Next, attach the servo motor arm to the motor shaft but don’t screw it down just yet – we’ll do that in a bit.

The last thing for the servo is to attach it to the chassis (double-sided tape for the moment) and connect the three-pin plug into the servo header pins on the shield – use the SERVO_2 (servo motor 2) input (note the polarity from the block diagram).

While the servo motor comes with its own three-pin jumper cable, you’ll need a four-pin female-to-female jumper cable for the ultrasonic sensor. You can buy a big pack of these on eBay for $2 or so – just carefully peel off four wires. These make detaching the sensor much easier than soldering wires into place.

STEP 5: Setting up the Motor Drive Shield

Some kits use brass spacers to raise the universal front wheel; others don’t.

We love this shield because it makes building a robot nice and easy. For this project, you do not apply any power to the Arduino directly – we connect it to the Motor Drive Shield instead via the power switch to the EXT_PWR terminal pair on the shield. Make sure you get the polarity right – the positive wire goes to the ‘+M’ terminal point, the black wire to ground (GND).

Right next to the terminal block, you should see a yellow jumper header with PWR written above it. This jumper links power from the shield to the Arduino – if the jumper header is missing, you can buy them as a pack of 10 from Jaycar (cat. HM3240) for $2 or so.

Use your hookup wire to connect the GM3 motors to terminal block pairs M1 and M4 (this caused a bit of confusion last time, but that’s been fixed). Don’t worry too much about the motor polarity at this stage – we’ll fix that during the testing phase.

STEP 6: Adding the power switch

As we mentioned, you need to add in a power switch. We recommend a SPST toggle switch, so again, grab some hookup wire, cut a short length just comfortably long enough to go from the switch to the ‘+M’ terminal on the EXT_PWR block input on the motor shield.

Solder the red wire from the battery holder and one end of your hook-up wire to the switch’s tags and use the screw clamp to anchor the other end into the ‘+M’ terminal. Finally, do likewise with the black wire from the battery holder to the negative terminal on the EXT_PWR terminal block. (We’ve used a DPDT (double-pole/double-throw) toggle switch to switch both battery leads – its complete overkill but we’re fans of using whatever you have in your ‘junk box’.)

Either way, whether you use an SPST or DPDT switch, polarity is vital here – reversing the polarity to the shield will likely blow up it and the Arduino.

STEP 7: Loading up the sketch

The Rolly Mk. II can use the R2 or R3 version of the Arduino Uno microcontroller.

As usual, you’ll find the software or ‘sketch’ for the Mk. II on our Arduino page. It’s designed for Arduino IDE version 1.0.5. Unzip the file, copy the contents of the ‘libraries’ folder into the /libraries subfolder of your IDE folder and load the .ino file into the IDE. Next, connect up the board via USB, select the Arduino Uno R3 and the correct COM port for your board and finally, upload the sketch to the Arduino.

STEP 8: Test drive

Do a last once-over of your wiring and make sure everything is where it should be. When you’re ready, load in four fresh AA batteries (alkaline, Lithium or NiMH rechargeables), flick the power switch and see what happens.

First up, the servo motor and sensor should align so the ultrasonic sensor is facing forward. If not, turn off the power and reposition the mount arm on the servo motor shaft so that it does. Now turn it back on and while the servo motor will ‘wriggle’, the sensor should now face forward. If so, install the tiny self-tapping screw into the centre of the arm down into the shaft to lock it into place.

Provided you have a clear path forward, the Mk. II’s first movement should be briefly forward before its direction sensing takes over. If it turns in left-hand circles, make sure your wiring is correct – it’s possible the left motor wire pair will be reverse. If you get right-hand circles, try reversing the right motor wiring.

Straight-line running

Use two cable ties to anchor the ultrasonic sensor to the servo motor arm.

Now some chassis kits will also include two circular slotted discs – these ‘encoder wheels’ fit over the inside motor axle and allow us to correct straight-line drift. However, since not all kits seem to include them, we’ll look at these another time.

Still, once Rolly Mk. II is up and running, you’ll want to make sure he’s running as straight as possible. Without the encoding wheels, we have no way of creating the ‘negative feedback’ or correction necessary for it to happen automatically. That means you’ll need to do it manually by changing the code in the marked area to adjust the motor speeds so they’re both equal. All things going well, you should really only need to do this once.

These GM3 gearbox motors are hugely popular and turn up everywhere – but they come in a number of gear ratios. The chassis kits we’ve seen include the 1:48-ratio version – these move quickly, but won’t have much torque to climb over (or bash through) obstacles.

That means they need to be set at near-to-full speed to ensure they don’t stall. We’d suggest purchasing a couple of 1:120-ratio motors as replacements rather than slowing the PWM speed too much if you want a slower bot.

Happy rolling!

If you get this far, congratulations! You’ve just built yourself an autonomous robot. Now, it’s your turn – try modifying the sketch and seeing what else you can make Rolly Mk. II do, or maybe even think about adding new features. Only your imagination is the limit! We’d love to hear what you get up to, so drop us a line in the comments below.

  • Marq Mitchell

    I have a quick question. I have the same exact setup however when the 2nd time the robot detects an obstacle it backs up then the servo keeps scanning like its moving forward but the wheels aren’t turning. then if i put something in front of it it will continue as normal. But then it does it again??? Any ideas???

  • Daniel Castaño

    Hi, Greetings. I connected the Rolly as indicated by the first version (APC_4_ROBOT). The servo sensor starts working but only begins to spin in a circle with one servomotor, it seems that the other work (right). Use the version for rolly mk ii (APC_17_RollyMkII_v3) and the sensor shakes only and does not rotate. Please help.

    Thank you. excellent project

  • Daniel Castaño

    Hello, I have problems with the project are that rotates one side (right) and the obstacles seem to place him not detected. Help please!

  • Ron Hoey

    Hi, thanks for an interesting project and for improving on the Mk1 Rolly.
    I found that the sensor did not function when I wired Rolly 2 according to the wiring diagram. When going through the code I found that the Trig & Echo wires are reversed in the code compared to the diagram.
    I switched them and all is well with my new little mate. Ron

  • Asociación Peruana “ASPAST” de

    Robot stop moving only when something is just right at the front of the sensor, if put something to the sides keep moving as normal. Problem is that when there is nothing on the sides robot just stop. So my questio nis if you have the code fixed in that case. Thank you for your answer.

    • Try swapping the trig and echo wires, just out of curiosity sake.
      Cheers,
      Darren.

      • Asociación Peruana “ASPAST” de

        Thank you for your reply, but I fixed the problem modifying the code at “moveStop”. Now my problem is that one motor goes faster than the other. When I change the cables, for example, from M1 to M2, the situation is that the faster former becomes the slower.

  • David Connolly

    Excellent tutorial. Went together quickly and is running well. Swapped trig and echo to get ultrasonic sensor in line. Echo to A4 and Trig to A5. I made some changes to the sketch and the bot is working more to my liking. Slowed it down just a little but still running well on the carpet with no problem. Changed line 12 to #define MAX_SPEED 200. Changed line 14 to #define COLL_DIST 30 and line 34 to delay(4000); I started with the 4 AA batteries but then I took them out and connected two 18650s 4200mAh in serial and getting great results. I’m looking forward to really taking this robotics hobby to the next level. Thanks Darren.

  • Khoirul Anwar

    excuse me,, when the robot is walking and found a barrier,, he did not
    stop and did not want to turn back or retreat, but to stay ahead!!,,
    I’ve been looking for a solution, but have not yet found
    I use a coding program (APC_17_RollyMkII_v3)
    please solution, Thanks :)