Remote Control of a Brushed DC Motor

By Brandon Tsuge,


Introduction

In this post, we’ll learn how to assemble a brushed DC motor with a rotary encoder that is controlled by a radio transmitter. 

Here are the parts I used for this demonstration:

Pololu 50:1 Brushed DC Gear Motor (https://www.pololu.com/product/4753)

I’m not and affiliate for Pololu, but I still recommend this, as it is a quality motor with thorough documentation).

Arduino Nano: https://amzn.to/37z5OJE 

USB Cable for Nano: https://amzn.to/39MXSqW

DROK Dual DC Motor Driver: https://amzn.to/36LDx3y

Radiolink RC Transmitter and Receiver: https://amzn.to/3qvZsU6

Breadboard: https://amzn.to/3ge63xH

Jumper Wires: https://amzn.to/3owv6Pz

AA Battery Holder: https://amzn.to/36N3M9M

Glass Fuse Holder: https://amzn.to/37Fea2w 

Glass Fuses: https://amzn.to/37CUvQP

A typical brushed, direct current (DC) motor has two leads. When a voltage is applied across these two leads, the motor shaft spins. Reversing the polarity of this voltage will reverse the direction of rotation of the motor shaft. DC motors are usually wired to a motor driver, which receive and interpret control signals to ultimately drive the motor’s speed and direction. Brushed motors like this are considered to be open loop, meaning they aren’t capable of sending back information about its shaft position or speed.

Brushed DC Motor

This type of motor becomes closed loop when a rotary motor is attached. In this case, the motor is driven in the same way as any other brushed motor. The only difference is that there is now the ability to measure the motor shaft position. Usually this type of motor will have 5 or 6 wires. 

Brushed DC Gear Motor with Rotary Encoder

Two of the wires are used for the motor power and the other wires are used for the encoder. Essentially the encoder works by turning a signal on and off as the motor shaft rotates. These pulses are directly related to the motor shaft position. I like to use the analogy of a playing card flapping in the spokes of a bicycle wheel. The faster the wheel moves, the more times you hear the playing card making a noise. In the case of a rotary encoder, a high number of pulses over a given time period indicates a faster motors speed.

For this example I will be using a Pololu DC brushed motor with a 50:1 gear ratio and a rotary encoder with two outputs. It has red and green wires to power the motor shaft movement. It has a green wire for a ground for the encoder, a blue wire (Vcc) to receive a positive voltage between 3.5V and 20V, and a yellow and white wire to output separate encoder signals.

Rotary Encoder Wiring




Below is what the output signals would look like as the motor rotates. Notice how they are out of phase. The signals alternate between values of the supplied Vcc and 0V throughout the motor rotation. For this encoder, if you count the rising and falling edges of a single output, you will count 32 counts per revolution. If you count rising and falling edges for both outputs, you will count 64 counts per revolution. Since this is a 50:1 geared motor, a single rotation of the output shaft will result in a total of 3200 counts (50 x 64 counts).

Rotary Encoder Output — Forward direction

The order in which the rising edge of a particular signal is read is an indication of direction. For instance, let’s say that when the motor is rotating clockwise, the rising edge of Output B is counted before the rising edge of Output A. If that was reversed, the rising edge of Output A is counted first, indicating that the motor is rotating counterclockwise.

Rotary Encoder Output — Reversed Direction

An Arduino Nano is being used to power the motor encoder and read the output values of the encoder. It is also sending signals to a dual motor driver to control the speed of the motor.

I’m also using an RC transmitter and receiver to send signals to the Arduino. Essentially, moving a stick on the controller transmits a signal to the RC receiver. The receiver sends a signal to the Arduino which interprets it and sends it to the motor driver. The motor driver receives the signal from the Arduino, interprets it and outputs power to the motor. All of these signals are pulse width modulated signals, which I will discuss in another post. Lastly, as the motor rotates, the Arduino reads the encoder values.

Hardware for Remote Control of a Motor


Wiring

To start this example, I place an Arduino Nano in a breadboard. I use wire jumpers to make connections to the components. The red and black wires on the motor are wired to one of the black sets of screw terminal blocks on the motor controller. The green wire is connected the Arduino ground and the Blue wire is connected to the Arduino 5V output. The yellow and white wires are attached to pins 2 and 3 on the Arduino.

Electronic Assembly of Nano and Motor-Encoder

For the motor driver, the tan screw terminal blocks receive power from an external power source between 6.5V and 27V. I’m using a AA battery holder and a set of 8 AA batteries for this example. The user manual for this board recommends putting a 10A fuse in between one of the leads of the motors and the motor driver and a 15A fuse between the positive end of the power source and the motor driver.

The motor driver also has a set of male header pins. These pins are what control the behaviors of the attached motors. If you look at these two pins, there are two columns. The left column is for one motor and the right column is for the other. The top pins are connected to 5V from the Arduino and the bottom pins are connected to a ground, also on the Arduino. The pins labeled ENA receive a PWM signal from the Arduino and are directly related to the motor speed. These can be connected to any Arduino pin capable of a PWM output. The pins labeled IN1, IN2, IN3, and IN4 control the direction of the motor. If IN1 has a value of 1 and IN2 has a value of 0, one of the motors will spin forward. If you reverse this configuration, the motor changes direction. This applies to the other motor output with IN3 and IN4. These pins can be connected to any digital pin on the Arduino

Dual Motor Driver Board

Lastly, I used and RC transmitter and receiver to indirectly control the motor speed. I chose to use Channel 3, which is the up and down movement on the left stick. I chose this channel because it is not spring loaded and will not return to the center position. The top pin connects to any digital pin on the Arduino, the middle pin is connected to 5V and the bottom pin is connected to ground.


Radio Control Receiver

Below is the diagram of the breadboard view.

Motor and Receiver System Wiring Diagram


Arduino Code

Setup: In this example I use 6 different digital pins. I set the pin leading from RC receiver to be an Input. The pins leading to the ENA, IN1, and IN2 pins on the motor driver are set to be digital outputs, and the pins connected to the rotary encoder outputs are set to “INPUT_PULLUP.”

I also use the “attachInterrupt” command to interrupt the loop and increment counting functions every time encoder outputs a “CHANGE.” Essentially I am counting the rising and falling edges of each of the encoder outputs. This can only be used with pins 2 and 3 on the Arduino Uno and Nano. If a second motor is needed, one encoder output on each motor will not be used. One encoder output per motor is often enough for most projects.

Loop: I start the loop be reading the RC PWM value using the “pulseIn” command. I write IN1 to “HIGH” and IN2 to “LOW” to establish a motor direction. I then use “if” statements to store the minimum and maximum values that are read from the RC receiver. I use this range to map the current RC PWM value to values between 0 and 255, since this is the range that “analogWrite” uses. This value is then sent to the ENA Pin to ultimately spin the motor.

Lastly, I print the counters.

Functions: I use two functions that simply increment two different variables. These functions are called every time the interrupts are initiated. 

You should now be able to control the speed of the motor with the channel 3 joystick on the remote control. 

Here’s where you can find a copy of my code here.

Motor Control Demo

Also, note that when you open of the serial monitor, the counters are increasing as the motor spins. 

I hope this tutorial was informative.

The parts for this post were sponsored by Mechanical Design 101.


How To Get Started With Robotics At Home

By Brandon Tsuge,

If you’ve ever wanted to get started with DIY robotics, you’ve probably heard the name Arduino thrown around. Arduino is an Italian made, open-source, electronics platform with incredibly user friendly hardware and software. The modular nature of the hardware and the simplicity of the programming environment makes it ideal for beginners while still having the capabilities for more complex projects.

Most of the time when somebody says they are “using an Arduino,” they most likely mean they are using the Arduino Uno or Arduino Nano.


Arduino Nano and Arduino Uno


Arduino Uno

Arduino Nano

In simple terms, the Arduino is a mini computer that can perceive the environment through sensors that measure things like light, sound, temperature, distance, etc. It can then use this information to impart change to the physical environment by sending signals to actuators or other hardware. Actuators consist of things like motors, lights, speakers, LCD screens, and much more. The Arduino performs these actions through instructions received in a program, or sketch. These sketches are sent via a USB cable and created using the Arduino integrated development environment (IDE), which is based on the C programming language.


Arduino Communication Diagram


In a nutshell, here are some of the main features of the Arduino:

· Read an analog signal

· Write an analog signal*

· Read a digital signal

· Write a digital signal

· Provide a 5V or 3.3V source

· Provide a ground (0V)

· Easily communicate with your PC via USB

*Arduino can’t truly create an analog signal. It “fakes” it by using pulse width modulation (PWM). I’ll elaborate on this in a future post.

If you are a complete beginner to programming and electrical circuits, I recommend getting the Arduino starter kit (https://amzn.to/2YWt01o). This set comes with over 100 components and an easy to understand project book that teaches fundamental concepts via sample projects. In the upcoming posts, I will be providing tutorials on each of these examples from this book.


Exponential Threat, Part 2

By Chris McCarthy,

Ambassador Trong walks onto the bridge of Amanda’s ship. His attaches, Liam and Sturgis, enter with him. 

His pageant guard Maritha, walks just in front of him waving green and yellow flags wherever he is going to walk to give him the pageantry accorded to his station.

The entourage walks onto the bridge in a heightened dramatic way, stone faced and eyes not connecting with anyone. Liam and Sturgis do dramatic bows and Maritha walks around the bridge, waving her flags, as Ambassador Trong empties his pockets of the thick stack of unusable paper credits and gold statues of his predecessors. In the old days. He might have left one of these valuable statues with the ship, but inflation’s a bitch and these days the statues are just used in the ornate display of wealth and privilege that got the man into this position.

Amanda’s crew stand at attention in a line at the center of the bridge, Amanda standing directly on top of the four foot diameter Intergalactic Legion insignia, her fists up in the official pugilistic stance of a captain, the rest of the crew standing in official positions behind her, Salamander—his official title Number Two—with his arms on his hips looking up and to the right, affecting an ambitious overconfidence; Lisa, her hands on either cheek, her face locked into a silent primal scream, an affected stance all Navigation Specialists must use, the meaning lost over the centuries. Winston, the communications officer, is down on one knee, his arms out to the side as if he’s singing the final note in the final song of act two of a musical, his mouth wide open to affect a basic level understanding that his job is in communication, which typically for humans involves the mouth… ok, you get it. 

“Sup?” Suddenly, Ambassador Trong, relaxes his body and drops all formality. “What the fuck is up, Mandy?” He looks around the ship, taking in the small bridge. 

Amanda softens a bit, but keeps her official stance. Her crew behind her stay frozen but keep their eyes on her, following her cue. 

“What, you don’t want to talk to your old buddy, Edwin Trong?” He asks coyly. 

Amanda shows the beginning of an uncomfortable smile, still frozen in position. Edwin walks up and pretends to shadow box with Amanda. 

Lisa, her mouth still locked in the mock primal scream, meets Winston’s eyes below her and to the right, “Can we stop doing this now? I’m getting crow’s feet.”

Winston whispers, “We have to wait for Ambassador fuck face to say at ease…”

Trong takes in Amanda’s crew. “There’s a real ragtag underdog thing going on here. Very on-brand, Amanda. The self-sabotage is palpable… but that’s always been your thing, hasn’t it?”

He looks to his entourage who suddenly remember to laugh uproariously. Even Maritha stops waving her flags around and cracks up. 

WHOOOOSH.


Exponential Threat, Part 2
Exponential Threat, Part 2, Graphics by Chris McCarthy with Imagen3

The loud noise of a toilet distracts everyone as the automatic hatch slides open from a hallway at the back of the bridge and Chase walks onto the bridge. Trong’s retinue look over, Liam wide-eyed at the impertinence and Sturgis looking at Trong and Liam, wondering how he should react to this breach in protocol.

“Excuse me, sir, what do you think you’re doing?” Sturgis asks, a condescending lilt to his voice. “Trong is eldest son of one of the wealthiest asteroid mining families, so you will show him the respect he’s earned…”

Sturgis stops talking as Chase rips open a bag of Prathian Figs and throws one in his mouth. “These are supposed to help get you regular. Oh shit, wait, that’s prunes, right? Too bad Earth is gone and no one thought to take prune trees with them when they left.”

Then for the first time, Chase looks over at Ambassador Trong’s delegation. 

“Sorry, guys. I had to see a guy about a prairie dog back there. Right? Get it?” 

He walks over to Sturgis and wipes his hand off on his shirt then looks at it to make sure it’s clean. “Oh, I’m just fucking with you guys.” 

Sturgis’ mouth falls open. 

Amanda looks over at Chase nervously, “Dad…I mean Chase…who the hell are you doing?”  

The rest of Amanda’s crew, visibly exhausted now and wearing pained faces, look around at each other desperately as they try to hold their positions. 

Trong says, “Excuse me. You will give me the deference I have earned…” 

Maritha runs over waving her ribbon in Chase’s face—this time it’s an aggressive move. She hisses loudly at him. HISSSSSS. 

“OK, so they don’t have gum on Tumis,” Chase says. “Noted. I’ll let my smuggler friends know.” 

Chase looks at the stone-faced entourage. “I’m kidding. Come on, have a sense of humor.” 

Suddenly, a look of realization comes over Trong’s face. “Wait a minute…” says Trong. 

Maritha keeps waving the flags as she circles Chase, who doesn’t seem to notice. 

“Maritha, stop. Just please stop.” Trong says, pushing her flags away.

Maritha dances her way to the other side of the ship.

The crew, still frozen in place, look at each other as they mouth her name—Maritha.

Salamander says, “It has to be Marissa, right?”

Winston nods in agreement, “Has to be. The thhhh sound is really uncomfortable.” 

Trong walks up to Chase, excited, “You’re Chase Markley!” 

Chase throws another fig into his mouth then puts the empty sack into Liam’s pocket. “Yep, who the fuck are you and why are standing on my bridge?”

Trong steps back so Chase can see him better. “It’s Edwin Trong. You used to drive me to school when Mandy and I were in pre-academy.”

“Oh, yeah, Edwin. OK, how’s your mom doing?” 

“Oh… she’s dead.” 

“Oh really? Shit. Wow. She’s dead? Like fully dead?” Chase asks. 

“Yeah, like fully dead. Yes.” Edwin responds.  

Amanda rolls her eyes as Chase walks past Edwin over to her and the crew. “Why are you so uptight Mandy?”  

He touches her shoulder and gently shakes her and she unfreezes. 

The rest of the crew relax out of their poses. Lisa rubs her cheekbones and flexes her jaw. “It feels like I’ve been chewing gum for an hour.” 

“Gum’s illegal here. Just ask… Marissa, is it? I mean her breath could knock a buzzard off a shit wagon.” Chase says. 

Marissa looks over and hisses again but lowers her flags to her side when she notices Edwin laughing, quickly followed by Liam and Sturgis. 

Winston stands up, rubbing his knee. “Gonna need to oil this knee when we get to the outpost. Wait a minute…” 

Winston looks down surprised as his knee emits a faint blue glow.

Lisa raises her eyebrows. “What’s happening to your knee?

Winston pulls up his right sleeve and examines a small screen on his wrist. “It appears that the update included a patch to my regeneration algorithm. The nanobots in my system were reprogrammed for better efficiency.”

“Wow,” says Lisa. 

Chase looks at the crew, now relaxing back to their normal postures, except for Salamander. “Hey crew, relax. Chill. It’s just old Edwin Trong. Used to drive him to school then mow his mom’s lawn on my way back home.”

Chase shakes Salamander gently. “You can relax now.” 

Salamander wakes up, shivering. “Sorry, I went deep there.” He runs over to a corner of the bridge and taps a button. A stream of hot air comes out of a panel in the wall. “Oh yeah, that’s the stuff.” 

“Sorry, what did you say, Chase? Mow my mom’s lawn?” Edwin asks. 

Chase says, “It’s an expression.” 

“OK. That’s what I was wondering.” Edwin asks, slightly suspicious.

“I mean, I actually did mow the lawn…I did it well. Really well. Too well, maybe.” Chase says. 

“Oh. OK.” Edwin shakes off his confusion and it’s quickly replaced by excitement.

“Well, guys” Edwin says, “This is the legendary bounty hunter, Chase Markley. He brought down the Orphelian six.” 

“Seven. One of them morphed into two.” Chase says. 

Winston leans over to Salamander, and whispers, “Notice how one always morphs at the last minute. Champion stat padder, this guy.”

Sal says, “What are you talking about? Chase is a legend. Plus, he’s Amanda’s dad, so… ” 

“You’re obsessed with Amanda.” Winston counters. 

Salamander looks at her, admiringly, “She’s a good leader. Just doesn’t always know how to show it.” 

“She shoots you out the airlock every chance she gets,” Winston says.

Winston watches as Lisa walks over to Chase and puts a hand on his bicep.

Lisa says, “Chase, thanks. Finally someone did something.” 

“No problem, Lisa. Edwin’s just a family friend.” 

Amanda steps between Edwin and Chase. “So now that we’re done with all that, let’s talk about…”

Chase interrupts. He looks at Edwin, an edge to his voice. 

“So you weren’t going to at ease my very hospitable crew who were here all ready for your arrival. I mean, shit, ancient metal face over here got on one knee for you. You know how much effort that took?” Chase points at Winston. “The guy’s three hundred years old.” 

Winston glares at Chase, then looks down at his knee. He stretches it out. It feels amazing. 

Edwin puffs his chest out with pride. “Well, as you of course know, I am trade ambassador for Andolenga Outpost, a position my family has held for two hundred years. It is my duty and privilege to choose one ship a day to extract ceremonial tariff. So when I saw captain Amanda Markley’s identification come up, well, I mean, I had to stop her ship. Just for old time’s sake.” 

“For old time’s sake?” Amanda says. “I know you hate me for what I did. What do you want?” 

Chase shoots Amanda a look, “Amanda, I got this…” 

“No, Chase… I got this. Edwin, tell us our payment and we’ll be on our way. You’ve lorded yourself over me and my crew enough.” 

Edwin laughs. “Now why would I hate you Amanda?” He walks toward the front of the bridge and looks out the viewport at the blue planet that gets larger and larger as the ship approaches. 

He turns on his heels and looks back at her. “Because you came between me and my sister? Is that a reason to hate someone? I don’t know…” 

Chase tries to intercede. “Guys, let’s not get carried away here…” 

“Silence!” Edwin says. 

Liam pulls out a six inch blue light chryo-blade and waves it in front of his face, the blade humming as it slices the air. A second prior Liam seemed like nothing more than a fop courtier, but now he takes a well-practiced fighting stance.

Amanda looks around the bridge. She realizes she needs to take control. “Edwin, let’s…”

“Did you not hear what I said?!” Edwin screams. He waits a moment then looks around the bridge, everyone now silent. He sits down in the captain’s chair and picks at a hangnail. “Good. As I was saying… getting between me and my sister probably wouldn’t be enough for me to hate you. I mean, we were in academy. We were young.”

“That’s what I was thinking,” Amanda says. “Now let’s…” 

“But getting between me and my sister, whose heart you went on to break when you left her stranded after eloping with her.” Edwin says. 

Amanda takes a step back, “Uh, ok, see… what happened was…”

Edwin continues, “A heart break that quickly turned into rage for me after you told her you were breaking up with her because you had feelings for me, which was a lie…”

“It was, uh, the first thing that came to mind,” Amanda says. 

Lisa looks on and raises her eyebrows, “Wow.” 

“Yeah,” Chase says, nodding. 

Edwin continues on, “Edwina’s rage of course took our family down the pathway of internecine warfare, splitting our army into two factions, one that supported her as the successor of my family’s asteroid mines and the other, which supported me, splitting our power down the middle—and putting me in this embarrassing position as trade ambassador instead of Emperor of Planet Crassus.” 

Amanda cracks a sheepish smile. “Right. Totally. You have every right to be…” 

“Not that my sister fared any better. She fell in with a crew of Earth-wheat smugglers in the Daytona System and is now locked away in a prison half a galaxy away. Quite a fall from grace.”

“Yikes. Well…I would like to apologize…” Amanda responds. 

Edwin stands up and walks toward Amanda, “In other words, you destroyed my family, caused an internal division and power vacuum. A vacuum the Kreinalld family, our nemesis for centuries, stepped into, taking all of our power, now lording over Planet Crassus, our ancestral world.” 

Chase takes a step toward Amanda and Edwin at the center of the bridge, careful to avoid Liam’s glowing blade. “What can we do to make this right, Edwin?” 

“Make this right?” Edwin says, smiling. “Well, you’ve created the perfect scenario for me to justly kill you and your whole crew, right here on the bridge of your ship.”

Edwin nods to his right. Sturgis takes a step toward the center of the bridge and says, “You’re harboring a three month old mango-puppy, an animal blacklisted for trade. This is an infraction punishable by death on planet Tumis.”

“So, Chase and Amanda, I guess you could say you’re making this right.” Edwin says darkly.

Sturgis’ eyes turn bright green and he stares down Chase and the crew menacingly. 

Salamander walks over from the corner and stands next to Winston. “Did his eyes just change color?”

“Yeah. He’s like me. Just a later edition.” Winston says. 

“A later edition?” Salamander asks. 

“Yeah,” Winston says gulping. “He’s what we affectionately call… an armybot.”

“An armybot? As in…he’s like a full army by himself?”

Winston shakes his head, “ No. As in he murders entire armies…with his mind.”

“Oh sweet holy fuck. We’re going to die… like right now.” Salamander says, putting his hand to his neck. 

“Yep,” says Winston. He double takes as he notices a blue glow emitting from his right hand. 


Copyright Chris McCarthy and MDA Press 2024, Graphics by Chris McCarthy with Imagen3