Android Controlling DC Motors using the AndroiDAQ Module Part 3

Now that you have a basic understanding of DC motors and why we use DC motor controllers for manually or automatically starting or stopping a motor, for selecting forward or reverse rotation, for the selecting and regulating the speed of the motor, and also for regulating or limiting the torque of the motor and for protecting the motor and circuitry against overloads and faults, we will now go further in depth into the circuitry that makes up a DC motor controller, and more specifically describe a motor controller that can be used for the AndroiDAQ module.

For this motor controller, we will base our design on a circuit that is called an H-Bridge. An H-bridge is simply an electronic circuit that enables voltage to be applied across a motor in either direction. Using the H-bridge design we take care of two of our basic functions for a motor controller; to start and stop the motor, and to allow us to change the motor direction. 

An H bridge can be thought of as a circuit that is built with four switches and a motor, with the motor in between the two switch groups.  Two of these switches are connected to the power bus of the circuit with each of these switches connected to each of the connections on the motor, and the other two switches are connected to the ground bus with each switch again connected to each of the connections on the motor. In this configuration when one power bus connected switch and one ground bus connected switch, which is connected to the opposite connection of the motor, is closed, a voltage will be applied across the motor. By reversing which switches are closed in this circuit, this voltage applied to the motor is reversed, allowing reverse operation of the motor. 

You can see the H-bridge in action in the following image. It is important to keep in mind that if the power and ground bus switches that are connected to the same connector on the motor, the motor will not turn, and your power supply will be shorted together causing damage to your power supply. The same holds if both of the power bus or both of the ground bus switches are closed at the same time, the motor will not turn as no power is applied to the motor as the voltage circuit is not completed.

H Bridge Diagram


So now we have a method in our motor controller to switch on and off the motor and to control the direction of the motor’s spin, but how do we control the motors speed? We know from the previous article that the motor speed can be changed by raising or lowering the voltage supplied to the motor, so speed control can be done by simply adjusting the voltage sent to the motor, but this is quite inefficient and not possible with micro-controllers that utilize digital high or low levels. A better way would be to utilize what is called pulse width modulation which automatically switches the motor's supply voltage on and off very quickly so that the motor sees only the average voltage supplied to it. Say what, you say? Let me explain further. 

Imagine a light bulb with a switch. When you close the switch, the bulb turns on at full brightness and when you open the switch the bulb turns off. Now if you close the switch for a fraction of a second and then open it for the same amount of time back and forth, the filament won't have time to cool down or heat up totally, so you will see an average, but dimmer, glow from the light bulb.

This example is an over simplification on how light bulb dimmers work, though this same principle can be used by our motor speed controller to drive the motor at various speeds, and it works in the same way; when the power switch is closed, the motor sees the full voltage supplied, and when it is open it sees 0-volts. Now if you close the switch for a fraction of a second and then open it for the same amount of time, the motor won’t have time to come to a full stop and the motor speed will be slower. To utilize the full voltage that you are supplying to the motor, the power switch is turned on longer than it is turned off, so the average voltage supplied to the motor will be higher, hence your motor speed will be faster and vice verse.  

This is how pulse width modulation works, as it is the process of supplying a voltage signal which is pulsing on-off to an output device such as a motor. The amount of time the voltage is on compared to the amount of time the voltage is off is called the pulse-width. The pulse-width can be adjusted anywhere between being off all of the time to being on all of the time. The actual pulse-width is usually measured as the percentage of time that the signal is on compared to the entire cycle time, or during one second. This percentage of time is called the duty cycle. So if the duty cycle of your PWM is set at 60% and your power supply is say 12-volts, the voltage supplied to the motor would be 50% of the 12-volts, or 7.2-volts (12 * 60% = 7.2). 

PWM duty cycle operation

To simplify the H-bridge circuit design for our motor controller, a Texas Instruments SN754410 Quadruple Half-H Driver integrated chip will be used. The SN754410 chip was selected as it is readily available, easy to use, and it can supply up to 1A of current to drive small DC motors. The chip also automatically eliminates the problem described above of having two of the wrong switches closed at the same time which can cause damage to your power supply or motors. More detailed information on the SN754410 can be found at: 

To simplify the PWM circuit of our motor controller, we will use a simple circuit that takes an input voltage level and outputs a pulse width modulation signal whose duty cycle is proportional to the 0-5-volt input. Meaning for a scale of 0-5-volts input, you get a 0-100% duty cycle PWM signal. This circuit uses what is called an Operational Amplifier or Op-amp as they are more commonly called. Op-amps are one of the basic building blocks of analog electronic circuits. Operational amplifiers are linear devices that have all the properties required for nearly ideal DC amplification and are used extensively in signal conditioning, filtering or to perform mathematical operations such as add, subtract, integration and differentiation. More detailed information about op-amps can be found here: 

The basic op-amp PWM circuit is shown below. This circuit outputs a rectangular signal with duty cycle that varies between 0 and 100% in response to an input signal varying from 0 to 5V dc. More detailed information about how this circuit works specifically can be found here:



But wait you say, aren’t we using the above PWM circuit because the micro-controller and AndroiDAQ only output ones and zeros. You are correct if you caught this, so in addition to our PWM circuit, we need an additional circuit that can interpret a varying frequency output pulse train from our micro-controller, or AndroiDAQ module, and convert it to a voltage level.  For this we will use a LM2907 frequency to voltage converter integrated circuit. The LM2907 data sheet can be found here: and the circuit we will use is shown below.

Freq to Volt Converter

We now have most of the building blocks to complete our motor controller. We have methods to turn the motor on and off, to control the direction of rotation of the motor, and to control the speed of the motor. Now we need to put together these building blocks and use what is called glue logic to ensure all circuits talk nice to each other and to ensure external influences like electrostatic discharge and induction kickback doesn’t damage our electronics and motors during operation. All this and more will be included in the next article.

We invite you to read more about the AndroiDAQ data acquisition module for Android, LabVIEW, JAVA, and Python: About the AndroiDAQ module.


AndroiDAQ with xBee WiFi module