AUTORES:
Valentín Ferla López, Pablo Molina Ballester, Víctor Beamud Martínez y Valentín Ferla López.
DESCRIPCIÓN:
Nuestro proyecto consistirá en un coche equipado con una bomba de agua y un cañón para apagar incendios, manejado por nosotros vía Bluetooth.
MATERIALES:
- Arduino UNO.
- Ardumoto Shield.
- Bomba de Agua.
- 2 motores DC.
- 1 Arduino Bluetooth HC-06.
- 1 tupper (depósito agua).
- Interruptor.
- Pila de 9V (Para bomba de agua)
- 2 Pilas 18650 3.7V
- 1 Portapilas para 18650
- 1 Relay Keyes
- Cables (Al contar con solo una salida de 5V, utilizaremos un cable con un extremo macho y tres hembras)
CONEXIONES:
Bluetooth:
- RX –> PIN digital 7 del Ardumoto Shield
- TX –> PIN digital 8 del Ardumoto Shield
- GND –> GND del Ardumoto Shield
- +5V –> 5V del Ardumoto Shield
Portapilas:
Uno de los polos positivos –> VIN: Max 18V +
Uno de los polos negativos –> Bornes del interruptor
Interruptor:
Otro borne del interruptor –> VIN: Max 18V –
Motores:
Conectar cada uno de los polos del motor a cada una de las salidas A y B de la placa Ardumoto Shield
Relé:
- GND –> GND de la placa Ardumoto Shield
- VCC –> 5V de la placa Ardumoto Shield
- DAT –> PIN digital 9 de la placa Ardumoto Shield
Alimentación positiva y negativa –> Pila 9V y alimentación de bomba de agua
PROGRAMA
#include <SoftwareSerial.h>
SoftwareSerial bt1(8, 7); // RX (tx de bluetooth) | TX (rx de bluetooth)
char val;
#define CW 0 //Sentido 1
#define CCW 1 //Sentido 2
#define MOTOR_A 0
#define MOTOR_B 1
const byte PWMA = 3; //control velocidad motor A
const byte PWMB = 11; //control velocidad motor B
const byte DIRA = 12; //Dirección motor A
const byte DIRB = 13; //Direction motor B
void setup() {
Serial.begin(9600);
bt1.begin(9600);
pinMode(9, OUTPUT);
pinMode(PWMA, OUTPUT);
pinMode(PWMB, OUTPUT);
pinMode(DIRA, OUTPUT);
pinMode(DIRB, OUTPUT);
digitalWrite(PWMA, LOW);
digitalWrite(PWMB, LOW);
digitalWrite(DIRA, LOW);
digitalWrite(DIRB, LOW);
}
void loop() {
if ( bt1.available() ) {
val = bt1.read();
delay(25);
if ( val == ‘4’ ) {
accionMotor(MOTOR_A, CCW, 255);
accionMotor(MOTOR_A, CW, 127);
}
if ( val == ‘1’ ) {
accionMotor(MOTOR_A, CW, 255);
accionMotor(MOTOR_B, CW, 255);
}
if ( val == ‘2’ ) {
accionMotor(MOTOR_A, CCW, 127);
accionMotor(MOTOR_B, CCW, 127);
}
if ( val == ‘3’ ) {
accionMotor(MOTOR_B, CCW, 255);
accionMotor(MOTOR_B, CW, 127);
}
if ( val == ‘5’ ) {
stopMotor(MOTOR_A);
stopMotor(MOTOR_B);
}
if ( val == ‘6’ ) {
accionMotor(MOTOR_A, CW, 255);
accionMotor(MOTOR_B, CW, 255);
delay(10);
accionMotor(MOTOR_B, CCW, 255);
delay(10);
accionMotor(MOTOR_B, CW, 127);
delay(10);
}
if ( val == ‘7’ ) {
accionMotor(MOTOR_A, CW, 255);
accionMotor(MOTOR_B, CW, 255);
delay(10);
accionMotor(MOTOR_A, CCW, 255);
delay(10);
accionMotor(MOTOR_A, CW, 127);
delay(10);
}
if ( val == ‘8’ ) {
accionMotor(MOTOR_A, CCW, 127);
accionMotor(MOTOR_B, CCW, 127);
delay(10);
accionMotor(MOTOR_B, CCW, 255);
delay(10);
accionMotor(MOTOR_B, CW, 127);
delay(10);
}
if ( val == ‘9’ ) {
accionMotor(MOTOR_A, CCW, 127);
accionMotor(MOTOR_B, CCW, 127);
delay(10);
accionMotor(MOTOR_A, CCW, 255);
delay(10);
accionMotor(MOTOR_A, CW, 127);
delay(10);
}
if ( val == ‘+’ ) {
digitalWrite(9, HIGH);
}
if ( val == ‘-‘ ) {
digitalWrite(9, LOW);
}
}
}
void accionMotor(byte motor, byte dir, byte spd) {
if (motor == MOTOR_A) {
digitalWrite(DIRA, dir);
analogWrite(PWMA, spd);
}
else if (motor == MOTOR_B) {
digitalWrite(DIRB, dir);
analogWrite(PWMB, spd);
}
}
void stopMotor(byte motor) {
accionMotor(motor, 0, 0);
}