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:
```
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 ?
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.
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.
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.