Hello
i have a project in my workshop. I have a lift for cars but my problem is that my my ceiling is too short so a car can hit the ceiling.
So i have a project to instal hc-sr04.
so i have the code that disables the lift (using optocoupler). My problem now is that i want a buzzer when the sensor and arduino stop the car. I want that in final position red LED would light up and stay on. At the same time the buzzer would make a noise for about 5 seconds and then turn off. But the red LED would stay on for as long the car is in the final position.
My program:
#define trigPin 13
#define echoPin 12
#define led 11
#define rele 10
void setup()
{ Serial.begin (9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(led, OUTPUT);
pinMode(rele, 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 < 10)
{ digitalWrite(led,HIGH);
digitalWrite(rele,LOW);
}
else {
digitalWrite(led,LOW);
digitalWrite(rele,HIGH);
}
Serial.print(distance);
Serial.println(" cm");
delay(500);
}
In this program i dont have the buzzer yet because i did everything wrong that i tried.
i tried:
const unsigned long BUZZERTime=2000;
unsigned long TimeCaptured = millis();
#define buzzer 3
void setup() {
pinMode(3,OUTPUT);
tone(buzzer, 2500);
}
void loop() {
if ( (millis() - TimeCaptured) >= BUZZERTime )
{
noTone(buzzer);
}
}
no luck.....
my buzzer is working and it is piezo.
thanks for the help...and sorry for my poor english ![]()