Printed from www.nzmeccano.com
Buying and Building an Arduino System
(Author: David Couch)
Buying and Building an Arduino System
by David Couch, Nelson, New Zealand
Version 1.5 3 December 2015
This document describes a microcontroller system that is suitable for controlling Meccano models. It consists of an Arduino microcontroller board, a motor control shield and a terminal shield. In the process of designing this system I have bought and tested several components of each type, from several suppliers. I have come to the conclusion that the system described here provides all the functions you are likely to need at the lowest cost. The total cost is around £40 in the UK or $100 in New Zealand.
What is a shield?
A shield is a circuit board which piggybacks on the Arduino board. It has male headers, or pins, which plug into female headers, or sockets, on the Arduino board, making all the required connections. Figure 1 shows an Arduino Mega with a shield plugged into it. A large range of shields with many different functions is available.
What is a motor shield?
What is a terminal shield?
The Arduino has many input and output connectors in the form of pins, which do not make convenient or reliable connections to external devices. A terminal shield or screw shield provides a small screw terminal connector for each pin, so that wires from switches, potentiometers, LEDs etc can be easily and securely connected without soldering.
What can I connect to the Arduino system?
If you build the system described here, you can connect all of these:
Motors: four DC motors or two stepper motors can be controlled, with variable direction and speed. More can be added if a second motor shield is installed.
Servos: two standard or continuous rotation servos can be connected through the motor shield. Many more servos can be controlled by the Arduino with some additional circuitry.
LEDs (light emitting diodes): up to 12 LEDs can be connected and individually controlled through the terminal shield, with variable brightness if desired. Many more can be connected with additional circuitry. Larger groups can be controlled using the motor connections.
Switches: these can be hand-operated toggle or push-button switches, or microswitches, tilt switches or magnetic switches activated by the model. Up to 12 switches can be connected and read through the terminal shield. Many more can be connected with additional circuitry.
Joysticks and Potentiometers (variable resistors): up to six potentiometers can be connected and read through the terminal shield. More can be connected with additional circuitry. A joystick usually contains two potentiometers and possibly one or more switches. Up to three joysticks can be connected.
Relays: if relays are required to control high-current or high-voltage devices such as lamps, a four- or eight-relay module can be purchased and controlled by the Arduino.
Details of how to physically connect devices to the Arduino are given in my document Arduino Programming Reference. If you are interested in the extensions and additional circuitry mentioned above, please send me an email message.
What to buy and where to buy it
If you have bought an experimenter’s kit with an Arduino Mega, as I recommend in my introductory document, then of course you already have this.
The Arduino comes in several different formats, with different capabilities. The Uno is the standard entry-level Arduino, and probably the most popular. However, I recommend the Mega, the largest Arduino, because for just a small extra cost it offers much more memory and many more I/O pins.
The current model is called Arduino Mega 2560 R3. The best place to buy it is Hobby Components in the UK. The price, including the required USB A to B cable, is £12.49 including VAT.
The Arduino you buy from any source may be an original, or a clone or “compatible”. You should not be concerned about buying a clone. The Arduino is an open design, which other manufacturers are free to copy. Clones are not pirated or unethical, and as far as I know they are functionally identical to the Arduino originals.
I recommend the Adafruit Motor/Stepper/Servo Shield for Arduino V2, as it is the only shield I have found that can control four DC motors or two stepper motors. Version 2 of this shield has recently been released, and is definitely preferable to Version 1. The only place where Version 2 can be obtained at present is Adafruit. The price is $US19.95 (about £12). Several other web sites offer motor shields which are clones of either the Adafruit Version 1 shield or the Arduino motor shield, which can control only two motors.
I recommend the Proto-Screwshield R3 from Adafruit. It costs $US14.95 (about £9) and comes as a kit which requires soldering.
An alternative which does not require soldering is a terminal shield from Tinysine Electronics. The price is $US7.95 (about £4.70). The shield comes as a single board with a groove down the centre. It needs to be snapped at this groove into two separate boards, which will be plugged into the Arduino headers on either side. It has very long pins, which make it sit high above the Arduino. I cut 5 mm off each of the pins, so that it sits snugly on the Arduino headers.
Assembling the Arduino system
If you do not already own a suitable soldering iron, I strongly recommend that you buy a soldering station such as the one shown here (UK) or here (NZ). No doubt you will have more use for the iron when you come to connect motors, LEDs etc.
Installing the headers in the motor shield
The Adafruit web site gives instructions for installing headers, terminal blocks for the motor connections and headers for servos and the power jumper. However with the latest kits all you need to do is to install the four strips of headers around the edge of the board. These have been left so as to give you the choice between simple male headers and stacking headers, which allow you to stack another shield on top.
Please note the following points:
• On the side with the digital pins you need one 8-pin header strip and one 10-pin strip, which includes the SDA and SCL pins. See Figure 2.
• On the other side, one 8-pin and one 6-pin strips are shown. Replace the 6-pin strip for the analog pins 0 to 5 with a 4-pin strip and solder it into holes 0 to 3, so that there are no pins in the analog 4 and 5 holes. This prevents the motor shield from interfering with the operation of the analog 4 and 5 pins on the Arduino board. See Figure 3.
Putting the system together
First plug the terminal shield into the Arduino Mega, taking care that the headers are aligned correctly and no pins are bent. Figure 4 shows the two parts of the Tinysine shield installed. Then plug the motor shield into the terminal shield. Your system is now complete, as shown in Figure 5.
Getting started with the Arduino software
Instructions for getting started with the Arduino software are here. You will download and install the Arduino environment on your computer, connect the Arduino to it, install the drivers, launch the Arduino application, open an example sketch (program) called blink, upload the sketch to the Arduino and see it run.
Installing the Adafruit motor shield software
Next download and install the software for the Adafruit motor shield, following the instructions here.
Supplying power to the Arduino
There are several ways to supply power to the Arduino.
The USB cable that you use to connect the Arduino to your PC to upload sketches also provides power to the Arduino. It carries enough power to run the Arduino itself and a few attached devices such as an LED, a servo or even a motor for running the example sketches. It cannot provide enough power to run motors that power models.
Once a sketch has been uploaded to the Arduino, the USB cable can be disconnected, and the sketch will be retained in the Arduino’s flash memory, even when the power is turned off. The sketch will start to execute whenever the Arduino is powered on or reset.
For static models I prefer to use power supplies of the type which plug into a wall socket, known as plugpacks or wall-warts. Choose a regulated power supply, as unregulated ones can output a much higher voltage than their rating. The most useful type has the output voltage selected by a switch, usually with a range of 3 to 12 volts. An example can be seen here (UK) or here (NZ).
The power connector on the Arduino is a 2.1 mm centre-positive coaxial power connector or barrel connector, which is the type of connector commonly provided with plugpack power supplies. The input voltage can be in the range 7 to 12 volts, but it is best to use 7.5 or 9 volts. If you are using a power supply with interchangeable connectors, make sure the 2.1 mm barrel connector is oriented for the correct polarity, i.e. centre positive.
If the second power supply has a barrel connector, you can connect it to the terminals using an adapter like the one shown in Figure 6, which was bought from Jaycar.
For vehicles or for exhibition models it may be preferable to power the Arduino with batteries. Again there is a choice between using a single battery, with the motor shield power jumper installed, or two separate batteries, with the jumper removed. The battery used to power the Arduino should be a 7 to 9 volt one, consisting of six AA size or larger cells. Nickel metal hydride (NiMH) rechargeable batteries are suitable, though they give only 1.2 volts. For the motors you can use any battery of your choice from 4.5 to 13.5 volts. A sealed lead-acid battery will probably give the longest running time.
Programming the Arduino
If you bought an experimenter’s kit you will have already learned quite a lot about programming the Arduino. Whether or not you have done this, you should investigate and use all of these resources:
• A book on programming the Arduino. A good book can be downloaded free from here.
• The example sketches provided with the Arduino and Adafruit environment software which you have installed. In the Arduino program, in the File menu, click Examples to see the various categories of examples. It is a good idea to load and run some of the example sketches, and you can learn a lot from reading and modifying them.
• The Arduino language reference. In the Arduino program, in the Help menu, click Reference.
• The Arduino web site, which has loads of information and support.
• The Adafruit web site. Information on the motor shield, including the library reference, can be found here. (See the links on the left of the page.)
• My document Arduino Programming Reference, which provides a convenient reference for the code needed to control the various devices you are likely to connect to your Arduino.
The Arduino site
Sites with Arduino boards, shields and accessories
These are just a few of the many sites which offer shields and other devices for use with the Arduino. Browsing these sites will give you an idea of the great variety of controllers and sensors available, and how cheap they can be.
http://www.ebay.com (Use the search facility.)
I welcome additions, corrections, comments and questions related to the Arduino and Meccano. My email address is firstname.lastname@example.org
If you have any interesting information or comments about this page, please add them here: