Combining blynk code and Bluetooth codes to control one relay together

Cjjjjjjj's picture

Offline

Joined: Feb 21, 2020

Replies: 7
Combining blynk code and Bluetooth codes to control one relay together
February 23, 2020 - 4:09pm

Hell how can I combine my code from blynk code to Bluetooth codes to control one relay, the relay is connected to nodemcu I just want to control it using blynk and Bluetooth terminal app is it possible? Thank you! Here's my code in blynk. #define BLYNK_PRINT Serial #include #include char auth[] = "xxxxxxx"; char ssid[] = "xxxxxxx"; char pass[] = "xxxxxxx"; void setup() { Serial.begin(9600); Blynk.begin(auth, ssid, pwd); } void loop() { Blynk.run(); Here's my code in Bluetooth. #include SoftwareSerial btSerial(D2, D3); // Rx,Tx void setup() { pinMode(11, OUTPUT); pinMode(10, OUTPUT); Serial.begin(9600) } void loop() { if (Serial.available() > 0) { char c = Serial.read(); if (c == 'a') { Serial.print("in a code"); digitalWrite(10,HIGH); digitalWrite(11,LOW); Serial.print("10 HIGH"); lcd.clear(); lcd.print("**BULB1 ON**"); } if(c=='b') { digitalWrite(11,HIGH); digitalWrite(10,LOW); Serial.print("11 HIGH"); lcd.clear(); lcd.print("**BULB2 ON**"); } if(c=='c') { digitalWrite(10,HIGH); digitalWrite(11,HIGH); lcd.clear(); lcd.print("**BULB 1,2 ON**"); } if(c=='d') { digitalWrite(10,LOW); digitalWrite(11,LOW); lcd.clear(); lcd.print("**BULB 1,2 OFF**"); } } } }

Debasis Parida's picture

Offline

Joined: Aug 22, 2019

Replies: 125

The bluetooth control code is correct.just merge the blynk control code to this.That means, send a data via a virtual terminal from blynk and receive it in your code, and as per that control the relay.

Cjjjjjjj's picture

Offline

Joined: Feb 21, 2020

Replies: 7

Here's my blynk code
#define BLYNK_PRINT Serial
#include
#include
int Relay1 16; // D0 of nodemcu
int Relay2 5; // D1 of nodemcu
void setup()
{
Serial.begin(9600);
Blynk.begin(auth, ssid, pwd);
}

void loop()
{
Blynk.run();

}

Cjjjjjjj's picture

Offline

Joined: Feb 21, 2020

Replies: 7

Here's my blynk code
#define BLYNK_PRINT Serial
#include
#include
int Relay1 16; // D0 of nodemcu
int Relay2 5; // D1 of nodemcu
void setup()
{
Serial.begin(9600);
Blynk.begin(auth, ssid, pwd);
}

void loop()
{
Blynk.run();

}

Cjjjjjjj's picture

Offline

Joined: Feb 21, 2020

Replies: 7

Can we talk in email sir Debasis Parida?

Debasis Parida's picture

Offline

Joined: Aug 22, 2019

Replies: 125

#define BLYNK_PRINT Serial
#include
#include
int Relay1 16; // D0 of nodemcu
int Relay2 5; // D1 of nodemcu
void setup()
{
Serial.begin(9600);
Blynk.begin(auth, ssid, pwd);
}

void loop()
{
Blynk.run();

if(Serial.available>0)

{

char data=Serial.read();

if(data= ='a')

{

digitalWrite(16,HIGH);

}

else

{

digitalWrite(16,LOW);

}

}

}

Cjjjjjjj's picture

Offline

Joined: Feb 21, 2020

Replies: 7

Can i use bluetooth terminal app sir?

Debasis Parida's picture

Offline

Joined: Aug 22, 2019

Replies: 125

Yes..you can definitely use bluetooth terminal application to transfer data from mobile to nodemcu.No problem

Cjjjjjjj's picture

Offline

Joined: Feb 21, 2020

Replies: 7

Sir according to blynk community I need to use ESPSoftwareserial in order to use Bluetooth on nodemcu than the regular softwareserial but I don't know how to use the ESPSoftwareserial can you help me sir? Thank you!