Introduction: Xenio-bot "Car Controlled by Bluetooth"
Hello all!
We're students of UPMH , a mexican college , we're studying aeronautical engineering , and one of the main subjects is programming , we have done a car the car was built by our team , basing in the knowledge we acquired in the subject , the main purpose of the car was practice of all we have learnt during the time of the course , this car is our last project of the subject
Our crew are:
CORTES VALLE SERGIO
GARCIA SANCHEZ RAUL
LUNA GOMEZ VICTOR HUGO
JUAREZ MERA XENIA JAQUELINE
OROPEZA AGUILAR JOVANNI
We're students of UPMH , a mexican college , we're studying aeronautical engineering , and one of the main subjects is programming , we have done a car the car was built by our team , basing in the knowledge we acquired in the subject , the main purpose of the car was practice of all we have learnt during the time of the course , this car is our last project of the subject
Our crew are:
CORTES VALLE SERGIO
GARCIA SANCHEZ RAUL
LUNA GOMEZ VICTOR HUGO
JUAREZ MERA XENIA JAQUELINE
OROPEZA AGUILAR JOVANNI
Step 1: Get the Necessary Materials
The materials we have used are:
Arduino uno
Protoboard
Gauge wire 20, 21 y 22
H Bridge
Bluetooth module HC-06
Car structure with 2 engines
6 “AA” Batteries
A switch (you can use the one wich is included with the car)
Arduino uno
Protoboard
Gauge wire 20, 21 y 22
H Bridge
Bluetooth module HC-06
Car structure with 2 engines
6 “AA” Batteries
A switch (you can use the one wich is included with the car)
Step 2: If You Use an Old RC Car Test the Engines!
We looked for a RC car , for save money , we used a car of one integrant of our crew , then we tested the car’s engines to check the functionality of them , after that we remove the original car’s chip, to install the arduino “UNO” chip
1.- Check the engine's functionality
2.- Remove the original car’s chip
3.- Install the arduino “UNO” chip
1.- Check the engine's functionality
2.- Remove the original car’s chip
3.- Install the arduino “UNO” chip
Step 3: Connect
Connect with the wires Arduino "UNO" and BT module with the Protoboard
Step 4: Connect the Batteries
We used the batteries as the voltage source that provides energy to the car , we put a switch to turn on , or turn off the voltage source
Step 5: Make Your Own Script Code in Arduino , or Use Our Own Script Code!
We were programming our script code with Arduino , to send it to Arduino “UNO” chip , then we configured the Bluetooth module , after that, we installed the connections of the Arduino “UNO” chip , the protoboard, the Bluetooth module and the car’s engine
The last we have done is an app for android devices , the main purpose of our app is the Bluetooth communication between the smart phone and the module .
Our arduino code is:
#include <SoftwareSerial.h>
//Inicializacion de los pines
int bluetoothTx = 1;
int bluetoothRx = 0;
//Variables que corresponden a cada pin del Arduino, se omiten el pin 0 y pin 1 ya que estos se utilizan en la comunicación serial que se establece entre el Arduino y el módulo Bluetooth
int pin2=2;
int pin3=3;
int pin4=4;
int pin5=5;
int pin6=6;
int pin7=7;
int pin8=8;
int pin9=9;
int pin10=10;
int pin11=11;
int pin12=12;
int pin13=13;
//Varables de control utilizadas para controlar la velocidad de los motores DC
int velocidad = 255;
int velocidad2 = 255;
SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);
//Declaracion de los metodos que vamos a utilizar
void adelante();
void reversa();
void giro_derecha();
void giro_izquierda();
void pararMotorTraccion();
void pararMotorDireccion();
void encenderLuz();
void apagarLuz();
void encenderComponente();
void apagarComponente();
void encenderComponente2();
void apagarComponente2();
void encenderComponente3();
void apagarComponente3();
void modificarVelocidad(int vel);
void setup()
{
//Iniciamos la comunicacion serial con el USB y declaramos como salidas los pines que vamos a utilizar
Serial.begin(9600);
pinMode(pin2, OUTPUT);
pinMode(pin3, OUTPUT);
pinMode(pin4, OUTPUT);
pinMode(pin5, OUTPUT);
pinMode(pin6, OUTPUT);
pinMode(pin7, OUTPUT);
pinMode(pin8, OUTPUT);
pinMode(pin9, OUTPUT);
pinMode(pin10, OUTPUT);
pinMode(pin11, OUTPUT);
pinMode(pin12, OUTPUT);
pinMode(pin13, OUTPUT);
//Configuramos la conexion serial del bluetooth con el android
bluetooth.begin(115200);
bluetooth.print("$$$");
delay(100);
bluetooth.println("U,9600,N");
bluetooth.begin(9600);
}
void loop()
{
//Leemos del Bluetooth y escribimos en el serial
if(bluetooth.available())
{
char received = bluetooth.read();
char toSend = (char)bluetooth.read();
Serial.print(toSend);
}
//Si el android le manda algo al arduino este metodo toma el caracter que mando
//y en base a eso ejecuta el metodo deseado
if(Serial.available())
{
char toSend = (char)Serial.read();
bluetooth.print(toSend);
switch(toSend)
{
//Si recibe una C entra en el modo de control por medio de la pantalla Cardux
case 'C':
//Lee el siguiente pin y en base al numero o letra enciende el pin correspondiente
if(Serial.available())
{
char toSend2 = (char)Serial.read();
bluetooth.print(toSend2);
switch(toSend2){
//Botón de adelante presionado
case 'W': adelante(pin5 , pin6); break;
//Botón de reversa presionado
case 'S': reversa(pin5 , pin6); break;
//Botón de izquierda presionado
case 'A': giro_izquierda(pin2 , pin3); break;
//Botón de derecha presionado
case 'D': giro_derecha(pin2 , pin3); break;
//Este medoto se ejecuta al dejar de presionar el boton de adelante o reversa
case 'Z': pararMotor(pin5 , pin6); break;
//Este medoto se ejecuta al dejar de presionar el boton de derecha o izquierda
case 'X': pararMotor(pin2 , pin3); break;
//Cuando el switch de Luces esta en estado encendido
case 'I': encenderLuz(pin4); break;
//Cuando el switch de Luces esta en estado apagado
case 'O': apagarLuz(pin4); break;
//Cuando el switch de comp1 esta en estado encendido
case 'H': encenderComponente(pin8); break;
//Cuando el switch de comp1 esta en estado apagado
case 'B': apagarComponente(pin8); break;
//Cuando el switch de comp2 esta en estado encendido
case 'J': encenderComponente(pin9); break;
//Cuando el switch de comp2 esta en estado apagado
case 'N': apagarComponente(pin9); break;
//Cuando el switch de comp3 esta en estado encendido
case 'K': encenderComponente(pin10); break;
//Cuando el switch de comp3 esta en estado apagado
case 'M': apagarComponente(pin10); break;
//Si la aplicación se pausa por ejemplo al salir de la aplicación o al entrar una llamada apaga los motores que están conectados a los Pines 5 y 6, y a los Pines 2 y 3
// para evitar que estos sigan girando y se tenga un control del proyecto, si quieres apagar algo más solo agrega la línea de código que quieres que se ejecute
case 'x':
pararMotor(pin5 , pin6);
pararMotor(pin2 , pin3);
break;
//Método de control de velocidad del motor de tracción en el carrito
case 'V':
if(Serial.available())
{
char toSend3 = (char)Serial.read();
bluetooth.print(toSend3);
switch(toSend3){
//en base al valor que recibe es la velocidad que el carrito camina 64 es la más baja y 255 la más alta
case '0': modificarVelocidad(64); break;
case '1': modificarVelocidad(96); break;
case '2': modificarVelocidad(128); break;
case '3': modificarVelocidad(172); break;
case '4': modificarVelocidad(255); break;
}
}
break;
}//Fin del switch toSend2
} //Fin de if
break;
}
void adelante(int Pin1 , int Pin2){
analogWrite(Pin1,LOW);
analogWrite(Pin2,velocidad);
digitalWrite(pin13,HIGH);
}
void reversa(int Pin1 , int Pin2){
analogWrite(Pin1,velocidad);
analogWrite(Pin2,LOW);
digitalWrite(pin13,HIGH);
}
void pararMotor(int Pin1, int Pin2){
digitalWrite(Pin1,LOW);
digitalWrite(Pin2,LOW);
digitalWrite(pin13,LOW);
}
void modificarVelocidad(int vel){
velocidad=vel;
}
void modificarVelocidad2(int vel){
velocidad2=vel;
}
void giro_izquierda(int Pin1, int Pin2){
digitalWrite(Pin2,LOW);
digitalWrite(Pin1,velocidad2);
digitalWrite(pin13,HIGH);
}
void giro_derecha(int Pin1, int Pin2){
digitalWrite(Pin2,velocidad2);
digitalWrite(Pin1,LOW);
digitalWrite(pin13,HIGH);
}
void encenderLuz(int Pin){
digitalWrite(Pin,HIGH);
}
void apagarLuz(int Pin){
digitalWrite(Pin,LOW);
}
void encenderComponente(int Pin){
digitalWrite(Pin,HIGH);
}
void apagarComponente(int Pin){
digitalWrite(Pin,LOW);
}
void encenderPin(int Pin){
digitalWrite(Pin, HIGH);
}
void apagarPin(int Pin){
digitalWrite(Pin, LOW);
}
The last we have done is an app for android devices , the main purpose of our app is the Bluetooth communication between the smart phone and the module .
Our arduino code is:
#include <SoftwareSerial.h>
//Inicializacion de los pines
int bluetoothTx = 1;
int bluetoothRx = 0;
//Variables que corresponden a cada pin del Arduino, se omiten el pin 0 y pin 1 ya que estos se utilizan en la comunicación serial que se establece entre el Arduino y el módulo Bluetooth
int pin2=2;
int pin3=3;
int pin4=4;
int pin5=5;
int pin6=6;
int pin7=7;
int pin8=8;
int pin9=9;
int pin10=10;
int pin11=11;
int pin12=12;
int pin13=13;
//Varables de control utilizadas para controlar la velocidad de los motores DC
int velocidad = 255;
int velocidad2 = 255;
SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);
//Declaracion de los metodos que vamos a utilizar
void adelante();
void reversa();
void giro_derecha();
void giro_izquierda();
void pararMotorTraccion();
void pararMotorDireccion();
void encenderLuz();
void apagarLuz();
void encenderComponente();
void apagarComponente();
void encenderComponente2();
void apagarComponente2();
void encenderComponente3();
void apagarComponente3();
void modificarVelocidad(int vel);
void setup()
{
//Iniciamos la comunicacion serial con el USB y declaramos como salidas los pines que vamos a utilizar
Serial.begin(9600);
pinMode(pin2, OUTPUT);
pinMode(pin3, OUTPUT);
pinMode(pin4, OUTPUT);
pinMode(pin5, OUTPUT);
pinMode(pin6, OUTPUT);
pinMode(pin7, OUTPUT);
pinMode(pin8, OUTPUT);
pinMode(pin9, OUTPUT);
pinMode(pin10, OUTPUT);
pinMode(pin11, OUTPUT);
pinMode(pin12, OUTPUT);
pinMode(pin13, OUTPUT);
//Configuramos la conexion serial del bluetooth con el android
bluetooth.begin(115200);
bluetooth.print("$$$");
delay(100);
bluetooth.println("U,9600,N");
bluetooth.begin(9600);
}
void loop()
{
//Leemos del Bluetooth y escribimos en el serial
if(bluetooth.available())
{
char received = bluetooth.read();
char toSend = (char)bluetooth.read();
Serial.print(toSend);
}
//Si el android le manda algo al arduino este metodo toma el caracter que mando
//y en base a eso ejecuta el metodo deseado
if(Serial.available())
{
char toSend = (char)Serial.read();
bluetooth.print(toSend);
switch(toSend)
{
//Si recibe una C entra en el modo de control por medio de la pantalla Cardux
case 'C':
//Lee el siguiente pin y en base al numero o letra enciende el pin correspondiente
if(Serial.available())
{
char toSend2 = (char)Serial.read();
bluetooth.print(toSend2);
switch(toSend2){
//Botón de adelante presionado
case 'W': adelante(pin5 , pin6); break;
//Botón de reversa presionado
case 'S': reversa(pin5 , pin6); break;
//Botón de izquierda presionado
case 'A': giro_izquierda(pin2 , pin3); break;
//Botón de derecha presionado
case 'D': giro_derecha(pin2 , pin3); break;
//Este medoto se ejecuta al dejar de presionar el boton de adelante o reversa
case 'Z': pararMotor(pin5 , pin6); break;
//Este medoto se ejecuta al dejar de presionar el boton de derecha o izquierda
case 'X': pararMotor(pin2 , pin3); break;
//Cuando el switch de Luces esta en estado encendido
case 'I': encenderLuz(pin4); break;
//Cuando el switch de Luces esta en estado apagado
case 'O': apagarLuz(pin4); break;
//Cuando el switch de comp1 esta en estado encendido
case 'H': encenderComponente(pin8); break;
//Cuando el switch de comp1 esta en estado apagado
case 'B': apagarComponente(pin8); break;
//Cuando el switch de comp2 esta en estado encendido
case 'J': encenderComponente(pin9); break;
//Cuando el switch de comp2 esta en estado apagado
case 'N': apagarComponente(pin9); break;
//Cuando el switch de comp3 esta en estado encendido
case 'K': encenderComponente(pin10); break;
//Cuando el switch de comp3 esta en estado apagado
case 'M': apagarComponente(pin10); break;
//Si la aplicación se pausa por ejemplo al salir de la aplicación o al entrar una llamada apaga los motores que están conectados a los Pines 5 y 6, y a los Pines 2 y 3
// para evitar que estos sigan girando y se tenga un control del proyecto, si quieres apagar algo más solo agrega la línea de código que quieres que se ejecute
case 'x':
pararMotor(pin5 , pin6);
pararMotor(pin2 , pin3);
break;
//Método de control de velocidad del motor de tracción en el carrito
case 'V':
if(Serial.available())
{
char toSend3 = (char)Serial.read();
bluetooth.print(toSend3);
switch(toSend3){
//en base al valor que recibe es la velocidad que el carrito camina 64 es la más baja y 255 la más alta
case '0': modificarVelocidad(64); break;
case '1': modificarVelocidad(96); break;
case '2': modificarVelocidad(128); break;
case '3': modificarVelocidad(172); break;
case '4': modificarVelocidad(255); break;
}
}
break;
}//Fin del switch toSend2
} //Fin de if
break;
}
void adelante(int Pin1 , int Pin2){
analogWrite(Pin1,LOW);
analogWrite(Pin2,velocidad);
digitalWrite(pin13,HIGH);
}
void reversa(int Pin1 , int Pin2){
analogWrite(Pin1,velocidad);
analogWrite(Pin2,LOW);
digitalWrite(pin13,HIGH);
}
void pararMotor(int Pin1, int Pin2){
digitalWrite(Pin1,LOW);
digitalWrite(Pin2,LOW);
digitalWrite(pin13,LOW);
}
void modificarVelocidad(int vel){
velocidad=vel;
}
void modificarVelocidad2(int vel){
velocidad2=vel;
}
void giro_izquierda(int Pin1, int Pin2){
digitalWrite(Pin2,LOW);
digitalWrite(Pin1,velocidad2);
digitalWrite(pin13,HIGH);
}
void giro_derecha(int Pin1, int Pin2){
digitalWrite(Pin2,velocidad2);
digitalWrite(Pin1,LOW);
digitalWrite(pin13,HIGH);
}
void encenderLuz(int Pin){
digitalWrite(Pin,HIGH);
}
void apagarLuz(int Pin){
digitalWrite(Pin,LOW);
}
void encenderComponente(int Pin){
digitalWrite(Pin,HIGH);
}
void apagarComponente(int Pin){
digitalWrite(Pin,LOW);
}
void encenderPin(int Pin){
digitalWrite(Pin, HIGH);
}
void apagarPin(int Pin){
digitalWrite(Pin, LOW);
}
Step 6: Enjoy It!
Watch the car's video in the next link:
https://www.youtube.com/watch?v=75URgeTLRl8&feature=youtube_gdata_player
https://www.youtube.com/watch?v=75URgeTLRl8&feature=youtube_gdata_player