Vous êtes sur la page 1sur 6

Sonar-based security system

Concept: Creation of a security system which can be used in high-security vaults etc. to detect motion. The sensor reads distances of the nearest object at each angle and records the distances. The data in both the clockwise and the anti-clockwise rotations are compared and any change in the distance of the nearest object at any angle due to movement triggers an alarm. Team members: Rushina Shah Janaki Sheth Mentor: Ayesha Mudassir Software used: Arduino Working: http://www.youtube.com/watch?v=5AeZUpksal8 A video of the working model is demonstrated on the youtube link given above. The sensor HC-SR04 is mounted on top of the motor, Futaba S3003. The arduino board, run by a laptop, provides the voltage to operate both the sensor and the motor. The motor is controlled by a code which rotates it in 180 degrees clockwise in steps of 1 degree each. At every angle, the sensor records fifty values each. The program registers the mode of these fifty values as the distance of the nearest object at that angle. These distances (total 180 of them) are stored in an array.

unsigned long mode(unsigned long *dst) { for(int i=0; i<n; i++) { for(int j=0; j<n; j++) { if(dst[i]<=dst[j]+5&&dst[i]>=dst[j]-5 ) freq[i]++; } } maxi=dst[0]; for(int i=0; i<n; i++) { if(maxi<dst[i]) { maxi=dst[i]; mod=i; } } return dst[mod];
The mode is used in order to increase efficiency and record a precise value. The sensor works on the concept of transmission and reflection of sonar waves. After the 180 degree clockwise rotation, the motor moves anti-clockwise. The mode of the distances at each angle is compared with the previous

recorded value. If the value is the same, within a reasonable error margin, the motor moves ahead. If it is not, the buzzer is triggered without any time-delay. Accounting for error: The values are checked within 10 cm of error margin from the previous recorded mode. If the new value lies within the range, the old record is re-written. If it doesnt, the alarm is triggered. The complete Arduino code used is given below:

#include <Servo.h> #include <Ultrasonic.h> Servo myservo; Ultrasonic hcsr(13,12); int pos=0, cnt=0; const int n=50; unsigned long dist[n], d[181], tempd=0; int freq[n], maxi, mod, var=0; void setup() { Serial.begin(9600); myservo.attach(9); for(int i=0; i<n; i++) { dist[i]=0; freq[i]=0; } for(int i=0; i<=180; i++) d[i]=0; pinMode(5, OUTPUT); pinMode(4, OUTPUT); } void loop() { for(int i=0; i<100; i++) hcsr.Ranging(CM); digitalWrite(5, LOW); digitalWrite(4, LOW); for(pos=0; pos<=180; pos+=1) { myservo.write(pos); for(int i=0; i<n; i++) { dist[i]=hcsr.Ranging(CM); if(var==0) { var=1; } } tempd=mode(dist); Serial.print(pos); Serial.print(,);

Serial.println(tempd); if(cnt==0) { d[pos]=tempd; } else { if(!(tempd>=d[pos]-10&&tempd<=d[pos]+10||tempd==d[pos])) { while(1){ digitalWrite(5, HIGH); } } d[pos]=tempd; } delayMicroseconds(5); } cnt=1; for(pos=180; pos>=0; pos-=1) { myservo.write(pos); for(int i=0; i<n; i++) { dist[i]=hcsr.Ranging(CM); } tempd=mode(dist); Serial.print(pos); Serial.print(,); Serial.println(tempd); if(cnt==0) { d[pos]=tempd; } else { if(!(tempd>=d[pos]-10&&tempd<=d[pos]+10||tempd==d[pos])) { while(1){ digitalWrite(5, HIGH); } } d[pos]=tempd; } delayMicroseconds(5); } } unsigned long mode(unsigned long *dst) { for(int i=0; i<n; i++) { for(int j=0; j<n; j++)

{ if(dst[i]<=dst[j]+5&&dst[i]>=dst[j]-5 ) freq[i]++; } } maxi=dst[0]; for(int i=0; i<n; i++) { if(maxi<dst[i]) { maxi=dst[i]; mod=i; } } return dst[mod];
Mapping the room: Using Processing software, the distances are mapped onto the laptop screen, providing a 2-D map of the room at the level of the sensor.

The code used in the processing software is given below: import processing.serial.*;

float angle1 = 0, angle2 = 0; volatile String inString; volatile int data; Serial myPort; PFont p;

int [] distance = new int[180];

void setup(){ size(1200, 600); println(Serial.list()); myPort = new Serial (this, Serial.list()[0], 9600); myPort.bufferUntil('\n'); p = createFont("TimesNewRomanPSMT-48", 16, true);

setScreen();

void draw(){

/* Debug textFont(p); textAlign(CENTER); text(inString, width/2, height/2); */

void serialEvent(Serial p){ inString = p.readString(); float[] numlist = float(split(inString, ',')); //0 deg - 360 deg line(width/2, height/2, width/2 - numlist[1]*cos( radians(numlist[0])), height/2 numlist[1]*sin(radians(numlist[0]))); //0 deg - 180 deg //line(width/2, height/2, width/2 - numlist[1]*cos(radians(numlist[0])), height/2 numlist[1]*sin(radians(numlist[0]))); if(numlist[0] == 179)setScreen();

void setScreen(){ background(0, 70, 100); fill(255); /*ellipse(width/2, height/2, 400, 400);

fill(0);*/ }

The video of the surroundings being sketched is uploaded on the given youtube linkhttp://www.youtube.com/watch?v=A4QIlHQDxRo

Vous aimerez peut-être aussi