FractalTech
Published © GPL3+

Create Your Own 2WD Arduino Robot with Bluetooth Control

Control a 2WD robot via Bluetooth using an Arduino UNO. A simple and fun project to learn mobile robotics and wireless control.

BeginnerFull instructions provided169
Create Your Own 2WD Arduino Robot with Bluetooth Control

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
DC Motor, 12 V
DC Motor, 12 V
×2
HC-05 Bluetooth Module
HC-05 Bluetooth Module
×1
SparkFun Full-Bridge Motor Driver Breakout - L298N
SparkFun Full-Bridge Motor Driver Breakout - L298N
×1
Battery Holder, 18650 x 2
Battery Holder, 18650 x 2
×1
Reed Switch, Roller Ball
Reed Switch, Roller Ball
×1

Software apps and online services

Arduino Control RC
Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Mastech MS8217 Autorange Digital Multimeter
Digilent Mastech MS8217 Autorange Digital Multimeter

Story

Read more

Custom parts and enclosures

spacer

spacer between chassis and idler ball

Sketchfab still processing.

chasis

chassis cut in 6 mm MDF

Schematics

schematics

Circuit diagram

Code

Code

Arduino
String 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}

Credits

FractalTech
2 projects • 1 follower

Comments