Step 1: Decide that you want to make a low key security system that will be able to detect objects and tell you how far away the object or person is. The instructions come from a separate website, but this is how I did it with more details that were not given here: Personal Security System
Step 2: Buy all the materials needed:
Step 3: Place all components onto the board: Although on the online instruction they say to plug into the Trig to 7 THAT IS NOT RIGHT. Make sure to plug the trig into 6 and the echo into 7 or other wise it will not work.
Continue following on internet.
Although I was unable to successfully complete the eagle board if one more hole was added to the side of the buzzer, then the board would be ready to cut on the other mill. I used the great program of 123D circuit which was much less confusing then eagle and in my opinion worked better. Here is the link and this can be easily exported by clicking the download gerber button. Here is the link to my 123D design : CLICK HERE . After clicking on the link make sure to duplicate the project and make your own changes!
Extra notes:
Here is the code you should use:
#define trigPin 6
#define echoPin 7
#define GreenLED 11
#define YellowLED 10
#define RedLED 9
#define buzzer 3
int sound = 500;
void setup() {
Serial.begin (9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(GreenLED, OUTPUT);
pinMode(YellowLED, OUTPUT);
pinMode(RedLED, OUTPUT);
pinMode(buzzer, OUTPUT);
}
void loop() {
long duration, distance;
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/5) / 29.1;
if (distance < 50) {
digitalWrite(GreenLED, HIGH);
//If the distance is less then 50 cm then the green light goes off
}
else {
digitalWrite(GreenLED, LOW);
}
if (distance < 20) {
digitalWrite(YellowLED, HIGH);
}
else {
digitalWrite(YellowLED,LOW);
}
if (distance < 5) {
digitalWrite(RedLED, HIGH);
sound = 1000;
}
else {
digitalWrite(RedLED,LOW);
}
if (distance > 5 || distance <= 0){
Serial.println("Out of range");
noTone(buzzer);
}
else {
Serial.print(distance);
Serial.println(" cm");
tone(buzzer, sound);
}
delay(300);
}