I don´t know what is the problem with my code, the android app is fine, I tested the same app with other arduino code and it runs, turn on and off the lights at the pins 10 and 9.
When I active the buttons in the app and the app send the characters to bluetooth, the arduino do nothing.
#include <SoftwareSerial.h>
SoftwareSerial Bluetooth(3, 4); // RX TX
String dataIn =""; //variable para almacenar el comando enviado por el bluetooth
#define resistencia 9
#define bomba 10
// variables para contar el tiempo entre procesos, modo automatico.
unsigned long tiempo1=0;
unsigned long tiempo2=0;
int segundosResis=0;
int minutosResis=0;
int segundosBomba=0;
int minutosBomba=0;
void setup() {
// put your setup code here, to run once:
Bluetooth.begin(38400);
Bluetooth.setTimeout(1);
pinMode(resistencia, OUTPUT);
pinMode(bomba, OUTPUT);
// INICIALIZADA DE LOS ESTADOS DE RESISTENCIA Y BOMBA
digitalWrite(resistencia, LOW);
digitalWrite(bomba, LOW);
}
void loop() {
// put your main code here, to run repeatedly:
if (Bluetooth.available()>0)
{
dataIn = Bluetooth.readString(); // Read the data as string
if (dataIn=="A")
{
digitalWrite(resistencia, HIGH); // ESTADO A, RESISTENCIA PRENDIDA
}
if (dataIn=="B")
{
digitalWrite(bomba, HIGH); // ESTADO B, BOMBA PRENDIDA
}
if (dataIn == "C")
{
digitalWrite(bomba, LOW); // ESTADO C, BOMBA Y RESISTENCIA APAGADA
digitalWrite(resistencia, LOW);
}
if (dataIn == "D")
{
digitalWrite(resistencia, LOW); // ESTADO D, RESISTENCIA APAGADA
}
if (dataIn == "E")
{
digitalWrite(bomba, LOW); // ESTADO E, BOMBA APAGADA
}
// Se toman los datos enviados por el bluetooth en las casillas de tiempos de bomba y de resistencia
if(dataIn.startsWith("SR"))
{
String dataInS= dataIn.substring(2, dataIn.length());
segundosResis= dataInS.toFloat();
}
if(dataIn.startsWith("MR"))
{
String dataInS= dataIn.substring(2, dataIn.length());
minutosResis= dataInS.toFloat();
}
if(dataIn.startsWith("SB"))
{
String dataInS= dataIn.substring(2, dataIn.length());
segundosBomba= dataInS.toFloat();
}
if(dataIn.startsWith("MB"))
{
String dataInS= dataIn.substring(2, dataIn.length());
minutosBomba= dataInS.toFloat();
}
// se convierten los tiempos a segundos.
long tiempoResis= minutosResis*60+segundosResis;
long tiempoBomba= minutosBomba*60+segundosBomba;
long tiempoTotal=tiempoResis+tiempoBomba;
}
}