Voici la premiere étape de la construction de mon robot ( Jhonny 1.0 :p)
Le but est de controler deux servos via l'arduino alimenté sur batterie. Le robot effectue une séquence programmée : Avancer 3sec, tourner à droite, ....
Résultat :
La prochaine étape sera de connecter le raspberry avec l'Arduino et de le commander via une interface WEB :-)
Montage :
Code :
// Control 2 servo on Battery // The servo go forward for 3 sec and after turn right #includeServo leftservo; Servo rightservo; const int rightservopin = 8; const int leftservopin = 7; int speed = 10; void setup() { pinMode(leftservopin,OUTPUT); pinMode(rightservopin,OUTPUT); gostop(); Serial.begin(19200); Serial.println("Ready"); Serial.println("Play Beep"); pinMode(10, OUTPUT); beep(50); delay(100); beep(50); delay(100); beep(50); delay(4000); } void gostop() { leftservo.detach(); rightservo.detach(); } void beep(unsigned char delayms){ analogWrite(10, 20); // Almost any value can be used except 0 and 255 // experiment to get the best tone delay(delayms); // wait for a delayms ms analogWrite(10, 0); // 0 turns it off delay(delayms); // wait for a delayms ms } void loop() { beep(200); // Avancer pendant 3 sec leftservo.attach(leftservopin); rightservo.attach(rightservopin); rightservo.write(90 - speed); leftservo.write(90 + speed ); delay(3000); // Tour de 90degre a droite rightservo.write(90 + speed); leftservo.write(90 + speed ); delay(750); // Avancer pendant 3 sec rightservo.write(90 - speed); leftservo.write(90 + speed ); delay(3000); // Tour de 90degre a droite rightservo.write(90 + speed); leftservo.write(90 + speed ); delay(750); // Avancer pendant 3 sec rightservo.write(90 - speed); leftservo.write(90 + speed ); delay(3000); // Tour de 90degre a droite rightservo.write(90 + speed); leftservo.write(90 + speed ); delay(750); // Avancer pendant 3 sec rightservo.write(90 - speed); leftservo.write(90 + speed ); delay(3000); // Tour de 90degre a droite rightservo.write(90 + speed); leftservo.write(90 + speed ); delay(750); gostop(); }