Ok so here is the problem I need Blynk to act as a push button (turn on momentarily, then turn off) when controlling an 8 Relay Module but what happens is when I press a button on Blynk the relay will stay on and the only way to turn off the relay is to turn off power to the Bluno micro-controller. To answer any questions yes I did set the Blynk button to push instead of switch on the button settings. The thing is, is that I used this same code minus some libraries and other stuff like “SoftwareSerial DebugSerial(2, 3)” when I had an Arduino 101 and it worked fine as a push button. Unfortunately my Arduino 101 does not work anymore.
//#define BLYNK_USE_DIRECT_CONNECT
// You could use a spare Hardware Serial on boards that have it (like Mega)
#include <SoftwareSerial.h>
SoftwareSerial DebugSerial(2, 3); // RX, TX
#define BLYNK_PRINT DebugSerial
#include <BlynkSimpleSerialBLE.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "a6c6ea9f51734a0982d6fe8bfd43ee72";
const int buttonPin1 = 10; // the number of the pushbutton pin
const int buttonPin2 = 11; // the number of the pushbutton pin
const int buttonPin3 = 12; // the number of the pushbutton pin
const int relay1 = 2; // the number of the relay1 pin
const int relay2 = 3; // the number of the relay2 pin
const int relay3 = 4; // the number of the relay3 pin
const int relay4 = 5; // the number of the relay4 pin
const int relay5 = 6; // the number of the relay5 pin
const int relay6 = 7; // the number of the relay6 pin
const int relay7 = 8; // the number of the relay7 pin
const int relay8 = 9; // the number of the relay8 pin
int buttonState1 = 0; // variable for reading the pushbutton status
int buttonState2 = 0; // variable for reading the pushbutton status
int buttonState3 = 0; // variable for reading the pushbutton status
void setup()
{
// Debug console
DebugSerial.begin(9600);
DebugSerial.println("Waiting for connections...");
// Blynk will work through Serial
// Do not read or write this serial manually in your sketch
Serial.begin(115200);
Blynk.begin(Serial, auth);
// initialize the relay1,2,3,4 pins as an output:
pinMode(relay1, INPUT);
pinMode(relay2, INPUT);
pinMode(relay3, INPUT);
pinMode(relay4, INPUT);
pinMode(relay5, INPUT);
pinMode(relay6, INPUT);
pinMode(relay7, INPUT);
pinMode(relay8, INPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin1, INPUT);
pinMode(buttonPin2, INPUT);
pinMode(buttonPin3, INPUT);
}
void loop()
{
Blynk.run();
// read the state of the pushbutton value:
buttonState1 = digitalRead(buttonPin1);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState1 == HIGH) {
// turn relays on:
digitalWrite(relay1, HIGH);
digitalWrite(relay2, HIGH);
digitalWrite(relay3, HIGH);
digitalWrite(relay4, HIGH);
digitalWrite(relay5, HIGH);
digitalWrite(relay6, HIGH);
digitalWrite(relay7, HIGH);
digitalWrite(relay8, HIGH);
}
else {
// turn relays off:
digitalWrite(relay1, LOW);
digitalWrite(relay2, LOW);
digitalWrite(relay3, LOW);
digitalWrite(relay4, LOW);
digitalWrite(relay5, LOW);
digitalWrite(relay6, LOW);
digitalWrite(relay7, LOW);
digitalWrite(relay8, LOW);
}
buttonState2 = digitalRead(buttonPin2);
if (buttonState2 == HIGH) {
// turn relays on:
digitalWrite(relay1, HIGH);
digitalWrite(relay2, HIGH);
digitalWrite(relay3, HIGH);
digitalWrite(relay4, HIGH);
}
else {
// turn relays off:
digitalWrite(relay1, LOW);
digitalWrite(relay2, LOW);
digitalWrite(relay3, LOW);
digitalWrite(relay4, LOW);
}
buttonState3 = digitalRead(buttonPin3);
if (buttonState3 == HIGH) {
// turn relays on:
digitalWrite(relay5, HIGH);
digitalWrite(relay6, HIGH);
digitalWrite(relay7, HIGH);
digitalWrite(relay8, HIGH);
}
else {
// turn relays off:
digitalWrite(relay5, LOW);
digitalWrite(relay6, LOW);
digitalWrite(relay7, LOW);
digitalWrite(relay8, LOW);
}
}