ENIB 2020 : Coucoumatron : Différence entre versions

De Les Fabriques du Ponant
Aller à : navigation, rechercher
m (Liste des composants)
(Code)
Ligne 16 : Ligne 16 :
 
==Code==
 
==Code==
  
Le code est disponible sur Framagit : https://framagit.org/coucoumatron/coucoumatron
+
<code>
 +
/*
 +
*
 +
* The circuit:
 +
* * Module HR-SC04 (four pins) or PING))) (and other with
 +
*  three pins), attached to digital pins as follows:
 +
* ---------------------    --------------------
 +
* | HC-SC04 | Arduino |    | 3 pins | Arduino |
 +
* ---------------------    --------------------
 +
* |  Vcc  |  5V    |    |  Vcc  |  5V    |
 +
* |  Trig  |  12    | OR |  SIG  |  13    |
 +
* |  Echo  |  13    |    |  Gnd  |  GND  |
 +
* |  Gnd  |  GND  |    --------------------
 +
* ---------------------
 +
*
 +
* * A servo on pin 5
 +
*
 +
* created 3 Apr 2014
 +
* by Erick Simões (github: @ErickSimoes | twitter: @AloErickSimoes)
 +
* modified 23 Jan 2017
 +
* by Erick Simões (github: @ErickSimoes | twitter: @AloErickSimoes)
 +
* modified 03 Mar 2017
 +
* by Erick Simões (github: @ErickSimoes | twitter: @AloErickSimoes)
 +
* modified 11 Jun 2018
 +
* by Erick Simões (github: @ErickSimoes | twitter: @AloErickSimoes)
 +
* modified 20 Jan 2020
 +
* by Nils Van Zuijlen (github: @nils-van-zuijlen)
 +
* This example code is released into the MIT License.
 +
*/
 +
 
 +
#include <Ultrasonic.h>
 +
#include <Servo.h>
 +
 
 +
/*
 +
* Pass as a parameter the trigger and echo pin, respectively,
 +
* or only the signal pin (for sensors 3 pins), like:
 +
* Ultrasonic ultrasonic(13);
 +
*/
 +
Ultrasonic ultrasonic(12, 13);
 +
Servo arm;
 +
int distance;
 +
 
 +
void setup() {
 +
  Serial.begin(9600);
 +
  arm.attach(5);
 +
  arm.write(10);
 +
}
 +
 
 +
void loop() {
 +
  // Pass INC as a parameter to get the distance in inches
 +
  distance = ultrasonic.read();
 +
 
 +
  Serial.println(distance);
 +
 
 +
  if (distance < 50) {
 +
    Serial.println("Coucou");
 +
    for (int i = 0; i<2; i++) {
 +
      arm.write(100);
 +
      delay(500);
 +
      arm.write(10);
 +
      delay(500);
 +
    }
 +
  }
 +
 
 +
  delay(500);
 +
}
 +
</code>
  
 
==Catégories==
 
==Catégories==
  
 
[[Catégorie:Enib2020]]
 
[[Catégorie:Enib2020]]

Version du 20 janvier 2020 à 15:10

Photo de l’équipe

Photoenib2018.jpg

Que fait ce projet ?

Lorsqu’on fait coucou (on passe sa main devant le capteur) à la boite, elle répond en faisant coucou à son tour.

Liste des composants

  • Arduino
  • Capteur de distance Ultrasons
  • Servomoteur
  • Des fils de connexion
  • Du carton ou d'autres matériaux pour réaliser la boite et le bras+main

Code

/*

*
* The circuit:
* * Module HR-SC04 (four pins) or PING))) (and other with
*   three pins), attached to digital pins as follows:
* ---------------------    --------------------
* | HC-SC04 | Arduino |    | 3 pins | Arduino |
* ---------------------    --------------------
* |   Vcc   |   5V    |    |   Vcc  |   5V    |
* |   Trig  |   12    | OR |   SIG  |   13    |
* |   Echo  |   13    |    |   Gnd  |   GND   |
* |   Gnd   |   GND   |    --------------------
* ---------------------
* 
* * A servo on pin 5
*
* created 3 Apr 2014
* by Erick Simões (github: @ErickSimoes | twitter: @AloErickSimoes)
* modified 23 Jan 2017
* by Erick Simões (github: @ErickSimoes | twitter: @AloErickSimoes)
* modified 03 Mar 2017
* by Erick Simões (github: @ErickSimoes | twitter: @AloErickSimoes)
* modified 11 Jun 2018
* by Erick Simões (github: @ErickSimoes | twitter: @AloErickSimoes)
* modified 20 Jan 2020
* by Nils Van Zuijlen (github: @nils-van-zuijlen)
* This example code is released into the MIT License.
*/
  1. include <Ultrasonic.h>
  2. include <Servo.h>

/*

* Pass as a parameter the trigger and echo pin, respectively,
* or only the signal pin (for sensors 3 pins), like:
* Ultrasonic ultrasonic(13);
*/

Ultrasonic ultrasonic(12, 13); Servo arm; int distance;

void setup() {

 Serial.begin(9600);
 arm.attach(5);
 arm.write(10);

}

void loop() {

 // Pass INC as a parameter to get the distance in inches
 distance = ultrasonic.read();
 
 Serial.println(distance);
 if (distance < 50) {
   Serial.println("Coucou");
   for (int i = 0; i<2; i++) {
     arm.write(100);
     delay(500);
     arm.write(10);
     delay(500);
   }
 }
 
 delay(500);

}

Catégories