[SOLVED] Arduino UNO + ESP8266 + 4 relay

Yes you need the timer widget to set fixed on and off times.

See http://docs.blynk.cc/#widgets-controllers-timer and let us know if you have any questions.

1 Like

No way that it syncs with a clock app, right? I’ve been researching but found only negative answers.

You set the on and off time in the timer widget and Blynk sends the signal to virtual or physical pins for high and low at the allocated times.

You can have as many timer widgets (schedules) as you can fit in your dashboard, or the 10 or 11 maximum dashboards per user. The timer widget works very well but just make sure your smartphone is using internet time i.e. not fast or slow. If your phone is fast or slow you might miss the trigger times when you are testing your system.

2 Likes

They work with Blynk :wink:

Can’t find any documentation about that :frowning:
I read on the forum that ifttt only works on blynk private servers.

You can use makers channel and cloud.blynk.cc:8080 host. Documentation is not here yet as in future this API url will be changed.

Can’t thank you enough guys.

I opted to use my already existing IR remote to open and close the blinds so that arduino isn’t connected to 220v current. Arduino mimetizes a button press on the remote to open and than to stop that - vice-verse for closing. Also, with Automate Android, when my alarm clock rings in the morning the blinds open automatically. I’m waiting for automate to be able to get day/night in the weather block so blinds go down when sun goes down.

I have just a little problem right now. When I switch everything for the first time, if I press V2 push button, the LCD prints like it’s closing but the relay doesn’t get activated. But if I turn on/off on a D11 button directly just one time before, V2 works.

@glorifiedg you should have a problem with both relays, it is not if x = y it is if x == y in your if statements.

Problem persists after correction :s

Does D11 appear in your Blynk app as a button or is it just a physical button? If it is in the app is it a push or switch button? Do you have your virtual buttons set as push or switch mode.

Are the relays active (ON) HIGH or LOW? Looking at the code it appears to be active LOW.
What is the half second (500 milliseconds) timeout for? It looks like you activate the relay to open the blind and then 16 seconds later turn off the relay, right?

If relay is active (ON) low the code appears to be relay on for 0.5s then off for 16s then back off for 0.5s and finally off for 16s. Presumably nothing would actually happen but it depends how quick your relays are and how long it takes them to open and close the blinds. I am surprised any of your blinds are doing anything but you indicated one was ok and one wasn’t.

I am now thinking your relays are active HIGH and that you don’t have any pullup resistors in the circuit. In which case the virtual button should be digitalWrite(pinX, HIGH) and just one timeout 16s later to turn off the relay i.e. digitalWrite(pinX, LOW).

PLEASE use the </> icon when posting code as my brain hurts looking through your sketch in the gruesome format.

1 Like

D10 and D11 appears on the app as a switch for test purposes since I wont be using them.
V1 and V2 are push buttons.The relays are active on LOW.

The relays are connected to the old IR remote I used to control the blinds. That code mimetizes a push of the physical buttons it has.
So, when I want to turn the blind up, it sends a 500ms press of the button trow relay on pin 10, then it waits 16s to let the blind fully up and it send again the press of the button to stop it.

Post your sketch WITH </> and I’ll take another look at it now I know what it should be doing.

1 Like
//#define BLYNK_DEBUG
#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <ESP8266_HardSer.h>
#include <BlynkSimpleShieldEsp8266_HardSer.h>
#include <SimpleTimer.h>
#include <SPI.h>

// Set ESP8266 Serial object
#define EspSerial Serial

//Relay in Pin XX
#define Relay10 10
#define Relay11 11
#define Relay12 12
#define Relay13 13

ESP8266 wifi(EspSerial);
SimpleTimer timer;
WidgetLCD lcd(V31);

// You should get Auth Token in the Blynk App.
char auth[] = "XXXX";

void setup()
{
  // Set console baud rate
  Serial.begin(9600);
  delay(10);
  // Set ESP8266 baud rate
  EspSerial.begin(115200);
  delay(10);
   
  Blynk.begin(auth, wifi, "XXX", "XXXX");

lcd.print(0, 0, "Pronto"); 
}


//RELAY 10 SUBIR PERSIANA ESQUERDA

BLYNK_WRITE(V1) { 
  int RelayStatus10 = param.asInt();
  if (RelayStatus10 == 1) {
    digitalWrite(10, LOW);
    lcd.clear();
lcd.print(0, 0, "P. ESQUERDA"); 
lcd.print(0, 1, "A SUBIR");
  timer.setTimeout(500, turnRelay10AOff);
  }
  else{
    digitalWrite(10, HIGH);
  }
  
}

void turnRelay10AOff() {
    digitalWrite(Relay10, HIGH);
    timer.setTimeout(16000,turnRelay10on);
}

void turnRelay10on() {
    digitalWrite(Relay10, LOW);
    timer.setTimeout(500, turnRelay10Boff);
}

void turnRelay10Boff() {
    digitalWrite(Relay10, HIGH);
lcd.clear();
lcd.print(0, 0, "P. ESQUERDA"); 
lcd.print(0, 1, "ABERTA");
}


//RELAY 11 DESCER PERSIANA ESQUERDA

BLYNK_WRITE(V2) {
  int RelayStatus11 = param.asInt();
  if (RelayStatus11 == 1) {
    digitalWrite(11, LOW);
    lcd.clear();
lcd.print(0, 0, "P. ESQUERDA"); 
lcd.print(0, 1, "A DESCER");
  timer.setTimeout(500, turnRelay11AOff);
  }
  else{
    digitalWrite(11, HIGH);
  }
}

void turnRelay11AOff() {
    digitalWrite(Relay11, HIGH);
    timer.setTimeout(16000, turnRelay11on);
}

void turnRelay11on() {
    digitalWrite(Relay11, LOW);
    timer.setTimeout(500,turnRelay11Boff);
}

void turnRelay11Boff() {
    digitalWrite(Relay11, HIGH);
lcd.clear();
lcd.print(0, 0, "P. ESQUERDA"); 
lcd.print(0, 1, "FECHADA");
}
  
void loop()
{

  Blynk.run();
  timer.run(); // Initiates SimpleTimer
}

Modified your sketch to work on all Arduinos (no Blynk) as shown below and Serial monitor results are:

Sending IR signal .......
Sent IR signal to open blinds.
Blinds opening  .......
Blinds now open, relay OFF.

Sketch follows:

#include <SimpleTimer.h>

//Relay in Pin XX
#define Relay10 10
int loopjustonce = 0;
int RelayStatus10 = 0;

SimpleTimer timer;

void setup()
{ 
  Serial.begin(9600);   // Set console baud rate
  while (!Serial) {;}   // required for Leonardo
  delay(10);
}

void simulateV1() {
  if(loopjustonce == 0){ 
    RelayStatus10 = 1;
    loopjustonce = 1;
  }
  if (RelayStatus10 == 1) {
    digitalWrite(10, LOW);
    Serial.println("Sending IR signal .......");
    timer.setTimeout(500, turnRelay10AOff);
  }
  else{
    digitalWrite(10, HIGH);
  }
}

void turnRelay10AOff() {
    Serial.println("Sent IR signal to open blinds.");
    Serial.println("Blinds opening  .......");
    digitalWrite(Relay10, HIGH);
    timer.setTimeout(16000,turnRelay10on);
}

void turnRelay10on() {  
    digitalWrite(Relay10, LOW);
    timer.setTimeout(500, turnRelay10Boff);
}

void turnRelay10Boff() {
    Serial.println("Blinds now open, relay OFF.");
    digitalWrite(Relay10, HIGH);
}

  
void loop()
{
  timer.run(); // Initiates SimpleTimer
  if(loopjustonce == 0){
    simulateV1();
  }
}

Can you try this sketch and see if the relays and blinds respond as required.

1 Like

I think you are having trouble with V2 and relay 11 rather than V1 and relay 10 so amend my sketch accordingly.

I see the serial messages but relays do absolutely nothing :S

I suspected as much, so it is not a Blynk issue.

I guess we now need to see some sort of schematic.

Relay board connects
GND - GND
IN1 - D11
IN2 - D10
VCC - 5V

ESP8266 connects to RX, TX, GND and 5V after a resistor.

Maybe its a problem on the relay board.

use an LED instead of the relay - if the LED lights up, your relays are defunct, if it doesn’t, your code/board is defunct?