|
|
|
@@ -1,5 +1,9 @@ |
|
|
|
// ---------------------------------------------------------------- // |
|
|
|
|
|
|
|
// Arduino Ultrasoninc Sensor HC-SR04 |
|
|
|
// Re-writed by Arbi Abdul Jabbaar |
|
|
|
// Using Arduino IDE 1.8.7 |
|
|
|
// Using HC-SR04 Module |
|
|
|
// Tested on 17 September 2019 |
|
|
|
// ---------------------------------------------------------------- // |
|
|
|
|
|
|
|
#define echoPin 2 // attach pin D2 Arduino to pin Echo of HC-SR04 |
|
|
|
@@ -35,19 +39,17 @@ void loop() { |
|
|
|
digitalWrite(trigPin, LOW); |
|
|
|
|
|
|
|
duration = pulseIn(echoPin, HIGH); |
|
|
|
|
|
|
|
distance = duration * 0.034 / 2; |
|
|
|
|
|
|
|
|
|
|
|
if (distance < 30 ) { ouverture(); } |
|
|
|
if (distance > 30) { Serial.println("-"); } |
|
|
|
|
|
|
|
if (distance < 30 && distance > 1) { ouverture(); } |
|
|
|
if (distance > 30) { Serial.println("-"); fermeture(); } |
|
|
|
Serial.println(distance); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ouverture(){ |
|
|
|
|
|
|
|
Serial.println("Ouverture du bouchon"); |
|
|
|
digitalWrite(13, HIGH); |
|
|
|
myServo.write(170); |
|
|
|
@@ -55,11 +57,9 @@ void ouverture(){ |
|
|
|
Serial.println("Fermeture du bouchon"); |
|
|
|
digitalWrite(13, LOW); |
|
|
|
delay(2000); |
|
|
|
myServo.write(5); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
myServo.write(5); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void fermeture(){} |
|
|
|
|
|
|
|
|