Devices & Components
Arduino Uno Rev3
Buzzer
Jumper wires (generic)
Ultrasonic Sensor - HC-SR04 (Generic)
9V DC Battery Connector
9V DC Battery
LED (generic)
Software & Tools
Arduino IDE
Project description
Code
PROXIMTY_ALARM_CODE
c_cpp
The code is used for proximity alarm which acts like a 'SONAR'. It starts with a tune from buzzer, which acts like a loading music ! The beeping of buzzer changes every time, depending upon the distance observed by ultra-sonic sensor!
1#define trigPin 13 2#define echoPin 12 3int buzz=8; 4int b; 5int led=7; 6int a=2; 7int count =15; 8//int j; 9//#define led 11 10//#define led2 10 11 12void setup() { 13 Serial.begin (9600); 14 15 pinMode(led,OUTPUT); 16 pinMode(trigPin, OUTPUT); 17 pinMode(echoPin, INPUT); 18 //pinMode(led, OUTPUT); 19 // pinMode(led2, OUTPUT); 20} 21 22void loop() { 23 24 for(int i=0;i<2;i++) 25 { while(count>0) 26 {tone(buzz,500*count,300); 27 // j=(rand()%10); 28 delay(count*10); 29 count--; 30 } 31 } 32 long duration, distance; 33 digitalWrite(trigPin, LOW); // Added this line 34 delayMicroseconds(2); // Added this line 35 digitalWrite(trigPin, HIGH); 36// delayMicroseconds(1000); - Removed this line 37 delayMicroseconds(10); // Added this line 38 digitalWrite(trigPin, LOW); 39 duration = pulseIn(echoPin, HIGH); 40 distance = (duration/2) / 29.1; 41 // if (distance < 4) { // This is where the LED On/Off happens 42 // digitalWrite(led,HIGH); // When the Red condition is met, the Green LED should turn off 43// digitalWrite(led2,LOW); 44//} 45 // else { 46 // digitalWrite(led,LOW); 47 //digitalWrite(led2,HIGH); 48 // } 49 if (distance >= 300 || distance <= 0){ 50 // Serial.println("Out of range"); 51 } 52 else { 53 //Serial.write(distance); 54 //Serial.println(" cm"); 55 b=distance/10; 56 tone(buzz,10000,50); 57 digitalWrite(led, HIGH); 58 digitalWrite(led, LOW); 59 60 delay(b*70); 61 } 62 // delay(500); 63} 64 65 66 67
Downloadable files
PROXIMTY_ALARM_CIRCUIT
PROXIMTY_ALARM_CIRCUIT

PROXIMTY_ALARM_CIRCUIT
PROXIMTY_ALARM_CIRCUIT

Comments
Only logged in users can leave comments