You are on page 1of 34

PROJECT REPORT ....

EMBEDDED LAB SECURITY CAMERA

Security Camera Control Using Servo Motor


SUBMITTED BY: SYED MUHAMMAD ARSLAN GILANI L1F10BSEE0134 HAFIZ HAMZA RAHMAN L1F10BSEE0140 SECTION: EC2 SUBMISSION DATE: 22-06-2013

SUBMITTED TO: PROF JALIL ASGHAR MIRZA

COMPONENTS:
The components used in this project are i) Arduino ii) LCD iii) Keypad iv) Servo Motors v) Camera vi) Mechanical Rotational Structure vii) Connector Strip for LCD viii) Vero board ix) Connection wires x) Spacers

DESIGN:

DESCRIPTION:
There are two servo motor used to control the Azimuthal angle and Elevation angle of the security camera by using the keypad as input. There are two moods of operation 1) Automatic 2) Manual

Automatic:
In that mode the user once given the rotational delay between every degree and the degree of rotation then the camera start its rotation till user stop it by itself.

Manual:
In that mode the user give the required delay, azimuthal and elevation angle to rotate the camera at a specific point

CODE:
#include <Servo.h> #include <LiquidCrystal.h> #include <Keypad.h> Servo allivation; // create servo object to control a servo Servo rotation; int pos1=0; int pos2=0; int pos3=0; int pos4=0; char d=248; intdd,i; // variable to store the servo position // variable to store the servo position //variable to stor the previous value of pos1 //variable to stor the previous value of pos2 // to show the degree sign // use for user define delay i for loop

const byte ROWS = 4; //four rows const byte COLS = 3; //three columns char keys[ROWS][COLS] = { {'1','2','3'}, {'4','5','6'}, {'7','8','9'}, {'*','0','#'}};

byterowPins[ROWS] = {8, 7, 6, 5}; //connect to the row pinouts of the keypad bytecolPins[COLS] = {4, 3, 2}; pinouts of the keypad //connect to the column

Keypad kpd = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS ); /* The LCD circuit: * LCD RS pin to digital pin 12 * LCD Enable pin to digital pin 11 * LCD D4 pin to digital pin A3 * LCD D5 pin to digital pin A2 * LCD D6 pin to digital pin A1 * LCD D7 pin to digital pin A0 * LCD R/W pin to ground * 10K resistor: * ends to +5V and ground */ LiquidCrystallcd(12, 11, A3, A2, A1, A0); void setup(){ Serial.begin(9600);

pinMode(A0, OUTPUT); pinMode(A1, OUTPUT); pinMode(A2, OUTPUT); pinMode(A3, OUTPUT); lcd.begin(16,2); // initialize the library with the numbers of the interface pins kpd.setDebounceTime(10); rotation.attach(9); // attaches the servo on pin 9 to the servo object rotation.write(0); allivation.attach(10); allivation.write(0); } void loop(){ Reset: Serial.println(); char key; int k,k1,k2=0; int x=0; int y=0; int z=0;

lcd.clear(); // For Automatic or manual operation Serial.println("Press '1' for automatic control"); Serial.println("Press '2' for Manual control"); Serial.println("Press '*' for Operate Manualy at any time"); Serial.println("Press '#' for Reset at any time"); lcd.clear(); lcd.print("1) Automatic"); lcd.setCursor(0,1); lcd.print("2) Manual"); key=kpd.waitForKey(); if (key != NO_KEY) { lcd.print(key); } if(key=='*') { goto Manual; } else if(key=='#')

{ goto Reset; } else if(key=='1') { goto Automatic; } else if(key=='2') { goto Manual; } else { Serial.println(); Serial.println("You enterd an invalid no."); lcd.clear(); lcd.print("Invalid Value delay(200); goto Reset; } ");

// Function to mov the motor at specific degrees continusly Automatic: { intpos; int rot; lcd.clear(); Serial.println(); Serial.println("Enter the delay between the rotation in every degree of the motor"); lcd.print("Enter delay key=kpd.waitForKey(); if (key != NO_KEY) { lcd.print(key); } if(key=='*') { goto Manual; } else if(key=='#') { ");

goto Reset; } x= key-48; Serial.print(key); lcd.setCursor(8,1); lcd.print(key); // key= kpd.getKey(); key=kpd.waitForKey(); if (key != NO_KEY) { lcd.print(key); } if(key=='*') { goto Manual; } else if(key=='#') { goto Reset; } y=key-48;

k1=x*10; k2=y; k=k1+k2; Serial.print(key); lcd.setCursor(9,1); lcd.print(key); //key= kpd.getKey(); key=kpd.waitForKey(); if (key != NO_KEY) { lcd.print(key); } if(key=='*') { goto Manual; } else if(key=='#') { goto Reset; } z=key-48;

x=x*100; y=y*10; z=z; dd=x+y+z; Serial.print(key); lcd.setCursor(10,1); lcd.print(key); delay(200); lcd.clear(); Serial.println(); again: Serial.println("Enter 3 digit degree 0 t0 180"); lcd.clear(); lcd.print("Enter degree key=kpd.waitForKey(); if (key != NO_KEY) { lcd.print(key); } if(key=='*') { ");

goto Manual; } else if(key=='#') { goto Reset; } x= key-48; Serial.print(key); lcd.setCursor(8,1); lcd.print(key); // key= kpd.getKey(); key=kpd.waitForKey(); if (key != NO_KEY) { lcd.print(key); } if(key=='*') { goto Manual; } else if(key=='#')

{ goto Reset; } y=key-48; k1=x*10; k2=y; k=k1+k2; Serial.print(key); lcd.setCursor(9,1); lcd.print(key); //key= kpd.getKey(); key=kpd.waitForKey(); if (key != NO_KEY) { lcd.print(key); } if(key=='*') { goto Manual; } else if(key=='#')

{ goto Reset; } z=key-48; x=x*100; y=y*10; z=z; rot=x+y+z; if(rot>180) { Serial.println(key); Serial.println("You enterd invalid degree"); lcd.clear(); lcd.print("Invalid value"); delay(200); goto again; } Serial.print(key); lcd.setCursor(10,1); lcd.print(key); delay(100);

loc: for(pos = 0; pos< rot; pos += 1) // goes from 0 degrees to given degrees { // in steps of 1 degree // tell servo to go to position in rotation.write(pos); variable 'rot' key=kpd.getKey(); if(key=='*') { goto Manual; } else if(key=='#') { goto Reset; } delay(dd); the position } for(pos = rot; pos>=1; pos-=1) to 0 degrees { // goes from given degrees // waits 15ms for the servo to reach

rotation.write(pos); variable 'rot' key=kpd.getKey(); if(key=='*') { goto Manual; } else if(key=='#') { goto Reset; } delay(dd); reach the position } gotoloc; }

// tell servo to go to position in

// waits 15ms for the servo to

// Function to get the delay from the user Manual: { lcd.clear(); Serial.println();

Serial.println("Enter the delay between the rotation in every degree of the motor"); lcd.print("Enter delay key=kpd.waitForKey(); if (key != NO_KEY) { lcd.print(key); } if(key=='*') { goto Manual; } else if(key=='#') { goto Reset; } x= key-48; Serial.print(key); lcd.setCursor(8,1); lcd.print(key); // key= kpd.getKey(); ");

key=kpd.waitForKey(); if (key != NO_KEY) { lcd.print(key); } if(key=='*') { goto Manual; } else if(key=='#') { goto Reset; } y=key-48; k1=x*10; k2=y; k=k1+k2; Serial.print(key); lcd.setCursor(9,1); lcd.print(key); //key= kpd.getKey();

key=kpd.waitForKey(); if (key != NO_KEY) { lcd.print(key); } if(key=='*') { goto Manual; } else if(key=='#') { goto Reset; } z=key-48; x=x*100; y=y*10; z=z; dd=x+y+z; Serial.print(key); lcd.setCursor(10,1); lcd.print(key);

delay(200); // Azimuthal Angle of the Security Camera start1: Serial.println(); Serial.println("Enter 3 digit degree 0 to 180"); lcd.clear(); Serial.println(); Serial.println("Azimuthal angle "); lcd.print("Az "); // key=kpd.getKey(); key=kpd.waitForKey(); if (key != NO_KEY) { lcd.print(key); } if(key=='*') { goto Manual; } else if(key=='#')

{ goto Reset; } x= key-48; Serial.print(key); lcd.setCursor(8,0); lcd.print(key); // key= kpd.getKey(); key=kpd.waitForKey(); if (key != NO_KEY) { lcd.print(key); } if(key=='*') { goto Manual; } else if(key=='#') { goto Reset; }

y=key-48; k1=x*10; k2=y; k=k1+k2; Serial.print(key); lcd.setCursor(9,0); lcd.print(key); //key= kpd.getKey(); key=kpd.waitForKey(); if (key != NO_KEY) { lcd.print(key); } if(key=='*') { goto Manual; } else if(key=='#') { goto Reset; }

z=key-48; x=x*100; y=y*10; z=z; pos1=x+y+z; Serial.print(key); Serial.print(d); Serial.println(); lcd.setCursor(10,0); lcd.print(key); lcd.print(d); delay(200); if(pos1>180) { Serial.println(); Serial.print("You Enterd an invalid value please enter valid value"); lcd.setCursor(0,0); lcd.print("Invalid Value"); Serial.println(" "); delay(500);

goto start1; } // Elivation Angle of the Security Camera start2: k,k1,k2,x,y,z=0; lcd.setCursor(1,1); Serial.println("Elivation Angle lcd.print("El "); // key=kpd.getKey(); key=kpd.waitForKey(); if (key != NO_KEY) { lcd.print(key); } if(key=='*') { goto Manual; } else if(key=='#') ");

{ goto Reset; } x= key-48; Serial.print(key); lcd.setCursor(9,1); lcd.print(key); // key= kpd.getKey(); key=kpd.waitForKey(); if (key != NO_KEY) { lcd.print(key); } if(key=='*') { goto Manual; } else if(key=='#') { goto Reset; }

y=key-48; k1=x*10; k2=y; k=k1+k2; Serial.print(key); lcd.setCursor(10,1); lcd.print(key); //key= kpd.getKey(); key=kpd.waitForKey(); if (key != NO_KEY) { lcd.print(key); } if(key=='*') { goto Manual; } else if(key=='#') { goto Reset; }

z=key-48; x=x*100; y=y*10; z=z; pos2=x+y+z; Serial.print(key); Serial.print(d); Serial.println(); lcd.setCursor(11,1); lcd.print(key); lcd.print(d); delay(200); if(pos2>90) { Serial.println(); Serial.print("You Enterd an invalid value please enter valid value"); lcd.setCursor(1,1); lcd.println("Invalid Value"); Serial.println(); delay(500);

goto start2; } } lcd.clear(); Serial.print("Rotating"); lcd.print("Rotating"); Serial.println(); Serial.print("........................."); Serial.println(); delay(100); // Azimuthal Movment of Security Camera if(pos1>pos3) { for(i=0;i<=pos1;i++) { rotation.write(i); delay(dd); } } else if(pos1<pos3)

{ for(i=pos3;i>=pos1;i--) { rotation.write(i); delay(dd); } } else { } // Elevation Movment of Security Camera if(pos2>pos4) { for(i=0;i<pos2;i++) { allivation.write(i); delay(dd); } } else if(pos2<pos4)

{ for(i=pos4;i>=pos2;i--) { allivation.write(i); delay(dd); } } else { } // pos3 and pos4 are used to store the value of pos1 and pos2 repectively pos3=pos1; pos4=pos2; delay(500); lcd.clear(); lcd.setCursor(0,0); Serial.println(); Serial.print(" Done"); Serial.println(); lcd.print("Done");

lcd.setCursor(1,1); lcd.print(pos1); lcd.print(d); lcd.setCursor(9,1); lcd.print(pos2); lcd.print(d); Serial.println("Current Position of motor "); Serial.println(); Serial.print("Azimuthal Angle "); Serial.print(pos1); Serial.print(d); Serial.print(" "); Serial.print("Elivation Angle "); Serial.print(pos2); Serial.print(d); Serial.println(); Serial.println(); Serial.println(); delay(100); goto Manual; }

You might also like