Pages

Tuesday, 13 November 2012

DIY DC Motor Driver

How to make a motor driver by ourselves?
Motor driver is commonly used to control motor. Is not a difficult task to make a simple motor driver by ourselves! Here I would like to share my experience of making a simple motor driver.

First of all, the electronic components will be used are resistors, relay, transistors, capacitors, push button, and diodes. The specification of the components are:
1. 4700 ohm resistor
2. 1000 ohm resistor
3. BC547 NPN transistor
4. 12V relay
5. 0.1 microfarad capacitor
6. 1N4147 diode
7. push button


Figure above shows the schematic of the motor driver circuit. 
+12V and +5V is the power supply to the circuit, D1 and D2 represent 1N4147 diode, R1 and R3 are the 4700 ohm resistor, R2 and R4 are 1000 ohm resistor, C1 and C2 represent 0.1 microfarad capacitor, Q1 and Q2 are BC547 transistors. Terminal NO (normally open) is connected to 12V, terminal NC (normally closed) is connected to ground.
Function of D1 & D2 : act as protection to the relay.
Function of R1 & R3 : pull down resistor that make sure the voltage is 0V.
Function of R2 & R4 : limit the current that flow through the transistor.
Function of C1 & C2 : eliminate the bouncing effect when the push button is pressed and unpressed.
NO is connected to 12V, NC is connected to ground.

Once the circuit is complete, we can supply the 12V and 5V power supply to the circuit for testing the circuit by pressing one of the push button. 



When the lower part push button is pressed, the +5V will pass though the resistor R3 and produce current to the transistor Q2. Transistor Q2 is activated and act like short circuit to the ground. The current will flow through the relay coil from 12V to ground, relay coil now is become electromagnet and switch the terminal to NO which is 12V. Since there is voltage drop across the motor, the motor will rotate.



On the other hand, if we press another push button as shown in figure above, Q1 will be activated and the current flow through the relay coil. The left terminal of the motor will connected to 12V whereas right terminal connected to ground. This voltage drop will rotate the motor in clockwise direction.

Conclusion...
If you wish to build a motor driver circuit as explained above, you can buy the components here:
1. 12V Relay - https://www.sparkfun.com/products/10924
2. BC547 NPN transistor - https://www.sparkfun.com/products/8928
30.1 microfarad capacitor - https://www.sparkfun.com/products/8375
4. 1N4147 diode - https://www.sparkfun.com/products/8589
5. push button - http://www.cytron.com.my/viewProduct.php?pcode=SW-PBM-4N-060601&name=6x6x1%20Push%20Button%204Pin

6. Resistors - https://www.sparkfun.com/products/8374

Sunday, 11 November 2012

Controlling DC Brushed Motor

How to control the speed of a dc brushed motor?
The typical dc brushed motor has two terminal, positive and negative. To make the motor run we just need to plug in the two terminals with a dc power supply.
But what if we want the motor to run at different speed? Bear in mind the speed of motor is depend on the voltage supply to the motor. Speed of motor is linearly proportional to amount of voltage supply.

Generally, there are several methods can varies the speed of motor such as potential divider method and pulse-width modulation. Potentiometer is used for application of potential divider to control motor speed, whereas pulse-width modulation is generated from a microcontroller.



pulse-width modulation
Here I would like to describe the pulse-width modulation(PWM) method to control motor speed.
To do so, we need to have a microcontroller chip and a motor driver chip, L293D. This L293D can used to control the speed and direction of two dc brushed motors. 

pinout of L293D

From the pin-out diagram above, output 1 and output 2 is connect motor 1, whereas output 3 and 4 is connect to another dc motor, motor 2. Input 1, 2, 3, and 4 each has to connect to pin of microcontroller. These four pins are used to give signal to L293D to control the rotational direction of motor. Enable 1 is the PWM signal port for motor 1, enable 2 for motor 2. These two port have to connect to the PWM output port of the microcontroller. 







Saturday, 10 November 2012

Understanding Microcontroller


What is a microcontroller?
You might be asking yourself what is a microcontroller and what does it do?
A microcontroller is a computing device capable of executing a program (a sequence of instructions) and is often referred to as the “brain” or “control center” in a robot since it is usually responsible for all computations, decision making, and communications.
In order to interact with the outside world, a microcontroller possesses a series of pins (electrical signal connections) that can be turned HIGH (1), or LOW (0) through programming instructions. These pins can also be used to read electrical signals (coming form sensors or other devices) and tell whether they are HIGH or LOW.

Most modern microcontrollers can also measure analogue voltage signals (i.e. signals that can have a full range of values instead of just two well defined states) through the use of an Analogue to Digital Converter (ADC). By using the ADC, a microcontroller can assign a numerical value to an analogue voltage that is neither HIGH nor LOW.

What can a Microcontroller Do?
Although microcontrollers can seem rather limited at first glance, many complex actions can be achieved by setting the pins HIGH and LOW in a better way. Nevertheless, creating very complex algorithms or very large programs may be simply impossible for a microcontroller due to its inherent resource and speed limitations.
For instance, in order to blink a light, one could program a repeating sequence where the microcontrollers turns a pin HIGH, waits for a moment, turns it LOW, waits for another moment and starts again. A light connected to the pin in question would then blink indefinitely.

In a similar way, microcontrollers can be used to control other electrical devices such as actuators (when connected to motor controllers), storage devices (such as SD cards), WiFi or Bluetooth interfaces, etc. As a consequence of this incredible versatility, microcontrollers can be found in everyday products. Practically every home appliance or electronic device uses at least one (often many) microcontroller. For instance TV sets, washing machines, remote controls, telephones, watches, microwave ovens, and now robots require these little devices to operate.

Difference between Microcontroller and Microprocessor
Unlike microprocessors, a microcontroller does not require peripherals such as external RAM or external storage devices to operate. This means that although microcontrollers can be less powerful than their PC counterpart, developing circuits and products based on microcontrollers is much simpler and less expensive since very few additional hardware components are required.
It is important to note that a microcontroller can output only a very small amount of electrical power through its pins; this means that a generic microcontroller will likely not be able to power electrical motors, solenoids, large lights, or any other large load directly. Trying to do so may even cause physical damage to the controller.

Special features in Microcontroller
Special hardware built into the microcontrollers means these devices can do more than the typical digital I/O, basic computations, basic mathematics, and decision taking. Many microcontrollers readily support the most popular communication protocols such as UART, SPI, and I2C. This feature is incredibly useful when communicating with other devices such as computers, advanced sensors, or other microcontrollers.
Although it is possible to manually implement these protocols, it is always nice to have dedicated hardware built-in that takes care of the details. It allows the microcontroller to focus on other tasks and allows for a cleaner program.

Analogue-to-digital converters (ADC)  are used to translate analogue voltage signals to a digital number proportional to the magnitude of the voltage, this number can then be used in the microcontroller program. In order to output an intermediate amount of power different from HIGH and LOW, some microcontrollers are able to use pulse-width modulation PWM. For example this method makes it possible to smoothly dim an LED.

Finally, some microcontrollers integrate a voltage regulator in their development boards. This is rather convenient since it allows the microcontroller to be powered by a wide range of voltages that do not require you to provide the exact operating voltage required. This also allows it to readily power sensors and other accessories without requiring an external regulated power source.


Thursday, 8 November 2012

How DC Brushed Motor Works

Principle of Operation

In any dc brushed motor, operation is based on simple electromagnetism. A current-carrying conductor generates a magnetic field; then it is placed in an external magnetic field, it will experience a force proportional to the current in the conductor, and to the strength of the external magnetic field. As you are well aware of from playing with magnets as a kid, opposite (North and South) polarities attract, while like polarities (North and North, South and South) repel. The internal configuration of a dc motor is designed to harness the magnetic interaction between a current-carrying conductor and an external magnetic field to generate rotational motion.
Let's start by looking at a simple 2-pole dc electric motor (here red represents a magnet or winding with a "North" polarization, while green represents a magnet or winding with a "South" polarization).

Parts in a DC Motor
Every DC motor has six basic parts -- axle, rotor(armature), stator, commutator, field magnet(s), and brushes. In most common DC motors, the external magnetic field is produced by high-strength permanent magnets. The stator is the stationary part of the motor -- this includes the motor casing, as well as two or more permanent magnet pole pieces. The rotor (together with the axle and attached commutator) rotate with respect to the stator. The rotor consists of windings (generally on a core), the windings being electrically connected to the commutator. The above diagram shows a common motor layout -- with the rotor inside the stator (field) magnets.
The geometry of the brushes, commutator contacts, and rotor windings are such that when power is applied, the polarities of the energized winding and the stator magnet(s) are misaligned, and the rotor will rotate until it is almost aligned with the stator's field magnets. As the rotor reaches alignment, the brushes move to the next commutator contacts, and energize the next winding. Given our example two-pole motor, the rotation reverses the direction of current through the rotor winding, leading to a "flip" of the rotor's magnetic field, driving it to continue rotating.
In real life, though, dc motors will always have more than two poles. In particular, this avoids "dead spots" in the commutator. You can imagine how with our example two-pole motor, if the rotor is exactly at the middle of its rotation (perfectly aligned with the field magnets), it will get "stuck" there. Meanwhile, with a two-pole motor, there is a moment where the commutator shorts out the power supply (i.e., both brushes touch both commutator contacts simultaneously). This would be bad for the power supply, waste energy, and damage motor components as well. Yet another disadvantage of such a simple motor is that it would exhibit a high amount of torque "ripple" (the amount of torque it could produce is cyclic with the position of the rotor).

Armature

The use of an iron core armature is quite common, and has a number of advantages. First, the iron core provides a strong, rigid support for the windings -- a particularly important consideration for high-torque motors. The core also conducts heat away from the rotor windings, allowing the motor to be driven harder than might otherwise be the case. Iron core construction is also relatively inexpensive compared with other construction types.
But iron core construction also has several disadvantages. The iron armature has a relatively high inertia which limits motor acceleration. This construction also results in high winding inductances which limit brush and commutator life.

Lets have a look on this video that explain the principle of dc motor. http://www.youtube.com/watch?v=nM6bmQ-VEI0


typical dc brushed motor




Wednesday, 7 November 2012

Line tracking using IR sensor and Voltage Comparator


Why We need Voltage Comparator?

For a prototype hand held tachometer project, a microcontroller analyzed a phototransistor(receiver of IR sensor) and a pair of potentiometers using three built-in analog-to-digital (ADC) converters. Unfortunately, that design required the microcontroller to spend most of its time reading the phototransistor’s voltage in order to detect a passing line or mark.
It turns out that a dedicated comparator chip is a superior solution. Comparators constantly compare pairs of voltages and provide a digital indication ('1' or '0') of which voltage is higher. Using the dedicated chip frees the microcontroller, which is now only interrupted when the digital signal changes.
If your project requires a microcontroller, but the microcontroller doesn’t have any available ADCs, perhaps adding a comparator chip would provide a faster, less expensive solution.

example of application of  LM239 



The LM239 is a quad, single-supply comparator.
Quad: Can compare four different pairs of voltages.
Only half the comparator inputs were used since this example compares the phototransistor (U1) to one potentiometer (R1) and also compares the phototransistor (U1) to the other potentiometer (R2). The four unused inputs (lower-right of the IC) are connected to ground. The two unused outputs (lower-left of the IC) remain disconnected.
Single-Supply: The same power source provides the ground for the inputs, the chip itself, and the outputs. If necessary, use a dual-supply chip to prevent ground noise from one circuit at the inputs from affecting the other circuit at the outputs. Electrical noise isn’t an issue for this light detector, but could be for a circuit involving motors, spark-plugs, RF, or amplifiers.

Comparator: Connect two wires as inputs. If input A has a lower voltage than input B, the output goes low (to ground). If input A has a higher voltage than input B, the output disconnects. Oh no! I wanted low and high, not low and disconnect. Using a pullup resistor (R5) allows the disconnected output to go high (to +5 V).
The LM239 is pin compatible with MC3303, LM339, and LM2901 chips. Although their operating temperature ranges differ (and a few other differences) they’ll all work fine in this project.

C1

The 0.1-microfarad capacitor stores a small amount of power so that the comparator (IC1) has a stable supply. This is a very common use of a capacitor. It is called a “decoupling capacitor” in this usage.
A decoupling capacitor also absorbs or smooths short-lived higher voltage spikes. In this application, the capacitor doesn’t prevent the comparator from oscillating due to noise when the inputs are nearly identical.

R5 and R6

These 10-kilohm resistors are used in a very common way. They provide a +5-volt signal unless something to which they are connected provides GND.
A resistor in this configuration is called a “pullup resistor”. It pulls up the line to +5 V unless something stronger pulls it down.
Oddly enough, the comparator chip only provides an output of GND. So, the pullup resistors provide +5 V to the comparator outputs.
In this circuit, LEDs are hooked up to the outputs instead of a microcontroller or logic chips. So, R5 and R6 could be discarded from this circuit since only GND is needed to power the LEDs.

R3 and R4

These 470-ohm resistors limit the current going through each LED (LED1 and LED2). The LEDs can be made brighter with a lower value resistor (such as 220 ohms) or dimmer with a higher value resistor (such as 1 kilohm).

LED1 and LED2

Standard red and green LEDs.
They’re placed in “backwards”, so that the power goes from +5 V through each LED into the outputs of IC1. This is because the comparator chip can sink (ground) up to 16 milliamps of current, but can’t source (positive supply) any. No big deal, we just need to remember that the LED lights up opposite to what we’d normally expect on the output.

U1

This phototransistor is sensitive to normal visible light (800 nm). Infrared phototransistors can be used, but won’t be as sensitive to flashlights and other household sources.
The detector is classic for my projects. The sensor can be purchased from Jameco Electronics, part number 120221, product number BPW77.

R7

This combination of 22-kilohm resistor and phototransistor (U1) forms a voltage divider. If the light is bright, then the phototransistor uses very little voltage and R7 uses almost all of it. If the light is dim, then the phototransistor uses most of the voltage, so R7 gets almost none of it.
You'll notice the green wire coming from between the phototransistor and R7. This green wire is connected to two comparator inputs. The voltage of this wire is the same as the voltage that resistor R7 gets.



R1 and R2

These 10-kilohm potentiometers are variable resistors acting as voltage dividers. Five volts is connected to one end and GND to the other. The middle pin provides some voltage in between as the dial is adjusted back and forth.
The middle pin of each potentiometer is connected to input pins on the comparator (IC1). The comparator now has everything it needs to perform a comparison! It compares the middle pin of a potentiometer to the green wire in between U1 and R7. It compares the middle pin of the other potentiometer to the same green wire in between U1 and R7.

A Trick

In order to have the “backwards”-installed green LED turn on when the phototransistor is bright (using no voltage) and have the red LED do the opposite, the input wiring needs to be experimented with a bit.
The obvious condition is that the red inputs are wired the opposite of the green inputs. If the LEDs light up opposite of desired, swap the input from the potentiometer with the inputs from the phototransistor.
You can carefully think your way through the process to determine the correct layout or experiment on a solderless breadboard. This isn’t a serious problem, since the worst case is the LEDs aren’t lighting up when desired; they aren’t going to explode anything like that.

Lets have a look on a line follower robot that apply comparator to perform line following. http://www.youtube.com/watch?v=LMZtUnKGUwQ