Ultrasonic Project

Hi All.

I am new to this world of Home Electronics, but it's a great hobby.

I have decided to make a Ultrasonic distance warning device for my garage, i am using the same circuit as is on this site as a recommended project. I have no problems with the circuitry, but i am, a bit puzzled. I understand that the Buzzer and LED's come on when a vehicle comes into the range of the transmitter, and the buzzer gets louder the closer you get, but what switches the buzzer off when you have stopped the car? is it software?

Regards

Ray

You should post the code rather than have us hunt it down on the Arduino site....

Or at least a hyperlink to the page?

Hi

As stated i am a novice, i do not yet know how to do that.

Regards

Ray

Hi again.

I hope i have done this right ?

#define trigPin 7
#define echoPin 6
#define led 13
#define led2 12
#define led3 11
#define led4 10
#define led5 9
#define led6 8
#define buzzer 3

int sound = 250;

void setup() {
Serial.begin (9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(led, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
pinMode(led5, OUTPUT);
pinMode(led6, 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/2) / 29.1;

if (distance <= 30) {
digitalWrite(led, HIGH);
sound = 250;
}
else {
digitalWrite(led,LOW);
}
if (distance < 25) {
digitalWrite(led2, HIGH);
sound = 260;
}
else {
digitalWrite(led2, LOW);
}
if (distance < 20) {
digitalWrite(led3, HIGH);
sound = 270;
}
else {
digitalWrite(led3, LOW);
}
if (distance < 15) {
digitalWrite(led4, HIGH);
sound = 280;
}
else {
digitalWrite(led4,LOW);
}
if (distance < 10) {
digitalWrite(led5, HIGH);
sound = 290;
}
else {
digitalWrite(led5,LOW);
}
if (distance < 5) {
digitalWrite(led6, HIGH);
sound = 300;
}
else {
digitalWrite(led6,LOW);
}

if (distance > 30 || distance <= 0){
Serial.println(“Out of range”);
noTone(buzzer);
}
else {
Serial.print(distance);
Serial.println(" cm");
tone(buzzer, sound);

}
delay(500);
}

http://forum.arduino.cc/index.php/topic,148850.0.html

This piece does it:

if (distance > 30 || distance <= 0){
    Serial.println("Out of range");
    noTone(buzzer);
  }

You’ll probably have to tweak the 30 and 0 a bit to set the system up for the place you park your car. It’s just based on distance from the sensor though - it doesn’t care whether you have the car running/moving or not.

i guess you should have posted in programming questions and be sure to use the tags when posting code. I used an ultrasonic in my own garage parking sensor. I found the buzzer to be to quiet without the window down so I didn't use it.

but what switches the buzzer off when you have stopped the car? is it software?

Yes. Your code will need to detect that it has been on for enough time without any detected movement. Here is a link to an instructable I made. I hope it helps http://www.instructables.com/id/Ultrasonic-Garage-Parking-Assistant-with-Arduino/

H i rclmer.

Many thanks, it,s exactly what i am looking for.

If i may ask you a question further, my garage is a busy place, we store Freezers and a clothes drier in it, not to mention it's my workshop, so how can i disarm / put it to sleep, when there is no car in the garage, can this be done with the program, or can i power the Arduino from mains power transformed to low voltage of course and use something like an Infrared sensor beam activating the sensor when the car drives into the garage and breaks the beam?

Regards

Ray

Hmm, you could always add another button or switch that would disable it, put all the code in loop() into an if statement based on the condition of a switch.