automated room area measurement
Embed Size (px)
TRANSCRIPT

1
CHAPTER 1
INTRODUCTION
Nowadays there are many robotic mapping systems. But those systems use
very complex algorithms and image processing techniques. Here developed a system which
uses simple algorithm with minimum requirements. This project is intended measure the area
of room with any shape. The system utilized IR based distance sensor which is mounted on a
stepper motor, PIC 18f452 as the brain of the device, two wheels which is mounted on
stepper motors, a caster wheel and a Zigbee module for wireless communication. A server PC
will control the device remotely.

2
1.1. BASIC IDEA FOR AREA MEASUREMENT
Figure1.1. Room segmentation
Consider a square room and the figure above is the top view. The total area
can be divided into small sectors as shown above. Find out the area of each sectors and the
integration of all the sectors will give the total area. Smaller the sectors better the accuracy.
Figure1.2. Example for room segmentation
Consider the device is in the centre of the room. From there it will measure
each distance. A stepper motor with 1.8º step angle is used for mounting the sensor. So that
the total field of 360º is divided into 360º/1.8º = 200 units.

3
1.2. CALCULATIONS
Figure1.3. Figure of area calculation method
Let above be the top view of the room which is to be measured. The device
will calculate the distances d and c, the angle A is known (here 1.8º). Now the area of a single
sector can be calculated as;
By Heron’s formula,
As(i) = 𝑠 𝑠 − 𝑎 𝑠 − 𝑏 (𝑠 − 𝑐) [As(i) = area of a sector, s = 𝑎+𝑏+𝑐
2 ]
By cosine rule,
CosA = 𝑏2+ 𝑐2−𝑎2
2𝑏𝑐, a = 𝑏
2+ 𝑐2 − 2𝑏𝑐 𝑐𝑜𝑠𝐴
Total area, As = As (1) + As (2) + As (3) + As (4) + …..+ As (n)
Here n = 200
This type of area measurement is true from any point in the room rather than
the centre. But more accurate measurement can be taken from the centre of the room. So the
device needs to reach the centre of the room. Here the system uses a simple logic to reach the
centre of the room.

4
When placing the device at the entrance of the room the device can calculate
the forward and backward distances and from that it can reach the half-centre (here half-
centre means half-way between forward end and backward end.
Figure1.4. Movements of the device to reach the center
First the x and y (x—forward and y—backward) readings are taken. Then if x
is greater than y, d = [(x + y) / 2] – y. Otherwise, i.e; y > x, d = [(x + y)/2] – x. Now it can
move to half-centre as shown in figure1.4.II. Now it can calculate the second set of readings.
Same as in the first case, if u > v, d = [(u + v) / 2] – v else if v > u, d = [(u + v) / 2] – v. This
method is somewhat true for any shapes. Some examples are shown in figure1.5.
Figure1.5. Examples for centralization

5
CHAPTER 2
2.1. BLOCK DIAGRAM
Figure2.1. Block diagram of the device
Figure2.2. Block diagram representation of the server connection
Figure2.1 and 2.2 shows the block diagram of automated room area
measurement system. The device is built around PIC18f452—High-performance, Enhanced
Flash Microcontrollers with 10-Bit A/D. For movement of the device three wheels are used—
one caster wheel and two BO wheels. Caster wheel is Omni-directional wheel. The two BO
wheels are mounted on two stepper motors. The stepper motors are controlled by
microcontroller. Since the output current from microcontroller (25mA—sink or source) is not
enough to drive the stepper motor. So driver IC ULN2003 is used.

6
The distance sensor used is GP2Y0A21YK0F—from Sharp which is mounted
on another stepper motor with step-angle 1.8º. The output from the distance sensor is in
voltage form. It is fed to ADC input of the microcontroller. At a time five readings are taken
and calculate the average for accuracy. The corresponding digital value will be send to the
server. The communication between the device and the server is achieved by Zigbee module.
The power supply used is Nimh (Nickel–metal hydride) rechargeable batteries. The other pair
of Zigbee is connected to the server is driven through a MAX232 IC. The front end is
developed in Microsoft Visual Studio 2010 C#. It contains a login form. After login the front
end will be displayed. The dialog box contains start button and exit button. When start button
is clicked the operation will begin.
2.2. SENSOR--GP2Y0A21YK0F
GP2Y0A21YK0F is a distance measuring sensor unit, composed of an
integrated combination of PSD (position sensitive detector), IRED (infrared emitting diode)
and signal processing circuit. The variety of the reflectivity of the object, the environmental
temperature and the operating duration are not influenced easily to the distance detection
because of adopting the triangulation method. This device outputs the voltage corresponding
to the detection distance. So this sensor can also be used as a proximity sensor. Despite the
large difference between the reflectivity of the gray and white paper the sensor is still able to
output reliable readings. Note though that the reading at very close distances is the same as
very far distance. Here the sensor is mounted on the stepper motor and used for the
measurement of the distances.
Figure2.3. Timing chart of GP2Y0A21YK0F

7
Figure2.4. Block diagram of sensor
2.2.1. Features
1. Distance measuring range: 10 to 80 cm
2. Analog output type
3. Package size: 29.5×13×13.5 mm
4. Consumption current: Typ. 30mA
5. Supply voltage: 4.5 to 5.5 V
2.2.2. CHARACTERISTICS OF SENSOR
Figure2.5. V-D Characteristics

8
From the characteristics it can be see that the voltage output is inversely
proportional to the distance. The distace can be calculated by the following equation;
D (in cm) = 12343.85 × (ADC value)−1.15
ADC value is the corresponding converted value of the sensor output voltage.
2.3. PIC MICROCONTROLLER—18F452
Figure2.6. Pin out Diagram of 18F452
2.3.1. High Performance RISC CPU:
• C compiler optimized architecture/instruction set – Source code compatible with the PIC16
and PIC17 instruction sets
• Linear program memory addressing to 32 Kbytes
• Linear data memory addressing to 1.5 Kbytes
• Up to 10 MIPs operation:
DC - 40 MHz osc. / clock input
4MHz - 10MHz osc. / clock input with PLL active

9
• 16-bit wide instructions, 8-bit wide data path
• Priority levels for interrupts
• 8 x 8 Single Cycle Hardware Multiplier
Figure2.7. PIC 18FXXX Series features
2.3.2. Peripheral Features:
• High current sink / source 25mA / 25mA
• Three external interrupt pins
• Timer0 module: 8-bit / 16-bit timer / counter with 8-bit programmable prescaler
• Timer1 module: 16-bit timer / counter
• Timer2 module: 8-bit timer / counter with 8-bit period register (time-base for PWM)
• Timer3 module: 16-bit timer / counter
• Secondary oscillator clock option - Timer1 / Timer3
• Two Capture / Compare / PWM (CCP) modules. CCP pins that can be configured as:
Capture input: capture is 16-bit, max. resolution 6.25 ns (TCY / 16)
Compare is 16-bit, max. resolution 100 ns (TCY)
PWM output: PWM resolution is 1- to 10-bit, max. PWM freq.
@: 8-bit resolution = 156 kHz
10-bit resolution = 39 kHz
• Master Synchronous Serial Port (MSSP) module, Two modes of operation:
3-wire SPI™ (supports all 4 SPI modes)

10
I2C™ Master and Slave mode
• Addressable USART module:
Supports RS-485 and RS-232
• Parallel Slave Port (PSP) module
2.3.3. Analog Features:
• Compatible 10-bit Analog-to-Digital Converter module (A/D) with:
Fast sampling rate
Conversion available during SLEEP
Linearity ≤ 1 LSb
• Programmable Low Voltage Detection (PLVD)
Supports interrupt on-Low Voltage Detection
• Programmable Brown-out Reset (BOR)
2.3.4 Special Microcontroller Features:
• 100,000 erase/write cycle Enhanced FLASH program memory typical
• 1,000,000 erase/write cycle Data EEPROM memory
• FLASH/Data EEPROM Retention: > 40 years
• Self-reprogrammable under software control
• Power-on Reset (POR), Power-up Timer (PWRT) and Oscillator Start-up Timer (OST)
• Watchdog Timer (WDT) with its own On-Chip RCOscillator for reliable operation
• Programmable code protection
• Power saving SLEEP mode
• Selectable oscillator options including:
4X Phase Lock Loop (of primary oscillator)
Secondary Oscillator (32 kHz) clock input
• Single supply 5V In-Circuit Serial Programming™ (ICSP™) via two pins
• In-Circuit Debug (ICD) via two pins

11
2.3.5 CMOS Technology:
• Low power, high speed FLASH/EEPROM technology
• Fully static design
• Wide operating voltage range (2.0V to 5.5V)
• Industrial and Extended temperature ranges
• Low power consumption:
< 1.6 mA typical @ 5V, 4 MHz
25 μA typical @ 3V, 32 kHz
< 0.2 μA typical standby current
2.4. ZIGBEE MODULE
The XBee and XBee-PRO RF Modules were engineered to meet IEEE
802.15.4 standards and support the unique needs of low-cost, low-power wireless sensor
networks. The modules require minimal power and provide reliable delivery of data between
devices. The modules operate within the ISM 2.4 GHz (The Industrial, Scientific and Medical
(ISM) radio bands) frequency band and are pin-for-pin compatible with each other.
Figure2.8. Zigbee module and Pin out diagram
2.4.1. Key Features.
Long Range Data Integrity
XBee
• Indoor / Urban: up to 100’ (30 m)
• Outdoor line-of-sight: up to 300’ (90 m)

12
• Transmit Power: 1 mW (0 dBm)
• Receiver Sensitivity: -92 dBm
XBee-PRO
• Indoor/Urban: up to 300’ (90 m), 200' (60 m) for International variant
• Outdoor line-of-sight: up to 1 mile (1600 m), 2500' (750 m) for International variant
• Transmit Power: 63mW (18dBm), 10mW (10dBm) for International variant
• Receiver Sensitivity: -100 dBm
• RF Data Rate: 250,000 bps
Advanced Networking & Security
• Retries and Acknowledgements
• DSSS (Direct Sequence Spread Spectrum): each direct sequence channels has over 65,000
unique network addresses available
• Source / Destination Addressing
• Unicast & Broadcast Communications
• Point-to-point, point-to-multipoint and peer-to-peer topologies supported
Low Power
XBee
• TX Peak Current: 45 mA (@3.3 V)
• RX Current: 50 mA (@3.3 V)
• Power-down Current: < 10 μA
XBee-PRO
• TX Peak Current: 250mA (150mA for international variant)

13
• TX Peak Current (RPSMA module only): 340mA (180mA for international variant
• RX Current: 55 mA (@3.3 V)
• Power-down Current: < 10 Μa
ADC and I/O line support
• Analog-to-digital conversion, Digital I/OI/O Line Passing
Easy-to-Use
• No configuration necessary for out-of box RF communications
• Free X-CTU Software (Testing and configuration software) AT and API Command Modes
for configuring module parameters
• Extensive command set
• Small form factor
2.4.2. PIN DESCRIPTION
Figure2.9. Pin description of ZigBee

14
Minimum pin configuration is VCC, GND, DIN and DOUT
Figure2.10. Connection with microcontroller
Zigbee can be connected directly to the microcontroller. Rx to Data-out, Tx to Data-in and
common ground.
2.5. MAX232
The MAX232 is a dual driver/receiver that includes a capacitive voltage
generator to supply TIA/EIA-232-F voltage levels from a single 5-V supply. Each receiver
converts TIA/EIA-232-F inputs to 5-V TTL/CMOS levels. These receivers have a typical
threshold of 1.3 V, a typical hysteresis of 0.5 V, and can accept ±30V inputs. Each driver
converts TTL/CMOS input levels into TIA/EIA-232-F levels.
Figure2.11. Pin out of MAX232
Meets or Exceeds TIA/EIA-232-F and ITU Recommendation V.28
Operates From a Single 5-V Power Supply with 1.0-_F Charge-Pump Capacitors
Operates Up To 120 Kbit/s
Two Drivers and Two Receivers
±30V Input Levels
Low Supply Current: 8mA Typical

15
ESD Protection Exceeds JESD 22
- 2000-V Human-Body Model (A114-A)
Upgrade With Improved ESD (15-kV HBM) and 0.1-_F Charge-Pump Capacitors is
Available With the MAX202
Applications: TIA/EIA-232-F, Battery-Powered Systems, Terminals, Modems and
Computers
2.6. RS232
In telecommunications, RS-232 is the traditional name for a series of standards
for serial binary single-ended data and control signals connecting between a DTE (Data
Terminal Equipment) and a DCE (Data Circuit-terminating Equipment). It is commonly used
in computer serial ports. The standard defines the electrical characteristics and timing of
signals, the meaning of signals, and the physical size and pin out of connectors. The current
version of the standard is TIA-232-F Interface between Data Terminal Equipment and Data
Circuit-Terminating Equipment Employing Serial Binary Data Interchange, issued in 1997.
Figure2.12. RS232 pin out
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
plus or minus 3 to 15 volts; the ±3 V range near zero volts is not a valid RS-232 level. The
standard specifies a maximum open-circuit voltage of 25 volts: signal levels of ±5 V, ±10 V,
±12 V, and ±15 V are all commonly seen depending on the power supplies available within a
device. RS-232 drivers and receivers must be able to withstand indefinite short circuit to
ground or to any voltage level up to ±25 volts. The slew rate, or how fast the signal changes
between levels, is also controlled.

16
2.7. ULN2003
The ULN2003 is a monolithic high voltage and high current Darlington
transistor arrays. It consists of seven NPN Darlington pairs that feature high-voltage outputs
with common-cathode clamp diode for switching inductive loads. The collector-current rating
of a single Darlington pair is 500mA.
Figure2.12. Logic Diagram of ULN2003
The Darlington pairs may be paralleled for higher current capability.
Applications include relay drivers, hammer drivers, lamp drivers, display drivers (LED gas
discharge), line drivers, and logic buffers. The ULN2003 has a 2.7kΩ series base resistor for
each Darlington pair for operation directly with TTL or 5V CMOS devices
2.8. STEPPER MOTORS AND WHEELS
Stepper motors used here are;
1. STH–39D stepper motor (1nos)—1.8º step angle
2. PMS–35S stepper motor (2nos)—7.5º step angle
Figure2.14. PM–35S-048 Figure2.15. STH–39D-112

17
The stepper motor is controlled by the microcontroller. The sensor stepper
motor is controlled by output sequence from Port B and the two wheels are controlled by
PortD.
Figure2.16. Diagrammatic representation of 6-lead unipolar stepper motor and its sequence.
Figure2.17. Caster wheel & BO wheel
The caster wheel and BO wheel used are shown in the figure2.17. The
platform used for the system is shown in figure2.18. The PCB board is mounted beneath the
platform.
Figure2.18. The platform

18
CHAPTER 3
3.1. CIRCUIT DIAGRAM
Figure3.1. Circuit Diagram of the device
Figure3.1. shows the circuit diagram of the proposed system which is simulated in Proteus.
3.2. PCB LAYOUT
Figure3.2. Figure3.3
Figure3.2. shows the main board of the system and Figure3.3. Shows the Zigbee board.

19
3.3. SOFTWARES USED
3.3.1. MPLAB IDE V8.80:
MPLAB Integrated Development Environment (IDE) is a free, integrated
toolset for the development of embedded applications employing Microchip's PIC® and
dsPIC® microcontrollers. MPLAB IDE runs as a 32-bit application on MS Windows
®, is easy
to use and includes a host of free software components for fast application development and
super-charged debugging. MPLAB IDE also serves as a single, unified graphical user
interface for additional Microchip and third party software and hardware development tools.
Moving between tools is a snap, and upgrading from the free software simulator to hardware
debug and programming tools is done in a flash because MPLAB IDE has the same user
interface for all tools. The entire code is written in MPLAB IDE V8.80 and burn the hex file
into the PIC18f452.
3.3.2. ISIS PROTEUS V7.60:
At the heart of Proteus VSM is ProSPICE. This is an established product that
combines uses a SPICE3f5 analogue simulator kernel with a fast event-driven digital
simulator to provide seamless mixed-mode simulation. The use of a SPICE kernel let us
utilize any of the numerous manufacturer-supplied SPICE models now available and around
6000 of these are included with the package. Proteus VSM includes a number of virtual
instruments including an Oscilloscope, Logic Analyzer, Function Generator, Pattern
Generator, Counter Timer and Virtual Terminal as well as simple voltmeters and ammeters.
In addition, it is provided with dedicated Master/Slave/Monitor mode
protocol analyzers for SPI and I2C - simply wire them onto the serial lines and monitor or
interact with the data live during simulation.
3.3.3. ISIS ARES 7.60:
Proteus PCB design combines the ISIS schematic capture and ARES PCB
layout programs to provide a powerful, integrated and easy to use suite of tools for
professional PCB Design. All Proteus PCB design products include an integrated shape based
auto-router and a basic SPICE simulation capability as standard. More advanced routing
modes are included in Proteus PCB Design Level 2 and higher whilst simulation capabilities
can be enhanced by purchasing the Advanced Simulation option and/or micro-controller
simulation capabilities.

20
3.3.4. MICROSOFT VISUAL STUDIO 2010
Microsoft Visual Studio is a powerful IDE that ensures quality code
throughout the entire application lifecycle, from design to deployment. For SharePoint, the
web, Windows, Windows Phone, and beyond, Visual Studio is the ultimate all-in-one
solution developing applications.
Visual C# 2010 Express is part of the Visual Studio 2010 Express family, a
free set of tools that Windows developers at any level can use to create custom applications
using basic and expert settings. Visual C# is designed for building a variety of applications
that run on the .NET Framework. Visual C# is simple, powerful, type-safe, and object-
oriented. With its many innovations, Visual C# enables rapid application development and
also retains the expressiveness and elegance of C-style languages.
The front end and the code for the server are developed in Visual C# 2010.

21
CHAPTER 4
4.1. ALGORITHM
4.1.1. Algorithm for the PIC
1. start
2. initialize ports, configure timers & ADC
3. wait for the ―INIT‖ signal from the server
4. read the initial value of the sensor output & send it serially
5. feed the sequences to the sens_stepper for 180 degree
6. read the 2nd
value of the sensor output & send it serially
7. wait for FXXX or RXXX signal from the server
8. if FXXX feed the forward sequences to the stepper_lwl & stepper_rwl
9. if RXXX feed the reverse sequences to the stepper_lwl & stepper_rwl
10. read the 3rd
value of the sensor output & send it serially
11. feed the sequences to the sens_stepper for 180 degree
12. read the 4th value of the sensor output & send it serially
13. if the 3rd
& 4th values are different turn left or right.
14. wait for FXXX or RXXX signal from the server
15. if FXXX feed the forward sequences to the stepper_lwl & stepper_rwl
16. if RXXX feed the reverse sequences to the stepper_lwl & stepper_rwl
17. from the approximate centre read the sensor values for each 1.8 degree & send
serially
18. after completing 200 steps rotate the sens_stepper in the opposite direction
19. stop

22
4.1.2. Algorithm for the server
1. start
2. send ―INIT‖ to the device
3. wait for the 1st reading
4. using the equation convert it to centimeters
5. store it in x
6. wait for the 2nd
reading
7. using the equation convert it to centimeters
8. store it in y
9. if a>b send F+ ((x+y)/2)-y
10. else send R+ ((x+y)/2)-x
11. wait for the 3rd
reading
12. using the equation convert it to centimeters
13. store it in u
14. wait for the 4th reading
15. using the equation convert it to centimeters
16. store it in v
17. if a>b send ―F‖ + ((u+v)/2)-v
18. else send R+ ((u+v)/2)-u
19. then read the 200 readings from the centre
20. using Cosine rule & Heron’s formula calculate each area
21. integrate all the areas to get the total area
22. display the total area
23. stop

23
CHAPTER 5
5.1. PROGRAM CODE FOR PIC 18F452
#include <htc.h>
#define _XTAL_FREQ 12000000
#include <string.h>
void adc_fn(void);
void send_serial(void);
void stepper_forward(int);
void stepper_reverse(int);
void stepper_clkw(int);
void stepper_cclkw(int);
void movtoright(void);
void movtoleft(void);
int s=0,cnt=0,i,avg=0,result=0,timer1_count=0;
unsigned char staring_count=0;
char v[5],buf[20];
bit flag=0,reached_halfcentre=0,readytohalfreading=0;
bit timer_flag=0,readings_begin=0;
bit start_flag=0,startbit=0,readytomove=0,rotation_bit=0;
int count=0,end=0,ct=0,cp=0,rflg=0;
int step=0,adc_read[3],start=2;
void my_delay(unsigned int del)
{
while(--del)
{ __delay_ms(10);}
}
void interrupt dis()
{
if(TMR1IF)
{
TMR1IF=0;
timer1_count++;

24
if(timer1_count==2)
{
timer1_count=0;
timer_flag=1;
count+=1;
}
if(count==5)
count=1;
}
if(TMR0IF)
{
TMR0IF=0;
adc_fn();
s=s+result;
cnt++;
if(cnt==5)
{
TMR0ON=0;
avg=s/5;
flag=1;
cnt=0;
if(startbit||readytohalfreading)
{
staring_count++; }
if(staring_count==3)
{
startbit=0;
staring_count=0;
readytohalfreading=0;
}
}
}
if(RCIF)

25
{
RCIF=0;
buf[ct]=RCREG;
if(buf[ct-1]==0x0D &&buf[ct]==0x0A)
{
start_flag=1;
buf[4]='\0';
ct=0;
}
ct++;
} }
void main()
{
GIE=1;
PEIE=1;
TMR0IE=1;
T0CON=0b00001000;
//for ADC
ADCON0=0x00;
ADCON1=0b10000000;
//for UART
SPEN=1;
TRISC6=0;
SYNC=0;
BRGH=0;
SPBRG=19;
TXEN=1;
TRISA0=1;
TRISA1=1;
RCIE=1;
CREN=1;
TRISC7=1;
TMR1IE=1;
T1CON=0B10110000;

26
TRISB=0x00;
PORTB=0X00;
TRISD=0X00;
PORTD=0X00;
while(1)
{
if(start_flag)
{ ct=0;
start_flag=0;
start=strcmp("INIT",buf);
if(start==0)
{
start=2;
startbit=1;
TMR0ON=1;
}
else if(buf[0]=='F')
{
step=(((buf[1]-0x30)*100)+((buf[2]-0x30)*10)+((buf[3]-0x30)));
stepper_forward(step);
if(readytomove==0)
reached_halfcentre=1;
else
{
while(!TRMT);
TXREG='I';
readings_begin=1;
TMR1ON=1;
}
}
else if(buf[0]=='R')
{
step=(((buf[1]-0x30)*100)+((buf[2]-0x30)*10)+((buf[3]-0x30)));
stepper_reverse(step);

27
if(readytomove==0)
reached_halfcentre=1;
else
{
while(!TRMT);
TXREG='I';
readings_begin=1;
TMR1ON=1;
}}}
if(startbit&& flag)
{
flag=0;
send_serial();
my_delay(100);
if(staring_count==1)
stepper_clkw(25);
my_delay(20);
TMR0ON=1;
}
if(reached_halfcentre)
{
reached_halfcentre=0;
stepper_cclkw(13);
my_delay(10);
TMR0ON=1;
Readytohalfreading=1;
flag=0;
}
if(readytohalfreading==1 && flag==1)
{
flag=0;
cp++;
adc_read[cp]=avg;

28
send_serial();
if(staring_count==1)
stepper_clkw(25);
if(staring_count==2)
TMR0ON=0;
else
TMR0ON=1;
if(cp==2)
rflg=1;
}
if(rflg)
{
rflg=0;
if(adc_read[2]<adc_read[1])
{
movtoright();
readytomove=1;
}
else if(adc_read[2]>adc_read[1])
{
movtoleft();
readytomove=1;
}
else
readytomove=1;
}
if(timer_flag) // 200 readings start
{
end++;
timer_flag=0;
switch(count)
{
case 1:PORTB=0X08;
my_delay(5);

29
TMR0ON=1;
break;
case 2:PORTB=0X04;
my_delay(5);
TMR0ON=1;
break;
case 3:PORTB=0X02;
my_delay(5);
TMR0ON=1;
break;
case 4:PORTB=0X01;
my_delay(5);
TMR0ON=1;
break;
}
PORTB=0X00;
if(end==201)
{
TMR0ON=0;
TMR1ON=0;
stepper_cclkw(63);
readytomove=0;
}
}
if(flag &&readings_begin)
{
flag=0;
send_serial();
}
}
}
void adc_fn(void)
{
int a=0,b=0;

30
result=0;
ADCON0=0B10000001;
GODONE=1;
while(GODONE);
ADON=0;
a=ADRESH;
a=a<<8;
b=ADRESL;
result=a|b;
}
void movtoright()
{
int ifr=0,j=0;
while(ifr<24)
{
switch(j)
{
case 1:PORTD=0X60;
my_delay(5);
break;
case 2:PORTD=0X30;
my_delay(5);
break;
case 3:PORTD=0X90;
my_delay(5);
break;
case 4:PORTD=0XC0;
my_delay(5);
break;
}
ifr++;
j++;
if(j>4)
j=1;

31
}
PORTD=0x00;
my_delay(10);
}
void movtoleft()
{
intifr=0,j=0;
while(ifr<24)
{
switch(j)
{
case 1:PORTD=0X06;
my_delay(5);
break;
case 2:PORTD=0X03;
my_delay(5);
break;
case 3:PORTD=0X09;
my_delay(5);
break;
case 4:PORTD=0X0C;
my_delay(5);
break;
}
ifr++;
j++;
if(j>4)
j=1;
}
PORTD=0x00;
my_delay(10);
}
void stepper_cclkw(intsn)
{

32
TMR0ON=0;
TMR1ON=0;
for(i=0;i<sn;i++)
{
PORTB=0X01;
my_delay(5);
PORTB=0X02;
my_delay(5);
PORTB=0X04;
my_delay(5);
PORTB=0X08;
my_delay(5);
}
}
void stepper_clkw(intsn)
{
for(i=0;i<sn;i++)
{
PORTB=0X08;
my_delay(5);
PORTB=0X04;
my_delay(5);
PORTB=0X02;
my_delay(5);
PORTB=0X01;
my_delay(5);
}
}
void stepper_forward(intstp)
{
int ifr=0,j=0;
while(ifr<stp)
{
switch(j)

33
{
case 1:PORTD=0X66;
my_delay(5);
break;
case 2:PORTD=0X33;
my_delay(5);
break;
case 3:PORTD=0X99;
my_delay(5);
break;
case 4:PORTD=0XCC;
my_delay(5);
break;
}
ifr++;
j++;
if(j>4)
j=1;
}
PORTD=0x00;
my_delay(10);
}
void stepper_reverse(intstp)
{
intirv=0,j=0;
while(irv<stp)
{
switch(j)
{
case 1:PORTD=0XCC;
my_delay(5);
break;
case 2:PORTD=0X99;
my_delay(5);

34
break;
case 3:PORTD=0X33;
my_delay(5);
break;
case 4:PORTD=0X66;
my_delay(5);
break;
}
irv++;
j++;
if(j>4)
j=1;
}
PORTD=0x00;
my_delay(10);
}
void send_serial(void)
{
while(!TRMT);
TXREG='S';
flag=0;
TMR0ON=0;
//serial port pgm
v[0]=(avg/100)+0x30;
v[1]=((avg/10)%10)+0x30;
v[2]=((avg/10)%10)+0x30;
v[2]=(avg%10)+0x30;
for(i=0;i<=3;i++)
{
while(!TRMT);
TXREG=v[i];
}
avg=0;s=0; result=0;
}

35
5.2. PROGRAM CODE FOR THE SERVER
5.2.1. LoginForm.cs
Figure5.1. login form
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class LoginForm : Form
{
public LoginForm()
{
InitializeComponent();
}

36
private void simpleButton1_Click(object sender, EventArgs e)
{
if (textEdit1.Text == "admin" && textEdit2.Text == "123")
{
pictureEdit1.Image = WindowsFormsApplication1.Properties.Resources.open_padlock_md;
Form1 obj = new Form1();
obj.Show();
}
else
{
DevExpress.XtraEditors.XtraMessageBox.Show("Wrong UserName Or Password", "Error
Message...", MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
// MessageBox.Show("Wrong UserName Or Password", "Error Message...",
MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
}
}
private void textEdit1_EditValueChanged(object sender, EventArgs e)
{
pictureEdit1.Image =
WindowsFormsApplication1.Properties.Resources._11949848541326072700padlock_aj_asht
on_01_svg_med;
}
private void textEdit2_EditValueChanged(object sender, EventArgs e)

37
{
pictureEdit1.Image =
WindowsFormsApplication1.Properties.Resources._11949848541326072700padlock_aj_asht
on_01_svg_med;
}
}
}
5.2.2. Form1.cs
Figure5.2. Front panel
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO.Ports;

38
using System.Threading;
using DevExpress.XtraGauges.Win;
using DevExpress.XtraGauges.Win.Gauges.Linear;
using DevExpress.XtraGauges.Core.Model;
using DevExpress.XtraGauges.Core.Base;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
double[] a = new double[200];
double[] b = new double[200];
string[] ss = new string[200];
int i=0;
double d1 = 0; // Initialization
double d2 = 0;
double d = 0;
double s = 0;
string status = "";
double area = 0.00;
double num1 = 0;
double num2 = 0;
double num3 = 0;
double num4 = 0;
double num = 0;
int ar;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
if (ZigB.IsOpen == false)
{
ZigB.Open();

39
}
}
private void ZigB_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
string str = "";
str = ZigB.ReadExisting();
switch (status)
{
case "Initialize":
if (num1 == 0)
{
str = str.Substring(1, 3);
num1 = Convert.ToDouble(str);
num1 = (Math.Pow(num1, -1.15)) * 12343.85;
if (num1 > 15)
num1 = num1 / 1.4;
}
else
{
str = str.Substring(1, 3);
num2 = Convert.ToDouble(str);
num2 = (Math.Pow(num2, -1.15)) * 12343.85;
if (num2 > 15)
num2 = num2 / 1.4;
if (num1 > num2)
{
num=((num1 + num2) / 2) - num2;
num = num / .6541;
num = Math.Round(num);
if (num > 9)
ZigB.Write("F0" + num.ToString() + "\x0D" + "\x0A");
else
ZigB.Write("F00" + num.ToString() + "\x0D" + "\x0A");
}

40
else
{
num = ((num1 + num2) / 2) - num1;
num = num / .6541;
num = Math.Round(num);
if (num > 9)
ZigB.Write("R0" + num.ToString() + "\x0D" + "\x0A");
else
ZigB.Write("F00" + num.ToString() + "\x0D" + "\x0A");
}
status = "WaitingForSecondLocatios";
}
break;
case "WaitingForSecondLocatios":
if (num3 == 0)
{
str = str.Substring(1, 3);
num3 = Convert.ToDouble(str);
num3 = num3 / 2.0;
if (num3 > 15)
num3 = num3 / 1.4;
num3 = (Math.Pow(num3, -1.15)) * 12343.85;
}
else
{
str = str.Substring(1, 3);
num4 = Convert.ToDouble(str);
num4 = (Math.Pow(num4, -1.15)) * 12343.85;
if (num4 > 15)
num4 = num4 / 1.4;
if (num3 > num4)
{
num = ((num3 + num4) / 2) - num4;
num = num / 0.4906;

41
num = Math.Round(num);
if (num > 9)
ZigB.Write("F0" + num.ToString() + "\x0D" + "\x0A");
else
ZigB.Write("F00" + num.ToString() + "\x0D" + "\x0A");
}
else
{
num = ((num3 + num4) / 2) - num3;
num = num / 0.4906;
num = Math.Round(num);
if (num > 9)
ZigB.Write("R0" + num.ToString() + "\x0D" + "\x0A");
else
ZigB.Write("F00" + num.ToString() + "\x0D" + "\x0A");
}
status = "WaitingForData";
}
break;
case "WaitingForData":
if (str == "I")
{
return;
}
else
{
str = str.Substring(1, 3);
if (richTextBox1.InvokeRequired)
{
AddTextToTextBox(str+"\n");
}
double ip = Convert.ToDouble(str);
if ((d1 == 0) && (d2 == 0))
{

42
d1 = (Math.Pow(ip, -1.15)) * 12343.85;
if (d1 > 15)
d1 = d1 / 1.4;
}
else if ((d1 != 0) && (d2 == 0))
{
d2 = (Math.Pow(ip, -1.15)) * 12343.85;
if (d2 > 15)
d2 = d2 / 1.4;
}
else
{
d1 = d2;
d2 = (Math.Pow(ip, -1.15)) * 12343.85;
if (d2 > 15)
d2 = d2 / 1.4;
}
double temp = (Math.Pow(d1, 2) + Math.Pow(d2, 2)) - (2 * d1 * d2 * 0.9995065604);
d = Math.Sqrt(temp);
s = (d + d1 + d2) / 2;
a[i] = Math.Sqrt(s * (s - d1) * (s - d2) * (s - d));
i++;
double m = i;
arcScaleComponent1.Value =Convert.ToInt16(m);
{
LinearScaleComponent scale = linearGauge2.Scales[0];
scale.MinValue = 0;
scale.MaxValue = 100;
m = m / 2;
scale.Value = Convert.ToInt16(m);
}
area = area + a[i-1];
ar = Convert.ToInt16(area);
digitalGauge1.Text = ar.ToString();

43
if (i == 200)
{
temp = 0;
for (int j = 0; j < 200; j++)
{
temp = temp + a[j];
}
MessageBox.Show(temp.ToString());
}
}
break;
}
}
public delegate void AddnewTextDelegate(string str);
public void AddTextToTextBox(string str)
{
if (this.richTextBox1.InvokeRequired)
{
this.Invoke(new AddnewTextDelegate(AddTextToTextBox), str);
}
else
{
this.richTextBox1.Text=this.richTextBox1.Text + str ;
}
}
private void simpleButton1_Click(object sender, EventArgs e)
{
status="Initialize";
ZigB.Write("INIT"+"\x0D"+"\x0A");
}
private void simpleButton3_Click(object sender, EventArgs e)
{
this.Close();
}

44
private void labelControl1_Click(object sender, EventArgs e)
{
}
private void labelControl2_Click(object sender, EventArgs e)
{
}
}
}

45
CHAPTER 6
6.1. FUTURE MODIFICATIONS
The sensor can be replaced to achieve more range. The sensor with measuring range
of 20 – 150cm is available in the market
The sensor can be replaced by a laser range finder or a scanning laser range finder
Much more complex algorithm can be utilized to measure the real rooms with
obstacles
3D mapping can be achieved through powerful algorithm
The same device can be equipped with wireless camera module to obtain a live vision

46
6.2. CONCLUSION
Here developed a demo for the room area measurement system. Wireless
operation is achieved through Zigbee module. The development of automated systems
reduces the human efforts. The 3D mapping and 2D mapping are helpful in navigation and
position estimation of robots.

47
REFERENCES
1. EMBEDDED DESIGN WITH THE PIC 18F452 MICROCONTROLLER.
AUTHORS: JOHN PEATMAN
PRENTICE HALL, 2003
ISBN: 0-13-046213-6
2. PROGRAMMING AND CUSTOMIZING THE PIC MICROCONTROLLER BY
MYKE PRODKO.