| @@ -1,34 +1,43 @@ | |||
| // ---------------------------------------------------------------- // | |||
| // 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 | |||
| // ---------------------------------------------------------------- // | |||
| // Programme réalisé dans le cadre d'un projet BTS | |||
| // Servo Moteur : | |||
| #define echoPin 2 // attach pin D2 Arduino to pin Echo of HC-SR04 | |||
| #define trigPin 3 //attach pin D3 Arduino to pin Trig of HC-SR04 | |||
| // #define echoPin 2 // attach pin D2 Arduino to pin Echo of HC-SR04 | |||
| // #define trigPin 3 //attach pin D3 Arduino to pin Trig of HC-SR04 | |||
| #include <Servo.h> | |||
| Servo myServo; | |||
| const int trigPin = 9; | |||
| const int echoPin = 10; | |||
| const int servoPin = 6; | |||
| const int alimentation_Servo = 12; | |||
| long duration; | |||
| int distance; | |||
| void setup() { | |||
| pinMode(trigPin, OUTPUT); | |||
| pinMode(echoPin, INPUT); | |||
| pinMode(9, OUTPUT); | |||
| pinMode(13, OUTPUT); | |||
| digitalWrite(9, HIGH); | |||
| Serial.begin(9600); | |||
| Serial.println("Projet BTS Mathieu N."); | |||
| Serial.println("BTS Ecole Technique EME"); | |||
| myServo.attach(10); | |||
| myServo.write(5); | |||
| Serial.println("--------------------------------------------------------------------------"); | |||
| Serial.println("Initialisation du programme"); | |||
| pinMode(trigPin, OUTPUT); | |||
| Serial.print("Pin du Trigger du capteur ultrason : "); | |||
| Serial.println(trigPin); | |||
| Serial.print("Pin du Echo du capteur ultrason : "); | |||
| Serial.println(echoPin); | |||
| Serial.print("Pin d'alimentation du servomoteur : "); | |||
| Serial.println(alimentation_Servo); | |||
| Serial.print("Pin pour controler le servo : "); | |||
| Serial.println(servoPin); | |||
| delay(200); | |||
| pinMode(echoPin, INPUT); | |||
| pinMode(alimentation_Servo, OUTPUT); | |||
| myServo.attach(servoPin); | |||
| myServo.write(5); | |||
| } | |||
| void loop() { | |||
| @@ -41,12 +50,13 @@ void loop() { | |||
| duration = pulseIn(echoPin, HIGH); | |||
| distance = duration * 0.034 / 2; | |||
| Serial.print("Mesure de la valeur : "); | |||
| Serial.println(distance); | |||
| myServo.write(5); | |||
| if (distance < 30 && distance > 1) { | |||
| delay(500); | |||
| delay(100); | |||
| Serial.println("1ere verification validée, on passe à la suivante"); | |||
| digitalWrite(trigPin, LOW); | |||
| @@ -74,4 +84,4 @@ void ouverture(){ | |||
| digitalWrite(13, LOW); | |||
| delay(2000); | |||
| } | |||
| } | |||