Tourelle Nerf Auto pilotée par Arduino Version 1

Description :

Projet de création d’une tourelle automatique nerf pilotée par un Arduino.

Voici la version 1.

La structure est modélisée sous Solidworks et imprimé grâce à une imprimante résine. (Elegoo Mars 2 Pro)

Elle est pilotée grace à un joystick et 2 boutons pour commander le tir et allumage des moteurs.

 

 

    Prérequis :

Matériel :

  • 1 x Carte Arduino Uno
  • 2 x Boutons
  • 1 x Servo Tower pro 9g sg90
  • 2 x Servos Tower Pro MG995
  • 2 x TT Moteur 130
  • 1 x KY-023 Joystick
  • 1 x L298N
  • 1 x Alimentation 9v
  • Fils de connexion
  • 1 x Breadboard

Version IDE :

 

 

Vidéo de démonstration :

 

Schéma de câblage :

 

Fichiers SolidWorks et STL :

 

 

Code :

#define joystick1 A0
#define joystick2 A1
#define btmoteur  4
#define bttire    5
#define borneENA  6
#define borneIN1  7
#define borneIN2  8
#define borneIN3  9
#define borneIN4  10
#define borneENB  11
#define servo1    2
#define servo2    3
#define servo3    12

int poservo1 = 80;
int poservo2 = 40;
int poservo3 = 180;

#include <Servo.h>
Servo monServo1;
Servo monServo2;
Servo monServo3;

void setup() {
  Serial.begin(9600);
  monServo1.attach(servo1); monServo1.write(poservo1);
  monServo2.attach(servo2); monServo2.write(poservo2);
  monServo3.attach(servo3); monServo3.write(poservo3);
  delay(10);
  pinMode(btmoteur, INPUT_PULLUP);
  pinMode(bttire, INPUT_PULLUP);
  pinMode(borneIN1, OUTPUT); pinMode(borneIN2, OUTPUT);
  pinMode(borneIN3, OUTPUT); pinMode(borneIN4, OUTPUT);
  pinMode(borneENA, OUTPUT); pinMode(borneENB, OUTPUT);
}

void loop() {
  int Joystick1 = analogRead(joystick1);
  int Joystick2 = analogRead(joystick2);

  if (Joystick1 > 800 && Joystick1 < 1024 && poservo1 < 140) {
    poservo1++;
    monServo1.write(poservo1);
    delay(10);
  }
  if (Joystick1 >= 0 && Joystick1 < 200 && poservo1 > 40) {
    poservo1--;
    monServo1.write(poservo1);
    delay(10);
  }
  if (Joystick2 > 800 && Joystick2 < 1024 && poservo2 < 70) {//haut
    poservo2++;
    monServo2.write(poservo2);
    delay(10);
  }
  if (Joystick2 >= 0 && Joystick2 < 200 && poservo2 > 10) {
    poservo2--;
    monServo2.write(poservo2);
    delay(10);
  }

  if (digitalRead(btmoteur) == 0) {
    digitalWrite(borneIN1, HIGH); digitalWrite(borneIN2, LOW);
    digitalWrite(borneIN3, LOW); digitalWrite(borneIN4, HIGH);
    analogWrite(borneENA, 250); analogWrite(borneENB, 250);
  }
  else {
    digitalWrite(borneIN1, LOW); digitalWrite(borneIN2, LOW);
    digitalWrite(borneIN3, LOW); digitalWrite(borneIN4, LOW);
  }
  if (digitalRead(bttire) == 0 && digitalRead(btmoteur) == 0) {
    monServo3.write(60);
  }
  else {
    monServo3.write(180);
  }
}

 


 

Laisser un commentaire