Friday, 8 February 2013

Basic PC controlled robot

             A PC controlled robot is robotic platform that operates based on the data transmitted from the PC 
 serial COM port.

COM port is a 9 pin port that transmit data serially using UART(Universal asynchronous reception and transmission)  protocol. This is a full duplex which means one can transmit and receive data simultaneously.
Just like a USB port a PC will have a COM port at its back. It looks like this...
     
        
                             

Though this port is having 9 pins we deal with only two pins. The are...
         PIN 2:Serial Receiver(Rx)
              PIN 3:Serial Transmitter(Tx) 
PIN 5:Signal Ground 
if your PC is not having a serial port you can use a USB to Serial cable..

The connections of of PC and microcontroller will be as follows

We connected the circuit....but ..
Can a microcontroller understand the data sent by a PC ?
Have you seen the word "TTL" in the above picture..........? 
it stands for (Transistor Transistor Logic). In which a logic '0' is represented by 0V
                                                                                logic '1' is represented by 5V
but the data transferred from the PC will follow RS-232(Recommended standard) logic
The RS-232 standard defines the voltage levels that correspond to logical one and logical zero levels for the data transmission and the control signal lines. Valid signals are either in the range of +3 to +15 volts or the range -3 to -15 volts; the range between -3 to +3 volts is not a valid RS-232 level. For data transmission lines (TxD, RxD and their secondary channel equivalents) logic one is defined as a negative voltage, the signal condition is called marking. Logic zero is positive and the signal condition is termed spacing.  

So to convert the voltage levels we need a level converter. MAX232 chip is used to do this job.

MAX232 connections with PC 

Basically PC will have a male port. so take a female port and make this circuit and connect to the PC and microcontroller.



   now your microcontroller will receive the proper data from PC
Here comes the Question what microcontroller to choose?

Here i'm considering 8051 microcontroller...for beginners



now after the connection..... the programming for 8051 using keil microvision 3

Connecting motors to the microcontroller using an L293D motor driver
i connected the RA(1234) pins to Port1 lower pins
P1.0=>PA0
P1.1=>PA1
P1.2=>PA2
P1.3=>PA3

 before going through the code reader must know about 8051 microcontroller.
if you press reset it says "HEY" on hyper terminal

Code:
#include<reg51.h>

void serial_init()     // Initialize Timer 1 for serial communication
{
TMOD=0x20;  //Timer1, mode 2, baud rate 9600 bps
TH1=0XFD; 
SCON=0x50;
TR1=1;
}

unsigned char  recieve()  //Function to receive serial data
{
   unsigned char value;
   while(RI==0);
   value=SBUF;
   RI=0;
    return value;
}

void transmit(unsigned char data)  // Funtion to transmit serial data
{

SBUF=data;
while(TI==0);
TI=0;
}

void main()
{serial_init();
transmit('H');transmit('E');transmit('Y');// display "HEY" on serial hyperterminal
unsigned char x; while(1) { x= recieve();
if(x==w)
P1=0x0a;// forword
else if(x==a)
P1=0x06;// left turn
else if(x==w)
P1=0x09;// right turn
else if(x==w)
P1=0x05;// back
else
P1=0x00//stop
}
}
to execute this project you will need to open hyper terminal which is not possible in Windows7  instead you can use the following softwear
DOWNLOAD:  udp://tracker.ccc.de:80/announce
   select your COM port and settings as shown in the picture...
and type the data....in the field....
it starts.....working enjoy...............................................................

Sunday, 3 February 2013

interfacing 4*4 matrix keypad to Microcontroller



What is matrix key pad?

  Ans:  A matrix key pad is a two dimensional arrangement of switches in row and columns. This arrangement follows an algorithm to get the status of the keys. Here comes the questions:
 How a switch works ?
A switch is nothing but two conductive terminals and an adjustable contact that connects the two terminals. So that one can adjust a the position of the switch manually to make circuit "OPENED"  or "CLOSED"

        This switch  is called a "Tact switch",which is generally used to make matrix keypads. it consists of four terminals but opposite pins are shorted internally.
                                          How to connect the switch to a microcontroller?       
Before that don't forget that a switch simply "closes" or "opens" a circuit. 
But a microcontroller is a digital device that only understands "ZERO(0V)" or "ONE(5V)".
so we need a circuit that indicate the status of a switch in turms of "0" or '1"....
here it goes.....     

working of the circuitry is left to the reader's assignment
if switch close=1 and switch open =0 then it is called active high logic
if switch close=0 and switch open =1 then it is called active low logic


  • Reader must Google about the concept of    "Pull-up" and "Pull-down" resistor
  • The resistor in the above circuit prevents the              circuitry from "short circuit of  Vcc and Gnd" when the switch is pressed.


Now we go for the matrix key pad arrangement. Take a look at the figure below. the keys are arranged in   four rows and four columns. 
So we got 4+4 pins to interface this matrix key pad to the microcontroller.
Now how to check weather a switch is pressed or not....

The basic algorithm for matrix key pad ....
  Let us assume the row pins and columns are connected an 8 pin port
     7       6      5      4      3      2      1     0 
  R1   R2     R3    R4    C1   C2   C3   C4 
  
  1. Configure all row pins of microcontroller as outputs and column pins as input .(7,6,5,4 are output and 3,2,1,0 are input.) 
  2. pull -up all column pins
  3. write '1's to row pins so all row pins are at high state. 
  4. make R1 pin 0 and remaining pins high
  5. scan each column pin (if any key is pressed in this row then that particular column pin will be zero)
  6. make R2 pin 0 and remaining pins high
  7. scan each column pin (if any key is pressed in this row then that particular column pin will be zero)
  8. make R3 pin 0 and remaining pins high
  9. scan each column pin (if any key is pressed in this row then that particular column pin will be zero)
  10. make R4 pin 0 and remaining pins high
  11. scan each column pin (if any key is pressed in this row then that particular column pin will be zero)   
This is basic algorithm. initialize a variable and return the corresponding value to the variable. This algorithm
will be same for all microcontroller. Some expert developers add some additional hardware to it and makes it more reliable.