HackSpace – September 2019

(Jacob Rumans) #1
LENS

A SOLID BASE
To start, find yourself a piece of plywood or similar
to act as a base for your instrument. As you can see
in the photos, it needs to be wide enough that you
can mount the glockenspiel firmly at one end, and
long enough to also contain the arm, breadboard,
and Arduino.
Next, mount your Arduino and breadboard next to
each other on the base, with the Arduino’s USB and
power ports nearest the edge of the base.
Breadboards often come with a sticky underside,
making them very easy to mount. The Arduino can
be secured in place by screwing wood screws
through its mounting holes, but be careful not to
over-tighten them and crack the board.
On your newly secured breadboard, build the
circuit shown in the diagram above. The circuit
contains a button, which will be used to start and
stop the melody, and an LED, which is useful for
debugging (and aesthetics!).
The circuit also contains a 5-volt regulator chip.
The Arduino can’t provide enough current for our
somewhat chunky main servo, so we have to think
laterally. Our Arduino is going to be powered by a 9 V
mains transformer, which has plenty of current, and
the Arduino lets us access this 9 V power feed
directly, via the ‘Vin’ (voltage input) pin. The 5 V
regulator chip takes the 9 V input and steps it down
to 5 V, giving us enough power (at the correct
voltage) to run our servos. The capacitors are there
to keep the voltage stable – make sure you get them
the right way around.


FIRST MOVEMENT
Plug the 9 V power supply into the Arduino and turn
it on, before plugging the Arduino into your PC with
the USB cable. With a project like this, that requires

external power to drive motors, it is important to
make sure that there is always external power
available to the Arduino. Throughout this project,
make sure that you don’t turn off the external power
unless you have already unplugged the USB cable,
otherwise the Arduino will attempt to power the

motors via USB, which provides insufficient current
and could cause damage.
With the servos connected, as shown in the
diagram, and the external power supply turned on, try
out the Arduino example sketch found in File >
Examples > Servo > Sweep. Upload the sketch to

Above
;he  = raiS is Med
MroT a = Tains
transMorTer ]ia a  =
]oStaNe reNuSator

A servo is a special type of motor which has a built-in feedback mechanism, meaning that
the motor ‘knows’ its current position (or, sometimes, speed). Our servos read a signal from
the Arduino and then move to a particular angle, between 0° and 180°. The Arduino sends a
pulse of a specific length, and the servos interpret this as an angle and rapidly move to the
correct position.
You don’t need to worry about what pulse length to send, because there is a ready-made
library called ‘Servo’ which handles all the calculations. You just need to tell the Arduino
which motor is connected to which pin, and what angle you want each motor to move to.

Controlling servos


The circuit contains a


button, which will be


used to start and stop


the melody, and an LED


Quick Tip


This project assumes
some basic knowledge
of the Arduino platform


  • if this is your first
    time playing with an
    Arduino, start here:
    hsmag.cc/iSwUtN.

Free download pdf