<Please Enter Name>
<Please Enter University>
A light tracking system was created to search for the brightest spot in the room and display its location from a reference point on a liquid crystal display (LCD). The system comprised a microcontroller, servo motor, two phototransistors, a universal asynchronous receiver/transmitter (UART), an LM358 operational amplifier, battery and battery holder, LCD, and associated wiring.
Methods
The microcontroller was programmed to direct the servo motor to search the room within 180 degrees, and to continue in search mode, until the brightest light was detected by the phototransistors within two feet of the system. Once the brightest light was detected, its angle from a programmed reference point was to be displayed on the LCD screen. The code for the microcontroller is shown in Appendix A. The following ports of the LCD were used for the system components:
Port 1, Pin 5 for the first phototransistor;
Port 1, Pin 6 for the second phototransistor;
Port 1, Pin 2 for the servo motor; and
Port 3, Pin 1 for the UART.
Results
The use of several resistance values for the LM358 was required in order for the phototransistors to detect light within two feet of the system. In addition, in order to achieve a smooth rotation in the servo motor, experimentation with the delay function in the code was required. Nevertheless, although the microcontroller was programmed and the system appeared to have been assembled correctly, the system did not operate as planned.
Conclusion
It is hypothesized that perhaps the natural light in the room did not vary enough to be distinguishable by the phototransistors at a distance of two feet away from the system, thus not producing the desired response. Alternatively, perhaps the rate of movement of the servo motor was not smooth enough to detect a difference in light at a distance of two feet. Continued modification of the delay function in the code is recommended to test this hypothesis, and/or continued experimentation with the resistance values for the LM358 is also recommended.
Appendix A
#include<at89c51cc03.h>
#include<stdio.h>
//initializing the libraries
//for angle 90 rotation 7050
void moveC()
{
CCAP0L=Record%256;
CCAP0H=Record/256;
CR=1;
}
//for angle 0 rotation 2350
void moveL()
{
CCAP0L=Record%256;
CCAP0H=Record/256;
CR=1;
}
//for angle 180 rotation 11750
void moveR()
{
CCAP0L=Record%256;
CCAP0H=Record/256;
CR=1;
}
//for turning of CR,servo stops moving
void stopS()
{
CCAP0L=Record%256;
CCAP0H=Record/256;
CR=0;
}
//to display on LCD
void To_lcd(char msg[])
int c;
unsigned char i;
CKCON=0x01;
SCON=0X40;
RCLK=1;
TCLK=1;
RCAP2H=0XFE;
RCAP2L=0x91;
TR2=1;
REN=0;
RI=0;
i=0;
while(msg[i] !=0)
{
TI=0;
SBUF=msg[i];
i++;
while(TI==0);
}
for(c=0;c<28500;c++);
}
//P1_1 for servo input
void toggle(void) interrupt 6 using 1
{
if(CF)
{
IEN0=0x00;
P1_1=1;
CF=0;
IEN0=0xC0;
}
if(CFF0)
{
IEN0=0x00;
P1_1=0;
CCF0=0;
IEN0=0xC0;
}
}
//function for longer delay to start and wait for LCD
void LD(unsigned char h)
{
int b;
unsigned char g;
for(g=0;g<h;g++)
for(b=0;b<5000;b++)
return;
}
//function for delay
void D(unsigned char msec)
{
int i,j;
for(i=0;i<msec;i++)
for(j=0;j<1275;j++)
}
//function calling move right, left and center. stopS denotes stop servo, Record is a flag used here like Count, Angle to measure the rotation degrees
void moveR();//180
void moveC();//90
void moveL();//0 angle
void stopS();//stop servo, at p1.1
int Record;
void LD(unsigned char);
void D(unsigned char);
void To_lcd(char msg[]);//lcd at p3.1
int angle;
char string1[20];
void main(void)
{
CKCON=0x01;
CMOD=0x01;
CCAPM0=0x49;
IEN0=0xC0;//interrupt enable
Record=7050;
angle=90;
moveC();
LD(1000000);
while(1)
{
unsigned int R;
unsigned int L;
if(P1_5==0 && P1_6==0)
{
R=1;
L=0;
while(Record <= 11750 && R==1 && P1_5==0 && P1_6==0 )
{
Record= Record+208;
angle=angle+4;
D(75);
moveR();
}
R=0;
L=1;
while(Record >= 2350 && L==1 && P1_5==0 && P1_6==0 )
{
Record= Record-208;
angle=angle-4;
D(75);
moveL();
}
L=0;
R=1;
}
while(P1_5==1 && P1_6==1)
{
stopS();
sprintf(string1,"Angle=%d\n ",angle);
To_lcd(string1);
D(100);
}
moveL();
if(P1_5==1 && P1_6==0)
{
Record=Record-208;
angle=angle-4;
if(angle<0)
{
angle=0;
}
D(75);
if(Record>=2350)
{
moveL();
}
}
if(P1_5==0 && P1_6==1)
{
Record=Record+208;
angle=angle+4;
if(angle>180)
{
angle=180;
}
D(75);
if(Record<=11750)
moveR;
}
}
}