Devices & Components
Arduino Uno Rev3
Bluetooth hc-05
25W L298N Dual HBridge
portapilas
B01 1:120 Motorreductor Plastico 1:120 un eje.
Hardware & Tools
Multimeter
Software & Tools
Arduino IDE
Arduino Control RC
Project description
Code
Bluetooth2WD
cpp
Control a 2WD robot via Bluetooth using an Arduino
1String codigo = ""; 2 3//MOTOR 1 4const int M1A=5; 5const int M1B=6; 6//MOTOR 2 7const int M2A=9; 8const int M2B=10; 9 10 11//velocidad 12int vel=128; 13 14 15void setup() { 16 17 Serial.begin(9600); 18 //MOTOR 1 19 pinMode(M1A,OUTPUT); 20 pinMode(M1B,OUTPUT); 21 //MOTOR2 22 pinMode(M2A,OUTPUT); 23 pinMode(M2B,OUTPUT); 24 25 //Inicia detenido tanto el motor A , como el motor B 26 analogWrite(M1A,0); 27 analogWrite(M1B,0); 28 analogWrite(M2A,0); 29 analogWrite(M2B,0); 30} 31 32void loop() { 33 if (Serial.available() > 0) { 34 char caracter = Serial.read(); // Leer un carácter. // Read a character. 35 if (caracter != '\n') { 36 codigo += caracter; // Agrega el carácter al comando. // Add character to the command. 37 } else { 38 char inicial= codigo.charAt(0); 39 switch (inicial) { 40 case 'F': 41 adelante(); 42 Serial.println("Adelante"); 43 break; 44 case 'G': 45 atras(); 46 Serial.println("Atras"); 47 break; 48 case 'R': 49 derecha(); 50 Serial.println("Derecha"); 51 break; 52 case 'L': 53 izquierda(); 54 Serial.println("Izquierda"); 55 break; 56 case 'S': 57 detener(); 58 Serial.println("Detener"); 59 break; 60 case '#': 61 String numero= codigo.substring(1); // Desde el índice 1 hasta el final 62 vel=numero.toInt(); // actualiza la velocidad del vehiculo 63 break; 64 default: 65 Serial.println("Comando no válido"); 66 break; 67 } 68 codigo = ""; // Limpia el comando para el siguiente. // Clear the command string for next. 69 } 70 } 71 72} 73 74void adelante(){ 75 analogWrite(M1A,vel); 76 analogWrite(M1B,0); 77 analogWrite(M2A,vel); 78 analogWrite(M2B,0); 79} 80void atras(){ 81 analogWrite(M1A,0); 82 analogWrite(M1B,vel); 83 analogWrite(M2A,0); 84 analogWrite(M2B,vel); 85} 86void derecha(){ 87 analogWrite(M1A,vel); 88 analogWrite(M1B,0); 89 analogWrite(M2A,0); 90 analogWrite(M2B,vel); 91 92} 93void izquierda(){ 94 analogWrite(M1A,0); 95 analogWrite(M1B,vel); 96 analogWrite(M2A,vel); 97 analogWrite(M2B,0); 98} 99void detener(){ 100 analogWrite(M1A,0); 101 analogWrite(M1B,0); 102 analogWrite(M2A,0); 103 analogWrite(M2B,0); 104}
Downloadable files
Chasis
chassis cut in 6 mm MDF
chasis.pdf
spacer
spacer between chassis and idler ball
Acople_bola_loca.STL
Documentation
Circuit diagram
Circuit diagram
esquema.png

Comments
Only logged in users can leave comments