Silicon ChipThree Arduino Motor Driver Shields - October 2019 SILICON CHIP
  1. Outer Front Cover
  2. Contents
  3. Publisher's Letter: Encouraging chip developments
  4. Feature: History of Cyber Espionage and Cyber Weapons, Part 2 by Dr David Maddison
  5. Project: 45V, 8A Bench Power Supply to build by Tim Blythman
  6. Feature: Two new Arduino Nanos: the “Every” and the “33 IoT” by Tim Blythman
  7. Product Showcase
  8. PartShop
  9. Project: High resolution Audio Millivoltmeter/Voltmeter by Jim Rowe
  10. Feature: Three Arduino Motor Driver Shields by Tim Blythman
  11. Serviceman's Log: A shockingly cute new companion by Dave Thompson
  12. Project: Solving one of Home Automation’s biggest beefs! by Tim Blythman
  13. Project: Precision Audio Signal Amplifier by Jim Rowe
  14. Subscriptions
  15. Vintage Radio: Healing M602T transistor mantel radio by Ian Batty
  16. Market Centre
  17. Advertising Index
  18. Notes & Errata: Six-decade Resistor Sorter, September 2019; Gamer’s Simulation Seat, September 2019; Voice Modulator for Sound Effects, August 2019; Vintage Radio - National AKQ, July 2019; 433MHz Data Range Extender, May 2019; High power H-bridge, November 2017; RGB to Component Video Converter, October 2004
  19. Outer Back Cover

This is only a preview of the October 2019 issue of Silicon Chip.

You can view 39 of the 112 pages in the full issue, including the advertisments.

For full access, purchase the issue for $10.00 or subscribe for access to the latest issues.

Articles in this series:
  • History of Cyber Espionage and Cyber Weapons, Part 1 (September 2019)
  • History of Cyber Espionage and Cyber Weapons, Part 1 (September 2019)
  • History of Cyber Espionage and Cyber Weapons, Part 2 (October 2019)
  • History of Cyber Espionage and Cyber Weapons, Part 2 (October 2019)
Items relevant to "45V, 8A Bench Power Supply to build":
  • 45V/8A Linear Bench Supply PCB [18111181] (AUD $10.00)
  • FJA4313OTU 15A NPN transistor (Source component, AUD $10.00)
  • LM317HVT regulator and INA282AIDR shunt monitor IC for 45V 8A Linear Bench Supply (Component, AUD $15.00)
  • 3mm acrylic heatsink spacer for High-power Linear Bench Supply (PCB, AUD $2.50)
  • High Power Linear Bench Supply PCB pattern (PDF download) [18111181] (Free)
  • High Power Linear Bench Supply panel artwork and drilling/cutting diagrams (PDF download) (Free)
Articles in this series:
  • 45V, 8A Bench Power Supply to build (October 2019)
  • 45V, 8A Bench Power Supply to build (October 2019)
  • Digital Panel Meter/USB Display suits a range of projects (November 2019)
  • High performance linear power supply – part two (November 2019)
  • Digital Panel Meter/USB Display suits a range of projects (November 2019)
  • High performance linear power supply – part two (November 2019)
  • High performance linear power supply – part three (December 2019)
  • High performance linear power supply – part three (December 2019)
Items relevant to "High resolution Audio Millivoltmeter/Voltmeter":
  • High Resolution Audio Millivoltmeter PCB [04108191] (AUD $10.00)
  • Arduino sketch for the High-Resolution Digital Audio Millivoltmeter (Software, Free)
  • High Resolution Audio Millivoltmeter PCB pattern (PDF download) [04108191] (Free)
  • High Resolution Audio Millivoltmeter lid panel artwork and drilling diagrams (PDF download) (Free)
Items relevant to "Precision Audio Signal Amplifier":
  • Precision Audio Signal Amplifier PCB [04107191] (AUD $5.00)
  • Precision Audio Signal Amplifier PCB pattern (PDF download) [04107191] (Free)
  • Precision Audio Signal Amplifier lid panel artwork and drilling diagrams (PDF download) (Free)

Purchase a printed copy of this issue for $10.00.

Arduino Motor Driver Shields Are you building an autonomous robot or vehicle, or perhaps a CNC mill? You’ll need motors and something to drive them. In this article, we take a look at three motor driving Arduino shields that could form the heart of your next ‘mechatronics’ project. by Tim Blythman I n the February 2019 issue, we described how to use three different stepper motor driver modules (siliconchip.com.au/Article/11405). Stepper motors are great for precision control, such as is needed for a CNC machine or 3D printer, but they are slow and power-hungry, and do not suit every application. Even in CNC machines, a conventional brushed DC motor may be used for tasks such as spinning the cutting tool or raising and lowering the platform. A simple DC brushed motor (probably fitted with a gearbox) will turn faster and with much more power than a stepper motor, at a much lower cost. They’re also pretty easy to control. To control these types of motor from a microcontroller, a different kind of driver circuit and control module is needed. To drive a brushed DC or universal motor in either direction, we need a so-called H-bridge. All three Arduino shields described here use different integrated H-bridge driver ICs. It’s called an H-bridge because its logical configuration resembles the letter “H” in shape. You will see this resemblance if you take a look at Fig.1. This shows the four useful states of an H-bridge. In the three shields described here, the entire H-bridge funcsiliconchip.com.au tion, including control and switching elements, is incorporated entirely within a single chip. A shield is a module that can plug directly onto an Arduino-compatible main board, removing the need to wire it up pin-by-pin. Of course, the shield format locks in a specific pin allocation which cannot be easily changed, but that is not usually a problem. For example, all these shields are designed to work with an Arduino Uno, but subsequent Arduino R3 format mainboards (eg, the Leonardo and Mega) place PWM capable pins at similar locations, meaning they should work with those host controllers too. But note that other boards may not have been designed with the appropriate pin placements in mind and may not work, even if the shield will physically plug into their headers. It’s because of this Arduino-specific pinout that we won’t delve into how these modules can be controlled with a Micromite. It’s certainly possible, and we recommend that you look at our Arduino code samples if you’re thinking of interfacing any of these with a Micromite. Interestingly, one of the shields makes use of an L298 IC. This IC (in a different package) was also used in Australia’s electronics magazine one of the stepper motor drivers we reviewed in the February article on stepper motors mentioned above. We noted at the time that the module being described could also be used to drive a pair of brushed DC motors. However, the reverse is unlikely to be true; we don’t think any of these modules would make good stepper motor drivers. But one great thing about all three of these shields is that they have outputs capable of driving two DC motors in either direction with varying speeds. One of the shields can control four motors. It is handy to be able to control two or more motors as that allows skidsteer control (like a military tank or other tracked vehicle) to be implemented. While that has some disadvantages, it is elementary to implement in hardware as there are no complicated steering linkages or mechanisms. Skid-steer also provides the option to turn on the spot. Shield 1: Monster Moto shield The first shield is labelled as a Sparkfun “Monster Moto Shield”. Sparkfun is a company based in the USA which has been designing and selling Arduino parts for many years. Many of these designs have been copied, including, we suspect, the Monster Moto Shield. Fig.1: four of the five possible configurations of an H-bridge; the fifth is the same as (d) except that the braking current flows in the upper loop, which provides no real benefit. In each case, the voltage across the motor and the current flow path is shown, assuming a nominal 12V DC supply. In case (d), the current flow direction depends on the direction of motor rotation at the time of braking. The switches can be Mosfets, bipolar transistors, IGBTs or even relay contacts. Unlike the other two shields in this article, the Monster Moto Shield was not supplied pre-fitted with headers. This can be handy, as you may wish to choose between stackable headers and male headers, although the height of the capacitors on this board would probably not leave enough clearance for another board to be fitted above. We fitted our unit with male pin headers for our tests. The two chips which provide the motor driver function take up around one-third of the board space between them. They are two ST Microelectronics VNH2SP30 ICs, which provide the interface between logic level signals and the motors. Apart from these, there are two 35V 470µF bypass capacitors, two Mosfets and an assortment of tiny surfacemounted components. The full circuit diagram for this shield is shown in Fig.2. The VNH2SP30 ICs The Monster Moto shield is quite simple, although it has quite a few tiny SMD components. If necessary, the driver ICs could be heatsinked by the addition of self-adhesive PGA heatsinks such as Jaycar Cat HH8580. The red wire was added to allow the shield to be powered from the attached Arduino’s DC jack for testing at modest power levels. 62 Silicon Chip According to the data sheet of the VNH2SP30, this chip can handle up to 30A at 41V with PWM control at up to 20kHz. These are absolute maximums; in practice, they are difficult to achieve with this board, due to its lack of heatsinking. The 41V limit is also a bit misleading, as the datasheet says that the maximum sustained operating voltage for the IC is 16V. Two VNH2SP30 ICs are provided on the shield, and each IC implements a full H-bridge, meaning that two motors can be driven bi-directionally by the shield. Operation is typical for this sort of IC. Two inputs (INA and INB) deterAustralia’s electronics magazine mine the direction of rotation, and a third input can be fed with a PWM signal that modulates the outputs, allowing for speed control. When input INA is high and input INB is low, the motor rotates in one direction with a speed related to the PWM duty cycle. If INA is low and INB is high, the motor rotates in the other direction. If both inputs are high or both inputs are low, the motor is braked. The chip provides current sensing and fault detection, and these signals are fed to pins on the shield for processing by an attached Arduino board. The EN pin functions as an enable input, and is pulled up by a resistor on the shield during normal operation. An internal fault condition will cause this pin to be pulled to ground, disabling the device and alerting a connected microcontroller via pin A0 or A1. These pins can also be driven low to achieve the same shutdown effect for each driver IC. There is also a CS pin (current sense, not chip select) which sources a current proportional to the motor current. A resistor on the shield converts this into an analog voltage, which is smoothed by an RC network before being connected to an analog pin on the shield (A2 or A3). This allows the motor currents to be measured by the attached Arduino’s analog-to-digital converter (ADC) peripheral. Other important components Apart from the main driver ICs, a pair of 470µF 35V capacitors bypass the motor supply voltage. Two Mosfets, along with a resistor and zener siliconchip.com.au Fig.2: the circuit of the Monster Moto shield is quite minimal. The reverse protection circuit comprising Mosfets Q1 & Q2, zener diode ZD1 and the associated 100kW resistor is taken directly from the VNH2SP30 data sheet. diode, provide reverse polarity protection to the driver ICs. The ICs are only powered when a voltage of the correct polarity (and above the Mosfet’s threshold voltage) is applied. There are five LEDs to provide a power-on indication for the shield as well as power and direction indication for the two bridge outputs, and thus any connected motors. Series resistors between the Arduino pins and the control inputs of IC1 & IC2 protect those ICs should the Arduino try to send control signals when the motor power supply is absent, and pull-downs on the PWM pins mean that the motors will not turn if the pins are not being driven siliconchip.com.au (eg, while the Arduino is being programmed or reset). Using it Table 1 shows the I/O pin connections between this shield and an attached Arduino. They are mostly wellchosen, with the PWM control pins being connected to PWM-capable outputs on the Arduino. The analog pins are carefully chosen to avoid pins A4 and A5, which are multiplexed with the hardware I2C function on Uno (ATmega328 chip based) boards. It’s apparently quite an old design as it lacks the header locations for the dedicated I2C pins near AREF, and thus appears to predate the Uno R3. This should not cause any problems Australia’s electronics magazine unless you need to stack multiple shields. The easy fix is to attach this shield to the top of the stack. The use of digital pin 3 may be problematic if this board is to be used with a Leonardo, as the hardware I2C function is found on pins 2 and 3 on that controller. Other 5V boards (such as the Mega) should be fine, as they do not have these sort of conflicts. The VNH2SP30 data sheet indicates a 3.25V minimum input level for the logic level pins, meaning that operation may be borderline on 3.3V microcontrollers like the Micromite. Power Power for the motors is brought in through a pair of large solder pads at October 2019  63 one end of the board. The GND connection is common with the Arduino’s GND, but there is no connection to the VIN connection on the Arduino shield. This means that you have to apply external power to test the board. A wire could be soldered to the board if the Arduino’s power needs to be fed from the shield. We soldered a wire from the Arduino’s VIN pin (on the shield) to the shield’s positive supply to allow us to test with a 12V plug pack feeding the Arduino’s DC jack. This obviously only allows modest current levels, but we were able to test our demonstration sketch. The other two shields we’ll describe later have a jumper to allow this connection to be made or broken without soldering. Also, the input power connection sits directly above the ICSP header, so care must be taken that the power connections do not bridge to this header when the shield is plugged in. Similarly, the motor outputs come out near the USB socket end of the board. The connections for motor two come close to the USB socket. They don’t appear to touch it, but attached wires may do so. We applied some electrical tape to the top of the USB socket on our Arduino board to avoid mishaps. Sample code Our sample code (MonsterMoto_ Demo.ino) allows direct control of each motor’s speed using commands in the Serial Monitor. Enter a letter (“A” or “B”, for the motor output), followed by a number between -255 and 255 for the motor speed. Negative values give rotation in the opposite direction to positive values, and higher values give faster rotation. The code also prints the raw analog values from the CS (current sense) pins to the Console every 200ms. The current sensing on the CS pin has a nominal output ratio of 11,370, meaning that a current of 11.37A or 11,370mA from the driver would result in a 1mA current from the CS pin. This passes through a 1.5kW resistor to convert it into a voltage suitable for the Arduino’s ADC. The ADC can read a maximum of 5V, which corresponds to 3.33mA through the sense resistor or a nominal 37.9A (3.33mA × 11,370) at the driver output. Given that there are 1024 steps in the 64 Silicon Chip ADC output, each step corresponds to around 37mA of motor current. Shield 2: FunduMoto shield The FunduMoto is a bit of a contrast to the basic-but-powerful Monster Moto shield. The top of the shield is more tightly packed with components. Not surprisingly, it boasts a more diverse range of features and options. Its circuit diagram is shown in Fig.3. CON1 and CON2 provide two different options for wiring up the motors, while CON3 is for the motor power supply and JP1 (labelled “OPT” on the board) allows the Arduino’s VIN rail to power the motors. The shield also sports a buzzer and several extra headers. It is well-suited to form the basis of a small robot project, as these headers allow other modules and motors to be easily and directly connected to the shield. The buzzer is quite loud and shrill. It’s almost too alarming to be used for anything but a genuine emergency, as it’s unbearable to have it running for too long. CON4 and CON5 can be used to connect two servo motors, eg, for steering control. These are controlled by pulses from digital outputs D9 and D2 respectively, and the pin-outs suit many standard servos. CON6 and CON7 are designed to allow two different types of Bluetooth modules to be connected, for remote control and feedback. CON8 allows just about any RGB LED to be driven from the Arduino. CON9, labelled “ping”, suits certain ultrasonic distance sensor modules (similar to those we reviewed in December 2016; see siliconchip.com.au/ Article/10470). Such a sensor could be used by a robot to detect if it is about to run into something and act to avoid a collision. If the ultrasonic distance sensor could be mounted to the rotating head of a servo motor, then the robot can detect not only what is straight in front of it, but scan its surroundings by rotating the servo motor via CON4 or CON5. Its maximum supply voltage is 46V, and it can source or sink up to 2A continuously on each channel. The maximum PWM frequency is 40kHz. The bypass capacitor on the shield is only rated to 25V, so this limits the maximum supply voltage you can apply. Note that most Arduino boards can only handle up to 20V on their VIN pins (some only 15V, depending on the voltage regulator fitted), so there are multiple factors to be considered when using this shield with motor supply voltages above 15V. The L298 IC has provision for a shunt resistor to be used to measure motor current, but this has not been taken on the shield, meaning motor current cannot be easily measured. To add this would involve lifting two of the IC’s pins (pins 2 and 19) and fitting a shunt resistor between these pins and ground. Some signal conditioning components (eg, an RC filter or similar) would also be needed to average the current throughout a PWM cycle, if you want current feedback. Free-wheeling diodes are recommended for the outputs of the L298, to absorb back-EMF spikes and also energy generated by the motor as it runs down; these are fitted, although they are M7 silicon diodes (D1-D8; equivalent to 1N4007) instead of the recommended fast-recovery schottky The L298P IC The driver IC on this shield is an L298P, which is the same one used in our stepper motor article, mentioned earlier, but in a different package. The L298P includes two full-bridge motor drivers, so can drive two motors bidirectionally. Australia’s electronics magazine The FunduMoto shield looks complicated, but much of the space is taken by headers for sensors and the motors. The L298P has a large body which could accommodate a heatsink. The 2x6 2mm pitch header is for an obscure automotive Bluetooth module. siliconchip.com.au Fig.3: the FunduMoto shield circuit shown here includes two motor driver ICs, numerous headers plus eight free-wheeling diodes and a tactile pushbutton switch (S1) which can be used reset the attached Arduino processor board. siliconchip.com.au Australia’s electronics magazine October 2019  65 diodes, which means they will run hotter. This shield also appears to predate the Arduino Uno R3 layout, so any R3 shields should be stacked below this shield to ensure that necessary connections are made. Other components The L298 has two inputs per motor channel for direction control. On this shield, complementary drive signals are generated by a pair of tiny 74HC1G04 single inverter ICs (IC2 & IC3). While this reduces the number of I/O pins needed to control the motors, it removes the option of driving both inputs low to force dynamic braking. This is a factor in making this shield less suitable for driving stepper motors, as it is harder to generate some intermediate step positions without braking. CON10 allows a three-wire analog sensor (with GND, 5V & OUT connections) to plug straight in. You can also use this header to tap off 5V power, ground or make a connection to one of the analog pins. The shield also has an onboard reset button, in case you can’t get to the one on the Arduino. Using it The VIN pin supplies power to the Arduino board’s 5V voltage regulator, similar to power being applied to its DC jack. In spite of this, it’s not a good idea to feed power in through the DC jack to the attached shield, as there is usually a small reverse polarity protection diode between the DC jack and VIN pin on the Arduino board. The current drawn by the motors could burn this diode out. The better alternative is to feed power directly into the shield, either via the VIN and GND pins or the screw terminals. The attached Arduino board is then powered via its connection to the VIN pin. Of course, there is no reverse polarity protection in this case. The Arduino pin connections are shown in Table 2. Apart from the direction, PWM and buzzer, none of the functions shown in Table 2 have any effect unless something is actually connected to the shield, so the pins remain available if needed for other roles, for example, if a second shield is attached. We have written a sample Arduino sketch to test some of the features; it 66 Silicon Chip operates similarly to the Monster Moto shield sample sketch, except there is no display of motor current. It is named “FunduMoto_Shield_Demo. ino”. While LED1-LED4, near the motor screw terminals, appear to be a handy aid to show what the motor is doing, they unfortunately both tend to light up any time a motor is connected and powered, presumably due to backEMF during the PWM off-cycle. Shield 3: L293D-based motor and servo shield This shield is stocked by both Altronics (Cat Z6208A) and Jaycar (Cat XC4472), and features two L293D dual motor driver ICs as well as a 74HC595 serial-to-parallel shift register. On our version of the board, all three ICs were fitted via sockets. Its circuit is shown in Fig.4. It is a clone of a board originally designed by the Adafruit company, and it makes good use of the original Uno’s six PWM outputs. It is a fairly old design, and as such also lacks the R3 header connections (this is becoming a theme...). The supplied headers are not stackable, but being such a bulky shield, it makes sense for it to be the top-most board in a multi-shield stack anyway. The big upside of this board is that it is capable of driving four bi-directional DC brushed motors. It also features two servo headers, and all six analogcapable pins are brought out to headers too (although these headers were not fitted on the board we tested). The L293D IC The L293D motor driver IC is very similar in function and layout to the L298, although with more modest current and voltage capabilities. It has the benefit of being available in a convenient 16-pin DIP format. Both Altronics and Jaycar stock the bare L293D IC as well as the shield, so you have the option of developing your own hardware or even replacing a blown chip if that were to happen (never!). The IC is rated at 36V supply voltage and up to 600mA continuous current per channel. This is sufficient for many of the smaller hobby or gear motors that are around. The contact between the IC and its socket may introduce extra resistance, so these ratings may not be achievable with the socketed ICs. Our version of the board is populated with 16V electrolytic capacitors, so would not be able to withstand any voltages higher than this (they could be upgraded). The IC itself also incorporates shunt diodes, so direct connection to inductive loads is straightforward. It does not provide any provision for detecting current. The data sheet does not specify a maximum PWM frequency, although the consensus within the Arduino community is that 5kHz is about the maximum usable. The PWM signal is fed into an enable (EN) pin, which is shared by the two outputs that feed a single motor. By default, the AVR-based Arduino boards like the Uno have a default PWM frequency of either 490Hz or 980Hz (depending on the pin), so will be fine driving this shield if you don’t change that. The 74HC595 chip The presence of a 74HC595 shift register (IC3) means that this shield does not require eight separate digital outputs to drive the motor driver ICs. That’s fortunate, as it would otherwise use up a great many of the available I/O pins on a standard Arduino. Instead, the motor state is set indirectly via the shift register, although the PWM outputs come directly from the attached Arduino board, since the shift register would not be The L293D shield uses all through-hole parts and socketed ICs, making replacement of damaged parts easy. Australia’s electronics magazine siliconchip.com.au Fig.4: the L293D shield circuit includes two dual motor driver ICs, a shift register and various unpopulated headers which are not shown on this diagram. See the board photo for their connections. able to update quickly enough. Table 3 shows the connections for this shield. The OE (output tri-state) pin of the shift register is also connected to an Arduino pin, meaning the entire unit and all its motor outputs can be effectively switched off by that one pin. There are a handful of other components on the shield, including an assortment of capacitors and several unpopusiliconchip.com.au lated headers. Two three-way headers are fitted to one corner for servo motor connections. A resistor network provides pull-downs on the outputs from the shift register so that a safe state is present during initialisation. Screw terminals are provided for feeding power in (CON3) as well as the motor connections. The motor connections are via two Australia’s electronics magazine five-way screw terminals (CON1 & CON2), one at each end of the board, with the centre terminal of each connected to ground. This allows this shield to drive up to eight devices (including lamps) if polarity reversal is not needed, ie, by connecting them between one motor output and ground, instead of between a pair of outputs. October 2019  67 Like the FunduMoto shield, a jumper (JP1, marked PWRJMP on this shield) is provided to make or break the connection between the motor power supply and the Arduino’s VIN pin. Using it Table 3 shows the L293D Motor Shield’s connections. We found that some of the pins on the shield’s underside protruded quite badly, so we trimmed the pins of the screw terminal blocks and applied insulation tape to the USB connector of our Uno before connecting it. The pins were so long that the shield would not sit flat on the Arduino before trimming. While it may seem excessive for the L293D motor shield to be able to drive four motors, we think it would work well with some of the four-wheeled robot chassis that exist, like Jaycar Cat KR3162 or Altronics Cat K1092. The motors need not be driven independently in software, and the plentiful screw terminals make it easier to terminate the motor wiring separately. Our test sketch for this shield is called “L293D_demo.ino”. It operates similarly to the other two sketches, except that there are now four motors available to be controlled, and they are designated A through D, corresponding to M1 through M4 as marked on the headers on the shield. Summary We did not try to push any of these shields to their limits. Except for the Monster Moto Shield, the voltage limits of the ICs are overruled by the capacitors that have been installed. Our testing was also done at quite low current levels, and you may find that some form of heatsinking or ventilation may be needed at higher currents. The Monster Motor shield will drive bigger motors than the other two, with the FunduMoto shield being between the other two in terms of motor size capability. It’s worth noting that due to the inductive nature of DC motors, voltages higher than the supply might be present when the motors are switched off, such as at the end of a PWM cycle. The capacitors will need to be able to handle this too. For the basis of a simple robot car 68 Silicon Chip Australia’s electronics magazine project, the FunduMoto shield would work well. The various headers allow many sensors and other devices to be connected directly to the shield, simplifying the wiring for such a project. If more motors need to be driven, then clearly the L293D shield is the best choice, with its ability to drive four motors. Unfortunately, none of the shields offer any option for pin swapping, so there is no real option to stack multiple boards to provide more SC outputs than this. Table 1: Monster Moto Shield Connections Function Motor 1 Motor 2 INA 7 4 INB 8 9 PWM 5 6 EN A0 A1 CS A2 A3 Table 2: FunduMoto Shield Connections Function Pin Direction (Motor 1 & 2) 12 & 13 PWM (Motor 1 & 2) 10 & 11 Buzzer 4 Servo 1 9 Servo 2 2 Analog A0-A5 Ping Trigger 7 Ping Receive 8 RGB 3, 5 & 6 Bluetooth 0 & 1 (TX & RX) Table 3: L293D Shield Connections Function Pin 74HC595 Data 8 74HC595 Clock 4 74HC595 Latch 12 74HC595 Enable 7 PWM Motor 1-4 11, 3, 5 & 6 Servo 1 10 Servo 2 9 siliconchip.com.au