Hello, i’m trying to add bluetooth with my Arduino UNO with HC-05 module with blynk but i’m new to this and i’m having some trouble. My project is a led strip controller that can:
-change colour from the app.
-fade this color if a button is pressed .
-respond to music time when a button is pressed.
-change the speed of the fade.
in the app i have:
-zRGBa widget to V0 to send RGB values.
-a fade button in switch mode to V1.
-a music button in switch mode to V2
-a fade speed slider to V3.
PROBLEMS:
-in the serial port i’m receiving “connecting…” and then “login timeout” in loop. so i don’t understand why it’s not connecting. however i receive all virtual pins values.
-for now i’m only able to change color but there is a random delay from when i touch the widget and when the colour changes, maybe because the module is trying to connect and prevent data to be sended in the meanwhile?
-i’ve tried to write a “while” loop in the BLYNK_WRITE(V1) function but is not working properly, just loop forever, i can’t update the exit value inside the cicle, and even “Blynk.syncVirtual(V3)” that should call BLYNK_WRITE(V3) to update fade speed is not working. maybe because of my first problem as well?
-Interrupt does not work, when the BLYNK_WRITE(V2) function is called the R G B output pins just get all low.
Thank you al lot if you are going to help me
here is my code:
#define BLYNK_PRINT Serial
//#define BLYNK_DEBUG
struct rec
{
int fade,music;
int del;
int r,g,b;
};
rec data = {0, 1, 5, 255, 0, 255}; //default values for all the bt data
const int R = 9;
const int G = 10;
const int B = 11;
const int SI = 2;
const int RX = 0;
const int TX = 1;
int intflag = 0;
char auth[] = "4a8519321fcd4709959979919868a3a4";
#include <BlynkSimpleSerialBLE.h>
#include <SoftwareSerial.h>
SoftwareSerial SerialBLE(RX, TX); //0 1
void setup()
{
Serial.begin(9600);
SerialBLE.begin(9600);
Blynk.begin(SerialBLE, auth);
pinMode(B,OUTPUT); //outupts to mosfets
pinMode(R,OUTPUT);
pinMode(G,OUTPUT);
pinMode(SI,INPUT_PULLUP); // sound sensor input for interrupt
}
void loop()
{
Blynk.run();
}
BLYNK_CONNECTED()
{
Blynk.syncAll();//should get all the pins value from bt
}
BLYNK_WRITE(V0) //get rgb
{
data.r = param[0].asInt();
data.g = param[1].asInt();
data.b = param[2].asInt();
color(data.r,data.g,data.b); //function that send PWM values to mosfets
}
BLYNK_WRITE(V1) //get fade
{
data.fade = param.asInt();
while(data.fade==1)
{
Blynk.syncVirtual(V3); //read value of data.del?
fade(data.del); //function that fade with a specified delay the already present color
data.fade = param.asInt(); //should update data.fade value from bt in order to exit the cicle?
}
}
BLYNK_WRITE(V2) //get music
{
data.music = param.asInt();
if(data.music==1)
attachInterrupt(digitalPinToInterrupt(SI),off , RISING); //sound sensor attached to interrupt,off turn off all
//leds
else
detachInterrupt(digitalPinToInterrupt(SI));
}
BLYNK_WRITE(V3) //get del
{
data.del = param.asInt();
}
void fade (int del)
{
int con,conr,cong,conb,max=255;
conr=0;
cong=0;
conb=0;
for(con=0;con<max;con++)
{
if(conr<data.r)
conr++;
analogWrite(R,conr);
if(cong<data.g)
cong++;
analogWrite(G,cong);
if(conb<data.b)
conb++;
analogWrite(B,conb);
delay(del);
}
conr=data.r;
cong=data.g;
conb=data.b;
for(con=0;con<max;con++)
{
if(conr>0)
conr--;
analogWrite(R,conr);
if(cong>0)
cong--;
analogWrite(G,cong);
if(conb>0)
conb--;
analogWrite(B,conb);
delay(del);
}
}
void color (int r,int g,int b)
{
analogWrite(R,r);
analogWrite(G,g);
analogWrite(B,b);
}
void off ()
{
analogWrite(R,0);
analogWrite(G,0);
analogWrite(B,0);
}