Voilà, ça fonctionne bien avec les transistors :) Merci MrAlexis pour ton aide. Pour info, j'ai lu à plusieurs endroits que pour un pont utilisant seulement des mosfet N, la partie haute du pont devait être commutée avec une tension supérieure à la tension désirée en sortie. La prochaine fois je ferais un montage plus standard, avec deux N et deux P, qui ne présente pas cet inconvénient.
Plus qu'à faire le même montage pour l'autre moteur, et mon robot pourra faire des marche arrière et autres demis tours...
Cooljfo, en ce qui concerne la télécommande infrarouge, voici
la librairy et le bout de code que j'ai bricolé. Comme je l'indiquais plus haut, ça ne fonctionnait pas très bien (pas très réactif), donc il y a sans doute pas mal de trucs à améliorer.
Les codes rc5 définis au début du programme varient selon ta télécommande. Le plus simple pour les connaitre est d'utiliser le code d'exemple "How to receive" et de relever les valeurs sur le Serial Monitor.
// Contrôle deux moteurs grâce à une télécommande infrarouge
#include
//doc : http://www.arcfn.com/2009/08/multi-protocol-infrared-remote-library.html
// Définition des codes rc5 (varie selon le modèle de télécommande)
int rc5Haut = 4294950975;
int rc5Gauche = 8415;
int rc5Droite = 6375;
int rc5Bas = 765;
int rc5LED = 4294939245;
//diode IR
int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;
//blinkenlights
const int RED_PIN = 5;
const int YELLOW_PIN = 4;
const int GREEN_PIN = 3;
//moteurs
const int RightPin = 9; // pin that the Right Motor is attached to
const int LeftPin = 10; // pin that the Left Motor is attached to
// variables de réglage
int delai_rot = 150; //temps nécessaire pour faire un quart de tour
int delai_av = 400; //réglage du "pas"
//Déclaration de quelques variables
int direction = 0;
int rc5;
void setup() {
pinMode(RED_PIN, OUTPUT);
pinMode(YELLOW_PIN, OUTPUT);
pinMode(GREEN_PIN, OUTPUT);
// initialize serial communications at 9600 bps:
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
pinMode(RightPin, OUTPUT);
pinMode(LeftPin, OUTPUT);
}
void loop() {
//reception du signal, diag
if (irrecv.decode(&results)) {
rc5 = (results.value);
Serial.println(rc5, HEX);
if (rc5 == rc5LED) {
Serial.print(rc5,HEX);
Serial.println(" : Signal LED");
direction = 4;
}
if (rc5 == rc5Haut) {
Serial.print(rc5,HEX);
Serial.println(" : Signal Avancer");
direction = 2;
}
if (rc5 == rc5Gauche) {
Serial.print(rc5,HEX);
Serial.println(" : Signal Gauche");
direction = 1;
}
if (rc5 == rc5Droite) {
Serial.print(rc5,HEX);
Serial.println(" : Signal Droite");
direction = 3;
}
if (rc5 == rc5Bas) {
Serial.print(rc5,HEX);
Serial.println(" : Signal Stop");
direction = 0;
}
irrecv.resume(); // Receive the next value
}
//action à effectuer en fonction du signal reçu :
switch (direction) {
case 2 : //avance d'un pas, puis stop
digitalWrite(LeftPin, HIGH);
digitalWrite(RightPin, HIGH);
delay(delai_av);
direction = 0;
break;
case 0 : //stop
digitalWrite(LeftPin, LOW);
digitalWrite(RightPin, LOW);
break;
case 1 : //1/4 tour à gauche, puis stop
digitalWrite(LeftPin, HIGH);
digitalWrite(RightPin, LOW);
delay(delai_rot);
direction = 0;
break;
case 3 : //1/4 tour à droite, puis stop
digitalWrite(LeftPin, LOW);
digitalWrite(RightPin, HIGH);
delay(delai_rot);
direction = 0;
break;
case 4 : //blinkenlights
digitalWrite(RED_PIN, HIGH);
delay(500);
digitalWrite(YELLOW_PIN, HIGH);
delay(500);
digitalWrite(RED_PIN, LOW);
digitalWrite(GREEN_PIN, HIGH);
delay(500);
digitalWrite(YELLOW_PIN, LOW);
delay(500);
digitalWrite(GREEN_PIN, LOW);
break;
default :
break;
}
}
[/code]