BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Hello every one, need help with 2x4 relay modules

#1

i had those lying around so i tried to use them, but cant figure it out
i want the relays off when the wemos d1 mini is powered and then every1 second to power them one by one (think larson scanner but slow and stay ON)
i tried the relay shield it works then i started adding other pins 1-8 but now they are all on and just blink
(boot all ON, relay 1 off on; relay 2 off-on, and so on)
i read to use virtual pins here but cant find how.
i would appreciate if someone could point me in the right direction?
can wemos d1 mini control 8 relay in 2 modules? if not i will order one 8 relay module
thnx alot
blynk is the best (i monitor server temp&humidity at work)

0 Likes

#2

ok so i got i partially working
it works first time after upload after that reset/kill power doesnt work just 2 relays stay on (D3 & D8) should i set these to LOW at boot?

/*
 * Relay Shield - Blink
 * Turns on the relay for two seconds, then off for two seconds, repeatedly.
 *
 * Relay Shield transistor closes relay when D1 is HIGH
 */

const int relayPinD1 = D1;
const long interval = 1000;  // pause for two seconds
const int relayPinD2 = D2;
const int relayPinD3 = D3;
const int relayPinD4 = D4;
const int relayPinD5 = D5;
const int relayPinD6 = D6;
const int relayPinD7 = D7;
const int relayPinD8 = D8;



void setup() {
  pinMode(relayPinD1, OUTPUT);
  pinMode(relayPinD2, OUTPUT);
  pinMode(relayPinD3, OUTPUT);
  pinMode(relayPinD4, OUTPUT);
  pinMode(relayPinD5, OUTPUT);
  pinMode(relayPinD6, OUTPUT);
  pinMode(relayPinD7, OUTPUT);
  pinMode(relayPinD8, OUTPUT);
 
  digitalWrite(relayPinD1, HIGH);
  digitalWrite(relayPinD2, HIGH);
  digitalWrite(relayPinD3, HIGH);
  digitalWrite(relayPinD4, HIGH);
  digitalWrite(relayPinD5, HIGH);
  digitalWrite(relayPinD6, HIGH);
  digitalWrite(relayPinD7, HIGH);
 digitalWrite(relayPinD8, HIGH);
}

void loop() {
  digitalWrite(relayPinD1, HIGH); // turn on relay with voltage HIGH
  delay(interval);              // pause
  digitalWrite(relayPinD1, LOW);  // turn off relay with voltage LOW
  delay(interval);  
 digitalWrite(relayPinD2, HIGH); // turn on relay with voltage HIGH
  delay(interval);
  digitalWrite(relayPinD2, LOW);  // turn off relay with voltage LOW
  delay(interval);
 digitalWrite(relayPinD3, HIGH); // turn on relay with voltage HIGH
  delay(interval);
  digitalWrite(relayPinD3, LOW);  // turn off relay with voltage LOW
  delay(interval);
 digitalWrite(relayPinD4, HIGH); // turn on relay with voltage HIGH
  delay(interval);
  digitalWrite(relayPinD4, LOW);  // turn off relay with voltage LOW
  delay(interval);
 digitalWrite(relayPinD5, HIGH); // turn on relay with voltage HIGH
  delay(interval);
  digitalWrite(relayPinD5, LOW);  // turn off relay with voltage LOW
  delay(interval);
  digitalWrite(relayPinD6, HIGH); // turn on relay with voltage HIGH
  delay(interval);
  digitalWrite(relayPinD6, LOW);  // turn off relay with voltage LOW
  delay(interval);
  digitalWrite(relayPinD7, HIGH); // turn on relay with voltage HIGH
  delay(interval);
  digitalWrite(relayPinD7, LOW);  // turn off relay with voltage LOW
  delay(interval);
 digitalWrite(relayPinD8, HIGH); // turn on relay with voltage HIGH
  delay(interval);
  digitalWrite(relayPinD8, LOW);  // turn off relay with voltage LOW
  delay(interval);// pause
}
0 Likes

#3

Boot state of ESP8266 GPIO depends on the pins used…

0 Likes

#4

thnx alot, back to google i guess to find out more about virtual pins and a workaround with this issue

0 Likes

#5

Are you using Blynk to achieve your goal?? 16 seconds delay in total at the loop will KILL Blynk… RIP

2 Likes

#7

i will have it connected to ac light switch (via 220v to 5v adapter)
thats why i want it at boot all relays OFF then slowly powering all it can be shorter time 0,5 sec each
and
with blynk i want to have individual control (8 buttons to turn them ON/OFF)

how should i achieve all this? if its doable

0 Likes

#8

BlynkTimer

http://docs.blynk.cc/#blynk-firmware-blynktimer

Virtual Pins and a little if else() logic code tied in with the timers

https://www.arduino.cc/reference/en/language/structure/control-structure/if/

1 Like

#9

any example you could help me get started? i would be very thankful, coding is not my strong side :frowning:
thnx for all the help

0 Likes

#10

You will need to learn enough to get by :stuck_out_tongue_winking_eye: I did, am, will still be years from now…

I made this simple example months ago… Coded for Local Server and only 4 relays, so you will need to make those adjustments at least. I haven’t gotten around to posting it on my Example Topic yet, but here it is:

/***************** Library ESP and Blynk *****************/
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

char auth[] = "xxxxxxxxxx";
char ssid[] = "xxxxxxxxxx";
char pass[] = "xxxxxxxxxx";
char server[] = "xxx.xxx.xxx.xxx";
int port = 8080;
int count;
int ON = 0;
int OFF = 1;

// Set virtual LEDS to these vPins... but these commands are not required since using direct virtualWrite() commands
//WidgetLED led1(V3);
//WidgetLED led2(V4);
//WidgetLED led3(V5);
//WidgetLED led4(V6);

/*************** Array of Relays *********************/
int relay[] = {5, 4, 14, 12}; // The relay pin order for triggering based on count (GPIO pins, NOT using Dpin labeling)



/*************** Setup *********************/
void setup()
{
  Serial.begin(115200);

  WiFi.begin(ssid, pass);
  Blynk.config(auth, server, port);
  Blynk.connect();

  // Set all array pinmodes and set LOW
  for (count = 0; count <= 3; count++) {
    pinMode(relay[count], OUTPUT);
    digitalWrite(relay[count], OFF);
  }

}



/*************** Forward pattern *********************/
BLYNK_WRITE(V1) {  // Button-Switch Widget
  if (param.asInt() == 1) {
    for (count = 0; count < 4; count++) {  // Count forward
      //Serial.print(count);
      Blynk.virtualWrite(count+3, 255);  // Virtual LED ON (EG count 0 + 3 = V3) 
      digitalWrite(relay[count], ON);  // Toggle relays ON, based on array and count order
      Blynk.virtualWrite(count+3, 0);  // Virtual LED OFF
      digitalWrite(relay[count], OFF);  // Toggle relays OFF
    }
    Blynk.syncVirtual(V1);  // Repeat if switch still ON
  }
  else {  // Stop all relays if switch OFF
    for (count = 0; count <= 3; count++) {
      digitalWrite(relay[count], OFF);
    }
  }
}



/*************** Backward pattern *********************/
BLYNK_WRITE(V2) {  // Button-Switch Widget
  if (param.asInt() == 1) {  // Count backward
    for (count = 3; count >= 0; count--) {
      //Serial.print(count);
      Blynk.virtualWrite(count+3, 255);  // Virtual LED ON (EG count 0 + 3 = V3) 
      digitalWrite(relay[count], ON);  // Toggle relays ON, based on array and count order
      Blynk.virtualWrite(count+3, 0);  // Virtual LED OFF
      digitalWrite(relay[count], OFF);  // Toggle relays OFF
    }
    Blynk.syncVirtual(V2);
  }
  else {  // Stop all relays if switch OFF
    for (count = 0; count < 4; count++) {
      digitalWrite(relay[count], OFF);
    }
  }
}



/*************** Loop *********************/
void loop() {
  Blynk.run();
}
1 Like

#11

thnx a ton, i will try as soon as i can, that means in a couple of weeks :slight_smile: will post if i get it working

0 Likes