lets see if i can get this right with out making anyone angry…
im using particle photon with relay shield. i was able to get mostly what i want out of code and the vPINS working together, my code might not be the cleanest or effective but its working so far. what im trying to do now is start a timer when ever one of my three buttons on the app is pressed activating a relay and than deactivate the relay and reset the switch on the app after the timer has reached 0. ive done as much looking to find my answer with out having to bother asking and im not looking for someone to code for me just trying to learn, but with the code that i have, it compiles fine. i only have a start timer on one button just for testing. if i don’t press that button there’s no issues, but once i press the button it clearly starts the timer but once the timer reaches 0 my photon starts flashing the red light on the board and is basically disconnected from the app. i have all the actions commented out of the timer right now trying to track down the issue.
thanks in advance for someone pointing out where i went wrong.
#define BLYNK_PRINT Serial // Set serial output for debug prints
//#define BLYNK_DEBUG // Uncomment this to see detailed prints
#include <blynk.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "AUTH CODE";
void relay_off()
{
static int count = 0;
Serial.println(count++);
//digitalWrite(3, LOW);
//Blynk.virtualWrite(V1, 0);
//digitalWrite(4, LOW);
//Blynk.virtualWrite(V2, 0);
//digitalWrite(5, LOW);
//Blynk.virtualWrite(V3, 0);
//digitalWrite(6, LOW);
//Blynk.virtualWrite(V4, 0);
}
Timer timer(5000, relay_off);
void setup()
{
Serial.begin(9600);
delay(5000); // Allow board to settle
Blynk.begin(auth);
pinMode (3,OUTPUT); //define pin 3 as output for relay
pinMode (4,OUTPUT); //define pin 4 as output for relay
pinMode (5,OUTPUT); //define pin 5 as output for relay
pinMode (6,OUTPUT); //define pin 6 as output for relay
}
BLYNK_WRITE(1)
{
int pinValue = param.asInt(); // assigning incoming value from pin V3 to a variable
if (param.asInt()) {
timer.start();
digitalWrite(3, HIGH); //turns relay 1 on
digitalWrite(4, LOW); //turns relay 2 off
Blynk.virtualWrite(V2, 0); //updates Blynk Button to off
digitalWrite(5, LOW); //turns relay 3 off
Blynk.virtualWrite(V3, 0); //updates Blynk Button to off
digitalWrite(6, LOW); //turns relay 4 off
Blynk.virtualWrite(V4, 0); //updates Blynk Button to off
}
}
BLYNK_WRITE(2)
{
int pinValue = param.asInt(); // assigning incoming value from pin V3 to a variable
if (param.asInt()) {
//HIGH
digitalWrite(4, HIGH); //turns relay 2 on
digitalWrite(3, LOW); //turns relay 1 off
Blynk.virtualWrite(V1, 0); //updates Blynk Button to off
digitalWrite(5, LOW); //turns relay 3 off
Blynk.virtualWrite(V3, 0); //updates Blynk Button to off
digitalWrite(6, LOW); //turns relay 4 off
Blynk.virtualWrite(V4, 0); //updates Blynk Button to off
}
}
BLYNK_WRITE(3)
{
int pinValue = param.asInt(); // assigning incoming value from pin V3 to a variable
if (param.asInt()) {
//HIGH
digitalWrite(5, HIGH); //turns relay 3 on
digitalWrite(3, LOW); //turns relay 1 off
Blynk.virtualWrite(V1, 0); //updates Blynk Button to off
digitalWrite(4, LOW); //turns relay 2 off
Blynk.virtualWrite(V2, 0); //updates Blynk Button to off
digitalWrite(6, LOW); //turns relay 4 off
Blynk.virtualWrite(V4, 0); //updates Blynk Button to off
}
}
BLYNK_WRITE(4)
{
int pinValue = param.asInt(); // assigning incoming value from pin V3 to a variable
if (param.asInt()) {
// using 4th button to turn all relays off, when attempting to use else with any blynk write to turn the relay that was just turned on to off again i crash photon.
digitalWrite(6, LOW); //relay 4 off
digitalWrite(3, LOW); //relay 1 off
Blynk.virtualWrite(V1, 0); //updates Blynk Button to off
digitalWrite(4, LOW); //relay 2 off
Blynk.virtualWrite(V2, 0); //updates Blynk Button to off
digitalWrite(5, LOW); //relay 3 off
Blynk.virtualWrite(V3, 0); //updates Blynk Button to off
}
}
void loop()
{
Blynk.run();
}