Emakerz

Untitled

May 2nd, 2020
2,583
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. // vous pouvez copier, coller tout se script dans le logiciel arduino
  2. //Youtube : Emakerz
  3. //Vidéo fabriquer un distributeur de gel hydroalcoolique automatique
  4. // lien : https://youtu.be/4SBSe1jKelM
  5. #include <Servo.h> // librairie à télecharger (lien en description de ma vidéo)puis à ajouter : croquis/inclure une bibliothèque/ajouter
  6. #define trigPin 3
  7. #define echoPin 2
  8. Servo servo;
  9. int sound = 250;
  10. void setup() {
  11. Serial.begin (9600);
  12. pinMode(trigPin, OUTPUT);
  13. pinMode(echoPin, INPUT);
  14. servo.attach(4);
  15. }
  16. void loop() {
  17. long duration, distance;
  18. digitalWrite(trigPin, LOW);
  19. delayMicroseconds(2);
  20. digitalWrite(trigPin, HIGH);
  21. delayMicroseconds(10);
  22. digitalWrite(trigPin, LOW);
  23. duration = pulseIn(echoPin, HIGH);
  24. distance = (duration/2) / 29.1;
  25. if (distance < 7) { // distance inférieure à 7cm = activation
  26. servo.write(0);// position du servo moteur si il y a activation
  27. }
  28. else {
  29. servo.write(170);// position initiale di servo moteur
  30. }
  31. delay(500);
  32. }
Add Comment
Please, Sign In to add comment