Modules
In mechatronics, we have the option to construct our circuits from the
basic components described in the previous chapter, but we have more
convenient options.
We often work at the level of Modules,or pre-assembled collections of
components engineered to do a particular job.
The modules we use are usefully classified into several kinds:
- Input modules which sense some property of the physical world
and express it as electricity. For example switches, temperature
sensors, tilt sensors and touch screens.
- Output modules which convert electricity into a physical
effect, such as light, motion, sound or video display screens as found in
phones and TVs.
- Compute modules which can interpret and control the action of
other modules. A compute module will have a Microprocessor
(which carries out Computations (Instructions) encoded in a Program) and some
Memory which stores information (including the Instruction Program itself).
The creative act of mechatronics is to combine a power source, a
compute module, some input and output modules and a program, to
produce something (literally Some Thing) which carries out the
instructions that we have placed into the Program, responding to
Inputs to produce Outputs.
Input modules, like our own eyes ears and fingertips, convert aspects
of the physical world into electrical impulses.
The simplest ones simply produce a voltage in response to stimulus,
often using high voltage (5V) and low voltage (0V) to mean “yes” and
“no” (or True and False, One and Zero). In our instruction programs
we see these inputs as a value of One or Zero, so we will use these
terms here.
The simplest sensors have three pins, two power pins and one signal
pin, which expresses the sensor’s output as Zero or One. More
complicated sensors may have multiple output pins, or transmit a
“bit-serial” signal (something like the flashing of Morse-code) over a
single pin.
Since all voltages are really an expression of the differing electric
charge at two points, we describe the pin voltage in relation to the
poles of the power supply. We call the voltage of the power supply’s
negative pole variously “V-, Zero volts, 0v, Low, or Ground”. We
call the voltage of the other poll “V+, High, or Vcc” (the latter
for tiresome historical reasons involving the pre-integrated-circuit
transistor-based computing circuits of the 1950s and 60s).
You will see the power pins marked GND and VCC on many modules.
The kinds of input modules you may encounter include:
- Button
- A single switch that gives Zero when not pressed and 5v when pressed.
- Light sensor
- A light-sensitive element along with some filtering circuitry which
produces a Zero when “dark” and One when “lit” (often with a little
knob to adjust the transition between the two to suit your
circumstances).
- Temperature sensor
- A sensor that produces a voltage proportional to temperature, or
sends a number encoded as a bit-serial transmission. Temperature
sensors are sometimes part of modules that monitor other atmospheric
conditions.
- Digital Temperature and Humitidy (DHT)
- A sensor that measures temperature and humidity
- Barometer
- A sensor that reports atmospheric pressure (and often temperature
also)
- Dial
- A sensor that reports the position of a dial (like the volume knob
on a car radio)
- Slide
- A sensor that reports the position of a sliding knob. Two slide
sensors may form a “Joystick” as used on video game controller pads.
- Sonar
- A sonar sensor can be used to measure distances by observing the
echoes of an ultrasonic (high-frequency) audio signal
- Infrared object sensor
- Infrared sensors can be used to measure the presence of an object
(or distinguish between light and dark objects)
- Capacitive Touch sensor
- These sensors measure the electrical field around a touch plate, and
detect changes in the field that indicate the presence of a human
body. They are essentially a very sensitive button that requires
no pressure to activate, merely the presence of a finger. They can
work through glass.
- Touch screen
- Touch screens are a grid of sensors (sometimes capacitive, sometimes
measuring the resitance between two adjacent films) that can
pinpoint the location of a touch point in front of a screen. They
provide direct correlation of user input relative to a displayed
video image.
- Accelerometer (tilt sensor)
- These sensors measure the direction of acceleration. This can be
used to detect tilting (as in some game pads) or shaking (eg the
shake-to-undo idiom on iPhones)
Output modules
Output modules require power and at least one signal input. The
simplest convert a Zero or One into some event (light on, light off)
others may require complex commands to be sent either over multiple
pins, or in a bit-serial fashion over one or a few pins.
Some output modules are
- Light Emitting Diodes
- These modules combine an LED and the necessary other components to
regulate its brightness (often a resistor). Multi colour LEDs are
sometimes merely three primary coloured LEDs on one module, or a
small circuit which accepts commands to control brighness and colour.
- Servo motors
- These motor-and-gearbox contraptions can turn through 180 degrees,
and their position is relative to the duration of a high voltage
pulse sent to their input pin.
- LED Strings
- A series of LEDs that can be controlled by a single pin, by sending
complex control pulses
- Screens
- A grid of LEDs (or a liquid-crystal grid in front of a backlight)
that can display text and/or pictures.
- Speakers
- Produce beeps or sounds
- Relays
- A relay consists of a coil of wire that forms and electromagnet, and
a switch that is actuated by the magnet. This allows our
low-voltage (5v or 3v) circuit to turn on 220v appliances without
being directly connected to them (for safety).
- Solid-state relays (and motor drivers)
- Powerful transistors can be used to produce the same effect as a
relay. Since these can switch on and off very quickly, they can be
used to control motors very accurately (including changing speed and direction).
Compute Modules
Our desktop computers consist of inputs (keyboard, mouse,
touch-screen etc), outputs (screen, printer etc) and a “brain” (the
Central Processing Unit (CPU) along with several kinds of Storage
(Memory chips, disk drives)).
A microcontroller shrinks the whole computer down to a single module.
Often the CPU and memory are on a single integrated circuit.
The most popular microcontroller module for enthususiasts is the
Arduino, and its derivitives including the Lilypad. We’ll go deeper
into the Arduino later.
Connecting Modules
Computers do all their thinking with binary logic (ones and zeros),
and represent binary logic in the physical world using voltage. A
logical one is high voltage, a logical zero is no voltage. When a
computer talks to another computer or a peripheral device, there’s one
or more wires which are either at high voltage or low voltage. That’s
basically all there is to it. Skip the rest of this section if you
like.
For a long time, most computers used 5 Volts as the standard high
voltage. As computers became faster and used more power, the industry
shifted toward 3.3 Volts as the standard voltage.
Some of the modules we will be using follow the 3.3 Volt convention,
but you should be aware that a lot of stuff still uses 5 Volts, and
some 3.3 Volt equipment will be damaged (possibly fried) if given 5
Volts where it expects 3.3 Volts. There are inexpensive conversion
circuits that you can use where you need to connect 5 Volt signals to
devices that may be harmed by voltages above 3.3 Volts.
Serial communications
So far we have discussed only the simplest input and output, switches
and lights are from the point-of-view of a microcontroller
communicating only a single binary digit — one ‘bit’ — of
information, something is either on or off. More complex information
can be communicated in two ways: by using multiple pins, or by using
one pin (or a few pins) as a serial communication bus (that is, where
a multi-digit number is transmitted by sending as a series of digits,
one digit, then a pause, then the next digit and so on)
There are a couple of different ways of making a serial bus, from most
to least complex these are:
- USB (Universal Serial Bus)
- this very popular for full-sized computers but generally too complicated for most
micro-controllers and modules to understand
- Asynchronous serial
- this is an ancient protocol once commonly used for modems and
printers, and still used to program many microcontrollers. Often
simply called “serial”, “TTL serial” or “RS-232”.
- I2C (Inter Integrated-Circuit bus)
- This uses two pins (a clock and a bi-directional data pin). This is
often used to talk to sensors and simple displays.
- SPI (serial peripheral interface)
- this uses one pin in each direction plus some clock signaling and device identification pins. It’s often used to talk to graphical display modules, sensors and memory cards.
- OWB (One-wire bus)
- this uses a single pin that acts as clock and bi-directional data; it’s slow but cheap. A popular temperature sensor is the best known use.
- Various simple proprietary signalling mechanisms
- Some devices use a home-made signalling protocol (eg send a 1 on
this pin for 25 milliseconds, then time how long until a
high-voltage appears on some other pin). Fortunately these are rare.
- Just One Or Zero
- The simplest sensors need no signalling scheme, they merely signal YES
or NO using high or low voltage, and the microcontroller is free to
examine the voltage at any time.
The good news is that most microcontrollers have built-in hardware
and software to communicate with several of these technologies. As
long as you know which protocol a particular device module expects,
you should be able to talk to it without knowing too many of the gory details.