Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // vous pouvez copier, coller tout se script dans le logiciel arduino
- //Youtube : Emakerz
- //Vidéo fabriquer un distributeur de gel hydroalcoolique automatique
- // lien : https://youtu.be/4SBSe1jKelM
- #include <Servo.h> // librairie à télecharger (lien en description de ma vidéo)puis à ajouter : croquis/inclure une bibliothèque/ajouter
- #define trigPin 3
- #define echoPin 2
- Servo servo;
- int sound = 250;
- void setup() {
- Serial.begin (9600);
- pinMode(trigPin, OUTPUT);
- pinMode(echoPin, INPUT);
- servo.attach(4);
- }
- 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 < 7) { // distance inférieure à 7cm = activation
- servo.write(0);// position du servo moteur si il y a activation
- }
- else {
- servo.write(170);// position initiale di servo moteur
- }
- delay(500);
- }
Add Comment
Please, Sign In to add comment