Relay Trouble using BLE and Arduino

Hey all,

I am having some trouble using my relay module with Arduino and Blynk. Without Blynk, using a simple digitalwrite sketch, the relay has no operation issues. When using Blynk, its almost as if the switching signal is not strong enough.

I am using an HC-05 Bluetooth Module and Samsung Tablet as a controller. I know my sketch works as intended, I have tested it without the relay by using an LED in its place. I have also tested it by powering my Arduino and relay module separately.

It seems to me as soon as Blynk is introduced, I cannot get it to operate. I have attached my sketch, please give me some pointers and possible leads as to what my problem is! I am by no means well versed in coding, but love a challenge and willing to do the work! Just need a nudge in the right direction.

//Project Definitions
#define BLYNK_PRINT Serial
#include <SoftwareSerial.h>
#include <Blynk.h>
#include <BlynkSimpleSerialBLE.h>

int ledPin =7;
SoftwareSerial DebugSerial (2, 3); //RX, TX
char auth[] = "xxxxxxxx"; //Connection Code for Blynk

BlynkTimer timer;

void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
Blynk.begin(Serial, auth);
}

BLYNK_WRITE(V2) { 
int buttonState = param.asInt();
  if (buttonState == 1)
   {
     Blynk.virtualWrite(V12, 255);
     digitalWrite(ledPin, HIGH);
     timer.setTimeout(1000L, OFF); 
    }
}

void OFF()
{
     Blynk.virtualWrite(V12, 0);
     digitalWrite(ledPin, LOW);
}
void loop()
{
  Blynk.run();
  timer.run();

}

@addnn please edit your post, using the pencil icon at the bottom, and add triple backticks at the beginning and end of your code so that it displays correctly.
Triple backticks look like this:
```

Pete.

1 Like

Please attache your serial monitor too, so we could see what happened .
The code seems to be ok and quite simple.
Are you sure Bluetooth is connected ?

@Blynk_Coeur

Working on attaching my Serial Monitor for you now, waiting for my tablet to turn back on to ensure the correct information is displayed to the serial monitor. I will have this for you in a few minutes.

I believe the Bluetooth is connected as per my LED test, when my button is pressed my LED will light for 1 second and turn off until next button press.

1 Like

Is it a blynk virtual Led ?

No, a physical LED. Off of digital pin 7.

You are wrong, the physical LED is attached to digitalWrite
and V12 is a virtual pin

Not sure, I have been able to control my physical LED off of pin 7 with success. Just not the relay.

I’m OK with that, but what is V12 pin ?

I am not sure, I am very inexperienced with coding and especially Blynk. The code was written by someone else to help me with a simple LED timing on/off. If the V12 is part of the problem, what is recommended to be done differently? I have left it alone as i was making progress.

Maybe you should draw a circuit diagram, as well as showing is exactly what widgets you have set-up in your app and which pins (digital or virtual) they are connected to.

Pete.

2 Likes

Ok, if you need to control a relay, you have to define the relay pin

#include <BlynkSimpleSerialBLE.h>

int ledPin =7;

#define RelayPin 5 // change this according to the MCU pin you have attached the relay <--------

SoftwareSerial DebugSerial (2, 3); //RX, TX
char auth[] = "xxxxxxxx"; //Connection Code for Blynk.
.
.
.

BLYNK_WRITE(V2) { 
int buttonState = param.asInt();
  if (buttonState == 1)
   {
     digitalWrite(RelayPin , HIGH);
     digitalWrite(ledPin, HIGH);
     timer.setTimeout(1000L, OFF); 
    }
}

void OFF()
{
      digitalWrite(RelayPin , LOW);
     digitalWrite(ledPin, LOW);
}

I really appreciate you working through this with me.

Now, after viewing my Serial Monitor I get this…

[13466] Login timeout
[15466] Connecting...
xxxxxx[23084] Ready
[91115] Heartbeat Timeout
[93118] Connecting...
xxxxxxx[96222] Login timeout

Not sure what a Heartbeat Timeout is.

That says Blynk is not connected !
So it can’t work.
Are you sure you have replaced char auth[] = “xxxxxxxx” with the one you got from the App?

Yes I have replaced xxxxxx with my token. It was connected for a short duration though no?

I have reattached my Physical LED through digital pin 7 and GND, as I press my button on Blynk it flashes as expected but my Serial Monitor still says the connection has Timed Out.

Ok, now you have to attach relay to the pin define at #define RelayPin as I said, and change Blynk.virtualWrite(V12, 255) to digitalWrite(RelayPin , HIGH)

I have replaced the LED with my relay and used the defined pin. Still no luck getting the relay to switch over Blynk, even after powering the relay separately.

This is the problem I have been facing, not sure what it is. Its as if the Arduino cannot supply enough switching current when Blynk is introduced.

@Blynk_Coeur, from what I am gathering @addnn is just swapping out the physical LED with the relay. So I do not see the need to define another pin. Unless he wants to use the LED and Relay at the same time. which may be helpful for this debugging.

I think @PeteKnight’s suggestion is a good one.

I would also add that we could use a picture or link to the relay module you are using.

2 Likes

So what do you do with V12 ? I realy don’t understand

I think there is a misunderstanding between the virtual pins and the digital pins