BuddyBot: Controlling a Stepper Motor with an Android Smartphone
By Michael Parks, P.E., Mouser Electronics
Licensed under CC BY-SA
4.0
The Build
- To begin, partition your breadboard into different parts. You will need space on the breadboard for the
following components:
- L293D stepper motor interface chip and all the interface wires
- Terminal screw blocks for the laser
- 3 male header pins for interfacing to the ultrasonic sensor
- Voltage divider circuit to interface the STM32 Nucleo with the Bluetooth board
- Pull-down resistors for the motor limit switches
- Voltage regulator circuit
Figure 3: The BuddyBot Schematic. Click to enlarge.
- Let’s start with the L293D H-Bridge Motor Driver Chip:
- Gently secure the L293D chip into the breadboard to avoid damaging the pins.
- Hook up the ground rail (GND) to the pins that need a connection to GND; this includes pins 4, 5, 12,
and 13.
- Run a 10k-ohm resistor for the Vcc rail to pin 1 which is the enable pin for the chip.
- Run a wire from pin 1 to pin 9, which is also an enable pin.
- Run Vcc directly into pins 8 and 16 to provide the power to drive the motors.
- If we had a large load, we would have to use an external power source for these pins. But since the load
is small, we can drive it off the 5V from the STM32 Nucleo with no problem. We will revisit this when we
wire it up to the motor and the STM32 Nucleo later on.
- Hooking up the laser:
- If needed, extend the wires of the laser by soldering an additional length of wire. Be sure to insulate
the solder point with electric tape or heat shrink.
- Insert the screw terminal block onto the breadboard.
- Connect one terminal of the screw terminal to GND.
- Connect the GND wire of the laser to the GND terminal of the screw block.
- Connect the Vcc wire of the laser to the other terminal of the screw block.
- Connect a wire from the STM32 Nucleo pin PA_8 to the same row on the breadboard as the Vcc laser
terminal.
- This allows us to toggle the laser on and off in the software we will write later.
- Hook up the PNG))) ultrasonic sensor:
- Place a strip of 3 male header pins on the breadboard.
- Then we provide a connection to Vcc and GND to the header pins.
- The signal output pin of the ultrasonic sensor can be ran from the header pin directly into the STM32
Nucleo’s PA_6 GPIO pin. We will use the pulseIn function of the STM32 Nucleo to read in the ultrasonic
sensor signal.
- Ensure that you match the pins on breadboard to the pins on the PING sensor. Looking at the front of the
PING sensor the order of the wires is SIG, Vcc, GND.
- Limit Switches: To prevent the motor from turning a full 360-degrees and ripping out the laser and
ultrasonic sensor wires, we will need to include two limit switches. Use the schematic to refer to, as well
as instructions below. You also have an illustrated breadboard with which to follow along. Let’s wire the
limit switches up next:
- First let’s solder some pretty long wires to our micro lever switches.
- Using a multimeter, check to see the normally open (N.O.) position for your switches. Solder a wire to each of the
terminals. I prefer to use a red and green color wire to differentiate terminals.
- We can’t let our STM32 Nucleo pins
float when the switches aren’t depressed, so we will need 10k-ohm pull-down resistors for each
switch. Repeat steps 1) through 3) below for both limit switches:
- Connect one end of the 10k-ohm resistor to GND and the other end into a row on the breadboard.
- Connect the red wire of the limit switch into the Vcc rail of the breadboard (the row marked +).
- Connect the green wire of the limit switch to the same row on the breadboard as the 10k-ohm
resistor.
- Connect the left limit switch to STM32 Nucleo pin PB_3 by tapping the point between our left
limit switch and its 10k-ohm resistor.
- The right limit switch will connect to pin STM32 Nucleo PC_7 by tapping the point between our
right limit switch and its 10k-ohm resistor.
- Voltage regulator: To ensure clean power on the breadboard we have a 7805 voltage regulator and some
capacitors to filter out any noise. Wire the components as such:
- Place the 7805 into the breadboard.
- Connect the positive lead of the 10uF capacitor to Vin pin of the 7805.
- Connect the negative lead to the GND pin.
- Connect the positive lead of the .1uF capacitor to Vout pin of the 7805.
- Connect the negative lead to the GND pin.
- Connect the Vout pin of the 7805 to the Vcc rail of the breadboard.
- Connect the 5V pin of the STM32 Nucleo to the Vin pin of the 7805.
- Connect a wire from the GND pin of the 7805 to the GND rail of the breadboard.
- STM32 Nucleo: Let’s next connect the STM32 Nucleo to the RN42 Bluetooth module. Most important in
this step is to create a voltage divider circuit so that the STM32 Nucleo can safely talk to the RN42
Bluetooth module:
- The STM32 Nucleo outputs 5V for logic high. However, the Bluetooth board can only tolerate up to 3.3V. A
simple way to resolve this mismatch is to make a voltage divider circuit using a 5k-ohm and 10k-ohm
resistor.
- Ensure that one end of the 5k-ohm resistor connects to pin PA_9 on our STM32 Nucleo.
- One end of the 10k-ohm resistor is connected to ground.
- The remaining ends of each resistor will connect at a common node on the breadboard. We will tap off
this node and run a wire to the Bluetooth TX pin, which is pin 3 on
the RN42 breakout board.
- The Bluetooth module RX pin (RN42, pin 2) can safely connect directly to the STM32
Nucleo on pin PA_10.
- Connect the RN42 pin 1 to the STM32 Nucleo’s 3.3V pin.
- Connect the RN42 GND pin to the breadboard’s GND rail.
When you are done your breadboard should look like this:
Figure 4: Illustrated BuddyBot Breadboard. Click to
enlarge.
- Now that the breadboard is wired for our components, we can go back in and add the wires that
connect the STM32 Nucleo to the L293D and the L293D to the stepper motor.
I chose to wire the motors last since there tends to be a lot of long wires involved and this prevents
confusion when wiring up the earlier components.
- The particular stepper motors used here happen to split each phase into two separate coils (thus there
are four coils in total). For this particular application, we will keep things simple by soldering
together the 8 motor wires into 4 pairs of two wires. Specifically, we will solder together the
following 8 wires coming from the stepper motor into these 4 pairs:
- Wire 1Y+ : Solid Orange wire with the Black/White wire
- Wire 1Y- : Solid Black wire with the Orange/White wire
- Wire 2Y+ : Solid Red wire with the Yellow/White wire
- Wire 2Y- : Solid Yellow wire with the Red/White wire
- Next we will hook up these wires to our L293D in the following way:
- Wire 1Y+ connects to L293D pin 3
- Wire 1Y- connects to L293D pin 6
- Wire 2Y+ connects to L293D pin 14
- Wire 2Y- connects to L293D pin 11
- Last, we need to connect the STM32 Nucleo to the L293D in the following way using some hook up wire:
- PB_6 to L293D pin 2
- PB_10 to L293D pin 7
- PA_7 to L293D pin 15
- PA_5 to L293D pin 10
This is what the wiring to L293D should look like (Figure 5b below):
That wraps up the hardware portion of the project. Go ahead and plug-in the USB cable to the STM32 Nucleo
and see if the LEDs on the STM32 Nucleo and the RN42 Bluetooth module light up. If the little lights are
blinking, then it’s time to move onto the software part of the project
Figure 5a: L293D Pinout Click to enlarge.
Figure 5b: Connect the motor and the STM32 Nucleo to
the L293D. Click to enlarge.
We would love to hear what you think about this project; please tell us in the
comments section below.