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.8 28 May 2019
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 for parts bought in the UK or USA is around £40 in the UK or $100 in New Zealand. If you buy the parts from AliExpress.com the total cost is about $US14 ( £11 or $NZ20).
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 a starter kit, 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. A good place to buy it in the UK is Hobby Components. The price, including the required USB A to B cable, is £12.50 including VAT. Alternatively you can buy it from AliExpress.com for about $US7.50. An example is here.
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. Arduino 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 is definitely preferable to Version 1. It can be obtained from Adafruit at a price of $US19.95 (about £12). I recommend also obtaining a set of stacking headers, which will need to be soldered to the shield.
A clone of this shield, which does not require soldering, can be obtained from AliExpress.com for about $US4.50 (£3.50), for example here. You would need to download the free software from the Adafruit web site, as described below.
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 AliExpress.com The price is $US1.33 (about £1). The shield comes as two separate boards, which will be plugged into the Arduino headers on either side. Its headers pass through the SCL and SDA signals, which were added in the R3 versions of the Arduino. However it does not provide terminals for these signals, and I have not been able to find any shield at AliExpress.com which does. The Adafruit shield does provide terminals for these signals.
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) or here (AliExpress.com). No doubt you will have more use for the iron when you come to connect motors, LEDs etc.
Installing the headers in the Adafruit 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. The shield from AliExpress has stacking headers installed and does not require any soldering.
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 2 shows a two-part shield installed. Then plug the motor shield into the terminal shield. Your system is now complete, as shown in Figure 3.
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) or here (AliExpress.com).
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 4.
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 a starter 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. Several are available from Amazon.
• 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: