Sunday, 10 June 2012

Computer Controlled Wireless Robot

The main objective of this project is to design a robot that can be controlled wirelessly from a computer serial port.



It consists of 2 modules

1. Transmitter


The transmitter consists of 8051 module with a serial port and interfaced to a RF Transmitter module. The microcontroller reads the commands sent by the computer from the serial port, interprets for the direction of the robot and sends the command to RF Transmitter and an acknowledgement back to Computer. We have commands such as "Left" - L, "Right" - R, "Forward" - F, "Reverse" - B, "Stop" - S.

For example, if a code "R" is sent from the Computer serial port the microntroller sends "0x01" to RF Transmitter and a string "Right" back to the computer indicating the direction the robot is going to move.

To Interface 8051 with RF Transmitter, we use a Encoder IC HT12E. A0 to A9 on HT12E represents the address and we have it set to 0x00. Data pins D3 to D0 on the encoder is interfaced with P1.0 to P1.3 of 8051. TE pin of encoder is "Transmission Enable" which enables  transmission of data only when it is "Active Low". In our case, the transmission enable is controlled programatically with P1.4 of 8051. The complete circuit is below.


8051 Microcontroller interface with RF Transmitter HT12E
8051 Interfacing with RF Transmitter and Encoder HT12E

2. Receiver


The 8051 interprets the commands received by RF receiver and sends appropriate signals to H- Bridge for the control of the robot.

The receiver consists of

a. RF Receiver
b. Decoder Chip HT12D
c. 8051
d. H-Bridge L293D
e. DC motors.

To Interface 8051 with RF Receiver, we use a DecoderIC HT12D. A0 to A9 is complementary to Address set on Encoder and hence it is 0x00. Data pins D3 t0 D0 are interfaced to pins P1.0 to P1.3 of 8051. Whenever data is received, Pin 17 of the decoder goes high. We use a switching transistor to invert it to "Active Low" to enable us to interface it with "Active Low" INTO Interrupt of 8051. So whenever data is received, INT0 is triggered. The microntroller reads the data from the P1.0 to P1.3 and sends appropriate signals to H-Bridge via P0.0 to P0.3 to control the motors.


8051 Microcontroller Interface with RF Receiver HT12D
8051 Interface with RF Receiver and RF Decoder HT12D

Tuesday, 8 May 2012

GeoLocation Tracking with GPS and GSM

The main objective of this project is to design a system where the location of the client module can be remotely sent to a customer on demand in human readable address


It consists of 2 main modules

1. Server Module

  • GSM modem : The server GSM modem will take the request from the customer in the form of a SMS to track the client module
  • Server Application : The server application keeps polling the server GSM modem for any request from customer or response from client module. For any request from customer, it will send a request to client module to send the Geo Location data. In case of response from client module, it will Reverse Geocode the Co Ordinates using Yahoo&Reg/ Google&Reg reverse geocoding service and send an SMS with the location in a human readable address

2. Client Module

  • GSM modem : The client GSM modem is used to receive and respond to location request
  • ARM processor : When there is request on the location, the ARM processor takes the raw data from GPS receiver and converts them to Geolocation Co-ordinates and sends the same to Server module using client GSM modem

Note:

  • In this project we wanted to send the location as human readable address and hence Yahoo® / Google® Reverse Geo Coding is used. In case only Geo Co ordniates is required to be sent, it will not require a Server Module
  • Below are the examples of Rest Webservices of Reverse Geocoding. The XML is parsed in the Server Application program
        Google® : http://maps.googleapis.com/maps/api/geocode/xml?latlng=12.971891,77.641154&sensor=true

        Yahoo® : http://where.yahooapis.com/geocode?q=12.971891,77.641154&gflags=R&appid=[yourappidhere]
  • The processor in the client module required 2 serial ports one for GSM modem and the other for GPS reciver. Hence ARM processor was chosen over 8051

Monday, 16 April 2012

LCD Interface with 8051 Microntroller


C Code


#include <regx51.h>
#define LCD_COMMAND 0
#define LCD_DATA 1
#define LCD_RS P0_0       //Edit it per your circuit design
#define LCD_RW P0_1       //Edit it per your circuit design
#define LCD_EN P0_2       //Edit it per your circuit design
#define LCD_PORT P2       //Edit it per your circuit design

char *message_1 = "electronicsprojs";
char *message_2 = ".blogspot.com";

/*Function Prototypes*/

void LCD_delay(unsigned int);
void LCD_putc(int,int);
void LCD_puts(unsigned char*);
void LCD_init();

main()
{
 LCD_init();
 LCD_putc(0x80,LCD_COMMAND); //Write to Row 1
 LCD_puts(message_1);
 LCD_putc(0xC0,LCD_COMMAND); //Write to Row 2
 LCD_puts(message_2);
 LCD_delay(1000);
 while(1);
}

void LCD_init()
{
 LCD_EN = 1;
 LCD_RS = 0;

 LCD_putc(0x38,LCD_COMMAND); //Use 2 lines 5X7 matrix
 LCD_putc(0x0C,LCD_COMMAND); //Display on Cursor on
 LCD_putc(0x01,LCD_COMMAND); //Clear Screen
 LCD_delay(256);
}

void LCD_delay(unsigned int i)
{
 while(i>0)
  i--;
}


void LCD_putc(int character, int type)
{

 LCD_delay(10);
 LCD_RS = type;  //1 : Write Data, 0 : Write Command
 LCD_RW = 0;
 LCD_PORT = character;
 LCD_EN = 0;   //Latch data with a low to high pulse
 LCD_delay(10);
 LCD_EN = 1;
}

void LCD_puts(unsigned char *string)
{

 while (*string)
 {
  LCD_putc(*string++,LCD_DATA);
 }
}


Sunday, 1 April 2012

Infrared Beam Break Detector

This purpose of this article is to design a circuit using Infrared signals to detect a beam break which can be used in multiple real world applications. The IR receiver used is TSOP1738. Below are some of the main requirements of Infrared Transmiter signal properties as described in the datasheet
  • Carrier frequency should be close to the  center frequency of the bandpass (38kHz)
  • Burst length should be 10 cycles/burst or longer
  • After each burst which is between 10 cycles and 70 cycles a gap time of at least 14 cycles is neccessary

Design


1. Carrier Frequency (f1) : The center frequency of TSOP1738 is 38kHz

f1 = 1.44/((Ra1+2Rb1)C)
f1 = 38kHz

Let
Ra1 = 1k
C = 0.01uF

With that Rb1 = 1.394k or
Rb1= 2k variable resistor


2. Burst and Gap frequency (f2) : Let burst cycle equals gap cycle be equal to 40 cycles (burst between 10 and 70 cycles and gap greater than14 cycles)

f2 = 38k/ 40
f2 = 950
f2 = 1.44/((Ra2+2Rb2)C)

Let
Ra2 = 10k
C = 0.01uF

With that
Rb2 = 70.789k or
Rb2 = 100k variable resistor

Note:
1. BC547 is used at the output of transmitter as switching transmitter to boost the voltage increasing the range.

2. When the Infrared beam is broken, the output of TSOP1738 goes high. Using switching transistor 2N2222, the signal is inverted to High to Low which can be directly interfaced to External edge triggered interrupts of 8051 (EXT0 and EXT1)

Infrared beam break detector transmitter receiver circuit

Saturday, 31 March 2012

Global Positioning System – How does the receiver calculate the range from satellites?

It is now clear from the previous discussion that the receiver has to calculate the distance of the GPS antenna (range) w.r.t each of the satellites that it is tracking1.

The GPS satellite signal structure plays a major role in this range estimation. GPS transmissions utilize Direct Sequence Spread Spectrum (DSSS CDMA) modulation technique in which each satellite is associated with a unique code (called the Pseudo-random code or PRN code). The data from each satellite is first encoded using this PRN code and then transmitted using BPSK modulation.

There are two types of codes that a GPS satellite uses – the coarse acquisition or the C/A code and the precise P code. Most of the commercial GPS equipments only utilize the C/A code for position determination (More on the signal structure in future blogs). For the moment let us just note that these codes are a special category of PRN codes called the “Gold codes” which have exceptional auto-correlation and cross-correlation property. These properties mean that –

  • The PRN code of a satellite has very little or no similarity with the shifted version of itself
  • The PRN code of any one satellite has very little or no similarity with the PRN codes (even shifted versions) of all other satellites

Hence in order to decode the data from the satellite, the receiver must produce a replica of the PRN code (which acts like a key to the locked data), which not only matches with the satellite Id but also matches the time shifts incurred due to propagation from satellite t user. Let us see this in more detail.

Consider the following case in which the satellite has transmitted the signal at t = t0 s. But due to the propagation delay, it has reached the receiver after a delay of td seconds –

The task of the receiver is thus to generate the replicas of the PRN code for the satellite with all possible shifts and determine that amount of shift for which the incoming PRN code matches the generated code (i.e. has the&nbsp; maximum correlation).
Now, if the time at which the satellite has transmitter the signal is known (t0) and the satellite clock and receiver clock are in perfect synchronization, then the shift required to match the incoming signal would exactly provide us with the propagation delay td. The range or the distance is immediately determined as this ∆t multiplied by the speed of light c (approximately 3 x 108 m/s).

But, the story is not that simple. The satellite clock is a very high precision atomic clock and the clock at the receiver is a low precision clock. Hence the propagation delay thus obtained suffers from what is called “user clock bias”.  One good thing about this clock bias is that since all the satellites are perfectly synchronized (or in other words, their errors can be estimated to high degree of accuracy), this user clock bias is a common error to all the satellite signals. This clock bias is the fourth variable in the range equations that needs to be estimated.


The range information thus obtained does not truly provide us with the geometric range of the satellite to the user but contains
  1. Geometric range from satellite to user
  2. User clock bias factor
  3. Offset between the system time and satellite clocks
  4. Other delays due to atmospheric errors (ionospheric and tropospheric)
Hence this range is referred to as “Pseudo range” rather than actual range.


Let us assume that the satellite clock bias can be accurately estimated and the atmospheric errors can be neglected (as of now). We can thus construct the range equations from the pseudo-range measurements from (at-least) four satellites as:

R1=√((x1 - xu)2 + (y1 - yu)2) + (z1 - zu)2) + ctu

R2=√((x2 - xu)2 + (y2 - yu)2) + (z2 - zu)2) + ctu

R3=√((x3 - xu)2 + (y3 - yu)2) + (z3 - zu)2) + ctu

R4=√((x4 - xu)2 + (y4 - yu)2) + (z4 - zu)2) + ctu

Where,
  • R1 to R4 are the pseudo-ranges from four satellites being tracked
  • (x1,y1,z1) correspond to the position of satellite 1 in x, y, z coordinates (and similarly for other satellites)
  • (xu,yu,zu) correspond to the position of user in x, y, z coordinates is the range due to user clock bias
Solving these equations for a Least-Square solution yields us the estimations of the user position.
The GPS system not only provides us with accurate position information but also accurate velocity and time information as well. Hence the complete GPS solution is called a PVT solution (Position, Velocity and Time). We shall discuss more on how each of them is extracted in future blogs.
1Tracking is a process of continuously monitoring the satellite signal parameters and extracting information from them

Saturday, 17 March 2012

Sending SMS using AT Commands

This article describes sending a SMS from a Microcontroller through a GSM modem using AT Commands. through RS232. AT commands can be sent to a GSM modem via a computer serial port or from the serial port of a 8051 Microcontroller.

Computer serial port


1. Connect your GSM modem to the computer serial port. New systems nowadays dot not have serial port, hence you would need to buy a USB to serial converter and connect the GSM modem to it.

2. If you are using Windows XP® OS, open Programs -> Accessories -> Communications -> HyperTerminal

3. Select the COM port you have the modem connected to.

4. Check the port settings, make sure that the baud rate matches with that of the GSM modem and and also that the Flow Control is set to "None".

5. Type the AT Commands below in the HyperTerminal Editor

AT+CMGF = 1 and Enter
AT+CMGS="+919449XXXXXX" and Enter
"Electronicprojs.Blogspot.com" and Hit CTRL+Z

6. In Windows 7® OS though, there is no hyperterminal program inbuilt. You will have to download a similar one. There are many good free programs available.

7. You would need to note that in this case we are connecting the serial port cable from Female pin (GSM Modem) to Male pin (Computer). Hence no crossing is required. In other words, we should use a straight cable.

8051 MicroController Serial port


1. 8051 SFR's are programmed for a baud rate of 9600.

2. Send the AT commands in #5 above through code. For Enter use escape character "\r" and for CTRL+Z use ASCII 0x1A.

3. The serial port cable is connecting from Female pin (GSM Modem) to Female (8051 Board). So you need a have a female to male converter. Also, make sure that the Rx and Tx inside in the converter are crossed. In otherwords, the Rx pin of GSM Modem should go to Tx pin of 8051 microntroller. This is called a crossed cable.

4. Below is the C program using Keil® Compiler for 8051. We added infinite while loop after the sendsms() routine because otherwise we found that the code compiled was sending the SMS in a infinite loop.

Note : Beginners always complain about their code working through serial port of a computer but the same not working through chip. It is very essential to understand the difference between crossed cable and straight cable as well as the pins configurations of male and female connectors before starting.

C program

#include <REGX51.H>
#include <AT89X51.H>

unsigned char *command_AT = "AT\r";
unsigned char *command_CMGF = "AT+CMGF=1\r";
unsigned char *command_CMGS = "AT+CMGS=\"+919449XXXXX\"\r";
unsigned char *message = "electronicprojs.blogspot.com";
unsigned char CTRLZ = 0x1A;

void puts(unsigned char* ptr);
void putc(unsigned char chr);
void sendsms(void);
void initialize();

main()
{
initialize();
sendsms();
while(1);
}

void initialize()
{
SCON  = 0x50;   /*SCON: mode 1, 8-bit UART, enable receive      */
TMOD |= 0x20;   /*TMOD: timer 1, mode 2, 8-bit                  */
TH1   = 0xFD;   /*TH1:  for 9600 baud                           */
TR1   = 1;      /*TR1:  timer 1 run                             */

}

void sendsms()
{
puts(command_AT);
puts(command_CMGF);
puts(command_CMGS);
puts(message);
putc(CTRLZ);
}

void puts(char* p)
{
char *temp = p;  /*temp pointer so that the actual pointer is not displaced */
while(*temp != 0x00)
{
putc(*temp);
temp++;
}
}

void putc(unsigned char chr)
{
SBUF = chr;
while(TI==0);  /*Wait until the character is completely sent */
TI=0;                    /*Reset the flag */
}

Tuesday, 6 March 2012

Global Positioning System (GPS) - Introduction

Global positioning system (GPS) is a satellite based navigation system that provides the user with accurate position and time information. Today we find GPS receivers in almost every field – right from car navigations systems to missile launches, mobiles to aircraft - GPS is becoming an integral part of our lives. Here is an attempt to make the readers better understand the GPS system and to some extent, the techniques involved in its working

GPS consists of a constellation of satellites (at least 24) that are deployed into orbits of 20000km. The data transmitted by the satellites is a Direct sequence spread spectrum (DSSS) signal with each satellite having a unique PRN (pseudo random noise) code of its own. The satellites are identified by this unique code that is a part of the signal that they transmit. The satellites have Ids from 1 to 32.

The orbits are inclined at an angle of 55 degrees to the equatorial plane. The choice of orbit is such that there are at-least 5 satellites visible to a GPS receiver (with an open sky view) from any point on earth. The satellites orbit the earth with an orbital period of 12hrs. Hence the visibility scenario at any point on earth repeats itself every 24 hrs. It simply means that, if at a particular point on earth, I see satellites with Ids 2, 4, 10, 17, 25, and 20 then I would see the same set of satellites tomorrow at the same time.

The basic idea of GPS positioning – Trilateration

Trilateration is the basic theory behind GPS positioning. Let me explain this in very simple terms.Consider a planar (2D) system in which I have three reference points or base stations (BS) which are transmitting signals and a mobile station (MS) or a receiver capable of receiving and decoding the signal from these base stations. The positions of these BS are fixed and are known to the MS.

Let us assume that the data sent by each of the BS has sufficient information such that the MS is able to calculate the accurate range or distance from the BS i.e. if MS decodes signal from BS1, it can obtain its exact distance from BS1.


Now, I know my distance (d1) from BS1 and as said earlier, I know the location of BS1. This means that the position of the MS is anywhere on the circle centered at BS1 and with a radius d1.




Similarly if the MS can decode the signal from BS2 and obtain the distance d2 from it, then the ambiguity associated with the position of MS reduces to the intersection of the two circles (with BS1 and BS2 as centers and d1 and d2 as radius respectively). Hence the position is either point A or point B as shown in the figure. Extending this idea to one more BS reduces the ambiguity to a point that is the intersection of all the three circles thus formed.


Now that you are convinced with the position determination in 2D space, we can extend the same to position determination in 3D space with MS being your GPS receiver and BS being the satellites in orbit. The range information from one satellite would give you a sphere, two satellites would give you a circle and three satellites would give you two points. One of these points, the true position will be towards the surface of the earth and the other will be on the other side of the satellite orbit and is discarded.

NOTE:
  • Even though it seems that only three satellites are essential for position determination, in practice 4 are required due to the low precision clock on the receiver (more about this later)
  • The positioning can also be thought of as a linear system of three unknowns (position co-ordinates x, y, and z) of the receiver, which requires at-least three equations to solve. These three equations are obtained by three satellites.
  • The fourth unknown called the user clock bias requires the range information from the fourth satellite.