Bonjour
Voilà je suis actuellement en train de réaliser une cuillère à glace commandé par un moteur pas à pas dépendant d'un capteur ultrason pour son ouverture et sa fermeture. Pour ce faire j'utilise le motor shield de chez adafruit Adafruit Motor/Stepper/Servo Shield for Arduino kit [v1.2] : ID 81 : $19.50 : Adafruit Industries, Unique & fun DIY electronics and kits pont en H, un capteur ultrason et un petit moteur pas à pas connecté à ma cuillère par un engrenage.
J'ai déjà réaliser un programme qui me satisfait moyennement et je souhaiterais l'améliorer
Donc pour le moment mon programme ouvre la cuillère lorsque la distance est inférieur ou égal à 40 cm, puis attend 10 secondes
pour enfin refermer la cuillère.
Je souhaiterais que le comportement se fasse autrement, c'est à dire que l'orsq'un obstacle se trouve à moins de 40 cm ma cuillère s'ouvre bien sûr mais que par la suite celle-ci ne se referme que l'orsque l'obstacle sort du champ du capteur (> à 40 cm).
J'ai tenté de le faire mais sans succès car évidement si l'obstacle reste indéfiniment à - de 40 cm mon moteur vas executer une rotation en boucle toujours dans le même sens. Pensez-vous que je puisse réaliser cela sans interrupteur de fin de course?
Voici mon code actuellement
#include <AFMotor.h>
AF_Stepper motor(48,1);
const int pingPin = 2;
void setup() {
// initialize serial communication:
Serial.begin(9600);
motor.setSpeed(100); // 50 rpm
}
void loop()
{
// establish variables for duration of the ping,
// and the distance result in inches and centimeters:
long duration, inches, cm;
// The PING))) is triggered by a HIGH pulse of 2 or more microseconds.
// Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(5);
digitalWrite(pingPin, LOW);
// The same pin is used to read the signal from the PING))): a HIGH
// pulse whose duration is the time (in microseconds) from the sending
// of the ping to the reception of its echo off of an object.
pinMode(pingPin, INPUT);
duration = pulseIn(pingPin, HIGH);
// convert the time into a distance
inches = microsecondsToInches(duration);
cm = microsecondsToCentimeters(duration);
//Serial.print(inches);
//Serial.print("in, ");
Serial.print(cm);
Serial.print("cm");
Serial.println();
if (cm <= 40) {
motor.step(229, FORWARD, MICROSTEP);
delay(10000);
motor.step(229, BACKWARD, MICROSTEP);
motor.release();
}
}
long microsecondsToInches(long microseconds)
{
// According to Parallax's datasheet for the PING))), there are
// 73.746 microseconds per inch (i.e. sound travels at 1130 feet per
// second). This gives the distance travelled by the ping, outbound
// and return, so we divide by 2 to get the distance of the obstacle.
// See: http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf
return microseconds / 74 / 2;
}
long microsecondsToCentimeters(long microseconds)
{
// The speed of sound is 340 m/s or 29 microseconds per centimeter.
// The ping travels out and back, so to find the distance of the
// object we take half of the distance travelled.
return microseconds / 29 / 2;
}
Merci d'avance pour vos aides