DC Motors are small, inexpensive and powerful motors used widely in robotics for their small size and high energy out. A typical DC motor operates at speeds that are far too high speed to be useful, and torque that are far too low. Gear reduction is the standard method by which a motor is made useful .Gear’s reduce the speed of motor and increases the torque.

Choosing a DC Motor Depends on application.Prefer following:

  • DCMotor with Gear head
  • Operating voltage 12V
  • Speed

Drive basics of DC Motor

Red wire Black wire Direction of rotation
Positive Negative Clock wise
Negative Positive Anti clock wise
Logic Logic Direction
1 0 Clock
0 1 Anti clock
Direction Pulse to
Clock wise A and C
Anti Clock wise B and D

Bi-Direction control of DC Motor

H-Bridge Circuit using transistors for bidirectional driving of DC motor. H-Bridges in IC’s to reduce the drive circuit complexity . L293D is a dual H-Bridge motor driver, So with one IC we can interface two DC motors which can be controlled in both clockwise and counter clockwise direction and if you have motor with fix direction of motion the you can make use of all the four I/Os to connect up to four DC motors. L293D has output current of 600mA and peak output current of 1.2A per channel. Moreover for protection of circuit from back EMF ouput diodes are included within the IC. The output supply (VCC2) has a wide range from 4.5V to 36V, which has made L293D a best choice for DC motor driver.

As you can see in the circuit, three pins are needed for interfacing a DC motor (A, B, Enable). If you want the o/p to be enabled completely then you can connect Enable to VCC and only 2 pins needed from controller to make the motor work.

**To Move the motor Clockwise And Anticlockwise,Must be use two separate Power source,one for microcontroller and another for driving motor with Driver IC.

Here,i have used ATMEGA32 micrcontroller and  Code is written in C  using AVR Studio 5.0.

Source Code

/*
* DCMotorControl.c
*
* Created: 4/1/2011 12:08:10 AM
*  Author: sfg
*/

#include <avr/io.h>
#include <util/delay.h>

int main(void)
{
DDRD=0xFF; //PORTD declared as output
PORTD=0x00;
DDRB=0x00; //PORTB as input
while(1)
{

//Pin 0 of PORTB high,then Moves Clockwise
//A–1–PD0
//B–0–PD1
//Enable–1–PD2
if(PINB==0x01)
{
PORTD=0x05;
//_delay_ms(5000);
}
//Pin 0 of PORTB Low,then Moves AntiClockwise
//A–0–PD0
//B–1–PD1
//Enable–1–PD2
else
{

PORTD=0x06;
//_delay_ms(5000);
}
}
}

Circuit Diagram

The first “Hello World!” project I prefer for Microcontroller is LED Blinking. I have used AVR  microcontroller .  Here,All pins of PORTB declared as output.

Source Code

Here,i have  written code  in C using AVR Studio 5.0.

/*
* ledblinking.c
*
* Created: 3/30/2011 9:36:30 AM
*  Author: sfg
*/

#include <avr/io.h>
#include <util/delay.h>

int main(void)
{
DDRB=0xFF; //all pins of PORTB declared as output
PORTB=0x00;
while(1)
{
//TODO:: Please write your application code
PORTB=0xFF;  //High State
_delay_ms(200); //delay
PORTB=0x00; //low state
_delay_ms(200); //delay
}
}

Circuit

Led blinking With Atmega32

The control signals for the rotation of the motor are provided by 8051 microcontroller.For basic concepts and know-how of a servo motor, refer to the article Servo Motor.

Source Code

Here,i have used AT89S51  microcontroller.Code is written in C using  Keil uVision4.
#include<reg51.h>
sbit output=P1^0;          //Output to motor

void timer(int msec)     // Function for timer
{
int i;

for(i=0;i<msec;i++)

{
TMOD=0x20;         // Mode2
TH1=0xFF;
TL1=0xD1;
//TH1= -23;        // 50usec timer
TR1=1;
while(TF1==0);
TF1=0;
TR1=0;
}
}

void main()
{
int i;

output=0;

while(1)
{
//anticlockwise direction
for(i=0;i<500;i++)
{
output=1;
timer(20);
output=0;
timer(360);
}
//clockwise direction
for(i=0;i<500;i++)
{
output=1;
timer(40);
output=0;
timer(360);
}
}
}

Circuit

Servo motor control

 

KEIL uVision is the name of a software dedicated to the development and testing of a family of microcontrollers based on 8051 technology,  which we are going to use along this tutorial. You can can download an evaluation version of KEIL at their website: http://www.keil.com/c51/. Most versions share merely the same interface, this tutorial uses KEIL C51 uVision 4 with the C51 compiler .

To create project,write and test the source code and also create hex file,follow the following steps:

Open Keil and Start a new project:


 

You will prompted to chose a name for your new project,chose  a name and click save.The following window will appear,where you will be asked to select a device for Target ‘Target 1’:

From the list ,select ATMEL and chose your microcntroller .The AT89s52 will be called your ‘Target device’ ,which is the final destination of your source code.You will be asked whether to copy standard 8051 startup code click No.

Click File,New and similar to the following window should appear.The blank space where your code should be written.

Now,You have to click ‘File ‘,Save as and chose a file name for code ending with the extension ‘.c’ and click save.Then you have to add this file to your project work space as shown in the following screen:

After right-clicking on ‘source group 1‘, click on ‘Add files to group…‘, then you will be prompted to browse the file to add to ‘source group 1’, chose the file that you just saved  and add it to the source group. You will notice that the file is added to the project tree at the left.

In some versions of this software you have to turn ON manually the option to generate HEX files. make sure it is turned ON, by right-clicking on target 1, Options for target ‘target 1’, then under the ‘output‘ tab, by checking the box ‘generate HEX file‘. This step is very important as the HEX file is the compiled output of your project that is going to be transferred to the microcontroller.

You can then start to write the source code in the window ‘ then before testing your source code, you have to compile your source code, and correct eventual syntax errors. In KEIL IDE, this step is called ‘rebuild all targets’ .

You can use the output window to track eventual syntax errors, but also to check the FLASH memory occupied by the program (code = 49) as well as the registers occupied in the RAM (data = 9). If after rebuilding the targets, the ‘output window’ shows that there is 0 error, then you are ready to test the performance of your code.

There are many other features to discover in the KEIL IDE. You will easily discover them in first couple hours of practice.

The first “Hello World!” project I prefer for Microcontroller is LED Blinking. I have used ATMEL’s 89C51 (40-pins DIP) 8051 architecture microcontroller which is ideal for first time learning MCU Chip.  The program is very simple and straight forward, that uses a delay procedure  loop based software delay.

Source Code

Here,i have  written code  in C using Keil uVision4.

#include <REGX51.H>
void msdelay(unsigned int );
void main(){

P2=0x00;  //all pin of PORT2 declared as output
//infinite loop
while(1){

P2=0xFF;   //all pin high
msdelay(250);    //delay
P2=0x00;   //all pin low
msdelay(250); //delay

}
}

//delay function
void msdelay(unsigned int value){

unsigned int x,y;
for(x=0;x<value;x++)
for(y=0;y<1275;y++);
}

In C programs you cannot be sure of delay, cause  it depends on compiler how it optimize the loops as soon as you make changes in the options the delay changes.

you will have to use Timers for making exact delays….. it does not matters whether u need delays of ms , us or even seconds…

below is a function of 1 second using timers…..

// the idea is to make a 50ms delay and run it 20 times as 20x50ms= 1000ms= 1sec

delay_1s() // timer of 1 sec
{
int d;
for(d=0;d<=20;d++)
{
TMOD=0x01;
TL0=0xFD;
TH0=0x04B;
TR0=1; // start timer.
while(TF0==0); // run until TF turns to 1
TR0=0; // stop timer
TF0=0; // reset the flag
}
}

Circuit Diagram

Led blinking with 8051 microcontroller

►Introduction

A stepper motor is a brushless, synchronous electric motor that converts electrical  pulses into mechanical movement. Every revolution of the stepper motor is divided into a discrete number of steps, and the motor must be sent a separate pulse for each step. The stepper motor can only take one step at a time and each step is the same size. Since each pulse causes the motor to rotate a precise angle, the motor’s position can be controlled without any feedback mechanism. As the electrical pulses increase in frequency, the step movement changes into continuous rotation, with the speed of rotation directly proportional to the frequency of the pulses. Step motors are used every day in both industrial and commercial applications because of their low cost, high reliability, high torque at low speeds and a simple, rugged construction that operates in almost any environment.

►Unipolar stepper motor
The unipolar stepper motor has five or six wires and four coils (actually two coils divided by center connections on each coil). The center connections of the coils are tied together and used as the power connection. They are called unipolar steppers because power always comes in on this one pole.

Unipolar Stepper Motor Windings

►Bipolar stepper motor
The bipolar stepper motor usually has four wires coming out of it. Unlike unipolar steppers, bipolar steppers have no common center connection. They have two independent sets of coils instead. You can distinguish them from unipolar steppers by measuring the resistance between the wires. You should find two pairs of wires with equal resistance. If you’ve got the leads of your meter connected to two wires that are not connected (i.e. not attached to the same coil), you should see infinite resistance (or no continuity).

Bipolar Stepper Motor windings

Stepper Motor interfacing with Microcontrollers

Stepper motors can be used in various areas of microcontroller projects such as making robots, robotic arm, automatic door lock system etc.Here,I will discuss different controlling types (Half step and Full step), Interfacing Techniques (using L293D or ULN2003) to control stepper motor.

Step Sequence

Stepper motors can be driven in two different patterns or sqeunces. namely,

  • Full Step Sequence
  • Half Step Sequence

►Full Step Sequence

In the full step sequence, two coils are energized at the same time and motor shaft rotates. The order in which coils has to be energized is given in the table below.

Full Step Sequence

►Half Step Sequence
In Half mode step sequence, motor step angle reduces to half the angle in full mode. So the angualar resolution is also increased i.e. it becomes double the angular resolution in full mode. Also in half mode sequence the number of steps gets doubled as that of full mode. Half mode is usually preffered over full mode. Table below shows the pattern of energizing the coils.

Half Step Sequence

►Step Angle

Step angle of the stepper motor is defined as the angle traversed by the motor in one step. To calculate step angle,simply divide 360 by number of steps a motor takes to complete one revolution. As we have seen that in half mode, the number of steps taken by the motor to complete one revolution gets doubled, so step angle reduces to half.

As in above examples, Stepper Motor rotating in full mode takes 4 steps to complete a revolution, So step angle can be calculated as…

Step Angle ø = 360° / 4 = 90°

and in case of half mode step angle gets half so 45°.

So this way we can calculate step angle for any stepper motor. Usually step angle is given in the spec sheet of the stepper motor you are using. Knowing stepper motor’s step angle helps you calibrate the rotation of motor also to helps you move the motor to correct angular position.


►Connecting Unipolar Stepper Motor with Microcontroller(PIC16F887) using ULN2003

Stepper Motor Interfacing with microcontroller Using ULN2003

►Connecting Unipolar Stepper Motor with Microcontroller(PIC16F887) using L293D

Stepper Motor Interfacing With microcontroller Using L293D

Source Code

Here,I  have used PIC16F887  Microcntroller  and Code is written in C using mikroC PRO for PIC.Adjusting the delay will increase or decrease the speed of the motor. Here just for demonstration i have taken some delay, you can change it as you want.

►Programming Full step Sequence

void main() {ANSEL  = 0;                // Configure AN pins as digital I/O
ANSELH = 0;
PORTD = 0;
TRISD = 0;                 // Configure PORTD as output

while(1){
PORTD=0x09;
Delay_ms(500);
PORTD=0x0C;
Delay_ms(500);
PORTD=0x06;
Delay_ms(500);
PORTD=0x03;
Delay_ms(500);
}
}

►Programming Half step Sequence

void main() {

ANSEL  = 0;                // Configure AN pins as digital I/O
ANSELH = 0;
PORTD = 0;
TRISD = 0;                 // Configure PORTD as output

while(1){
PORTD=0x08;

Delay_ms(500);
PORTD=0x0C;
Delay_ms(500);
PORTD=0x04;
Delay_ms(500);
PORTD=0x06;
Delay_ms(500);
PORTD=0x02;
Delay_ms(500);
PORTD=0x03;
Delay_ms(500);
PORTD=0x01;
Delay_ms(500);
PORTD=0x09;
Delay_ms(500);

}
}


Bluetooth® wireless technology is becoming a popular standard in the communication arena, and it is one of the fastest growing fields in the wireless technologies. It is  convenient, easy to use and has the bandwidth to meet most of today’s demands for mobile and personal communications. Bluetooth technology handles the wireless part of the communication channel; it transmits and receives data wirelessly between these devices. It delivers the received data and receives the data to be transmitted to and from a host system through a host controller interface (HCI). The most popular host controller interface today is either a UART or a USB .Here,I will only focus on the UART interface, it can be easily show how a Bluetooth module can be integrated on to a host system through a  UART connection and provide the designer an optimal solution for Bluetooth enabled systems.

Here,I will show two examples of  hardware interface between Bluetooth wireless technology and UART.One example shows an interface between an  Bluetooth module and a PC via UART, and the other example shows an interface between a Bluetooth module and a  Microcontroller via UART.

I have a used WT32 bluetooth module.To know more click here.

WT32 Bluetooth module

Supply voltage at VCC  pin can vary between 1.8 V and 3.3 V. VCC and BTEN  combined to a single 3.3 V supply voltage.

Interface between an  Bluetooth module and a PC via UART

Now connect the PC with Bluetooth module through RS232 over MAX232 or MAX233 level converter.

Bluetooth module Connection with PC

Now,Test  the connection with hyperterminal or any serial port communication software .Here,I have used hyperterminal for test.

Hyperterminal settings

 

– 9600 baud
– no parity
– 8 databits
– no flowcontrol
– 1 stopbit

You can be change this settings via hyperterminal with WT32 bluetooth module command.See more in user guide.

Interface between an  Bluetooth module and a Microcontroller via UART

Connect the bluetooth module with microcontroller.Here,I have used PIC16F887 microcontroller.

Now,Test the Communication between PC and Microcontroller Device.You can use the following code that is written in C using mikroC PRO for PIC.

Source Code

char uart_rd;
void main() {
ANSEL  = 0;                     // Configure AN pins as digital
ANSELH = 0;
UART1_Init(9600);               // Initialize UART module at 9600 bps
Delay_ms(100);                  // Wait for UART module to stabilize
while (1) {                     // Endless loop
UART1_Write_Text(“TEST”);
Delay_ms(2000);                  // Wait

}
}

Output

Now,you can be see the Data “TEST” on Hyperterminal that will send by microcontroller via Bluetooth Module.

Hyperterminal

Read the rest of this entry »

Follow

Get every new post delivered to your Inbox.

Join 50 other followers